[
{
"id": "cpp-java-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "cpp-java",
"Code1": "void printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n",
"Code2": "public static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "cpp-java",
"Code1": "float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"Code2": "static float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "cpp-java",
"Code1": "bool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n",
"Code2": "static boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "cpp-java",
"Code1": "int nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"Code2": "static int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-java",
"Code1": "void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-NON_REPEATING_ELEMENT_1",
"pair": "cpp-java",
"Code1": "int firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "static int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "cpp-java",
"Code1": "bool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n ",
"Code2": "static boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-java-BREAK_NUMBER_THREE_PARTS_1",
"pair": "cpp-java",
"Code1": "ll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"Code2": "static long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n",
"Code2": "static int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "cpp-java",
"Code1": "int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"Code2": "static int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "cpp-java",
"Code1": "int smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n",
"Code2": "static int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "cpp-java",
"Code1": "char findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"Code2": "static char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n\n"
},
{
"id": "cpp-java-RECAMANS_SEQUENCE_1",
"pair": "cpp-java",
"Code1": "void recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"Code2": "static void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "cpp-java",
"Code1": "int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"Code2": "public static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "cpp-java",
"Code1": "void countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n",
"Code2": "static void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "cpp-java",
"Code1": "int maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "cpp-java",
"Code1": "bool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "public static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-FRIENDS_PAIRING_PROBLEM_2",
"pair": "cpp-java",
"Code1": "int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"Code2": "static int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n\n"
},
{
"id": "cpp-java-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "cpp-java",
"Code1": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "cpp-java",
"Code1": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "cpp-java-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "cpp-java",
"Code1": "void subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n",
"Code2": "static void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "cpp-java",
"Code1": "bool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"Code2": "static boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "cpp-java",
"Code1": "void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"Code2": "static void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n\n"
},
{
"id": "cpp-java-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "cpp-java",
"Code1": "public : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"Code2": "static float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "cpp-java",
"Code1": "int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"Code2": "static int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "cpp-java",
"Code1": "int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"Code2": "static int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "cpp-java",
"Code1": "bool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n",
"Code2": "static boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "cpp-java",
"Code1": "double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n",
"Code2": "public static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n\n"
},
{
"id": "cpp-java-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "cpp-java",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "cpp-java",
"Code1": "int chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n ",
"Code2": "static int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n \n"
},
{
"id": "cpp-java-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "cpp-java",
"Code1": "double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"Code2": "static double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n\n"
},
{
"id": "cpp-java-MAJORITY_ELEMENT",
"pair": "cpp-java",
"Code1": "void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n",
"Code2": "static void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "cpp-java",
"Code1": "bool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"Code2": "static boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "cpp-java",
"Code1": "string findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"Code2": "static String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n \n"
},
{
"id": "cpp-java-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "cpp-java",
"Code1": "int countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"Code2": "static int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "cpp-java",
"Code1": "void pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n",
"Code2": "static void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n\n"
},
{
"id": "cpp-java-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "cpp-java",
"Code1": "int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"Code2": "public static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n\n"
},
{
"id": "cpp-java-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "cpp-java",
"Code1": "void shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n",
"Code2": "public static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "cpp-java",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n",
"Code2": "static int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "cpp-java-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "static int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "cpp-java",
"Code1": "int summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n",
"Code2": "static int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "cpp-java",
"Code1": "bool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"Code2": "static boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"Code2": "static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "cpp-java",
"Code1": "int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"Code2": "static int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "cpp-java",
"Code1": "int removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"Code2": "static int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "cpp-java",
"Code1": "void find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n",
"Code2": "static void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-NON_REPEATING_ELEMENT",
"pair": "cpp-java",
"Code1": "int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "static int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "cpp-java",
"Code1": "void middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n",
"Code2": "static void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n\n"
},
{
"id": "cpp-java-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "cpp-java",
"Code1": "long long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"Code2": "static long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "cpp-java",
"Code1": "void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n",
"Code2": "static void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-SUM_PAIRWISE_PRODUCTS_2",
"pair": "cpp-java",
"Code1": "long long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"Code2": "static int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "cpp-java",
"Code1": "int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"Code2": "public static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "cpp-java",
"Code1": "int largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n",
"Code2": "static int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "cpp-java",
"Code1": "bool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "static boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "cpp-java",
"Code1": "int minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "static int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "cpp-java",
"Code1": "void arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n",
"Code2": "static void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "cpp-java",
"Code1": "int getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n ",
"Code2": "static int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n \n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "cpp-java",
"Code1": "int carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"Code2": "static int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "cpp-java",
"Code1": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"Code2": "public static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "cpp-java",
"Code1": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"Code2": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "cpp-java",
"Code1": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n",
"Code2": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "cpp-java",
"Code1": "int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"Code2": "static int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "cpp-java",
"Code1": "void printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n",
"Code2": "static void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "cpp-java",
"Code1": "void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n",
"Code2": "static void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "cpp-java",
"Code1": "int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"Code2": "static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "cpp-java",
"Code1": "void countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n",
"Code2": "static void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "cpp-java",
"Code1": "float findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "static float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "cpp-java",
"Code1": "int countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "cpp-java",
"Code1": "int lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n",
"Code2": "static int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "cpp-java",
"Code1": "int editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "static int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "cpp-java",
"Code1": "int countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"Code2": "static int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "cpp-java",
"Code1": "void longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n",
"Code2": "public static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "cpp-java",
"Code1": "void printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n",
"Code2": "static void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "cpp-java",
"Code1": "bool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n",
"Code2": "public static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "cpp-java",
"Code1": "int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"Code2": "static int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "cpp-java",
"Code1": "void printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n ",
"Code2": "static void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n \n"
},
{
"id": "cpp-java-COUNT_SORTED_ROWS_MATRIX",
"pair": "cpp-java",
"Code1": "int sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"Code2": "static int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "cpp-java",
"Code1": "int countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "static int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "cpp-java",
"Code1": "int findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n",
"Code2": "static void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "void printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n",
"Code2": "static void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "cpp-java",
"Code1": "int maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n",
"Code2": "static int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "cpp-java",
"Code1": "int largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n",
"Code2": "static int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "cpp-java",
"Code1": "char encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n",
"Code2": "static char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"Code2": "public static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "cpp-java",
"Code1": "int maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"Code2": "static int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "cpp-java",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "cpp-java",
"Code1": "int countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n ",
"Code2": "public static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n \n"
},
{
"id": "cpp-java-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "cpp-java",
"Code1": "int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"Code2": "static int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_1",
"pair": "cpp-java",
"Code1": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"Code2": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "cpp-java",
"Code1": "int countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "static int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "cpp-java",
"Code1": "int countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"Code2": "static int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "cpp-java",
"Code1": "string decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n",
"Code2": "static String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "cpp-java",
"Code1": "int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"Code2": "static int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '\n"
},
{
"id": "cpp-java-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "cpp-java",
"Code1": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"Code2": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "cpp-java",
"Code1": "int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"Code2": "static int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "cpp-java",
"Code1": "int maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"Code2": "static int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "cpp-java",
"Code1": "int evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n",
"Code2": "static int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n\n"
},
{
"id": "cpp-java-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "cpp-java",
"Code1": "int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"Code2": "public static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "cpp-java",
"Code1": "int numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "cpp-java",
"Code1": "int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"Code2": "static int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "cpp-java",
"Code1": "int minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "public static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "cpp-java",
"Code1": "void spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n",
"Code2": "static void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "cpp-java",
"Code1": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n",
"Code2": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "cpp-java",
"Code1": "int minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"Code2": "static int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n\n"
},
{
"id": "cpp-java-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "cpp-java",
"Code1": "int findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "static int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "cpp-java",
"Code1": "void convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n",
"Code2": "static void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "cpp-java",
"Code1": "unsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"Code2": "static int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n\n"
},
{
"id": "cpp-java-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "cpp-java",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "static int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "cpp-java",
"Code1": "void transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n",
"Code2": "static void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "cpp-java",
"Code1": "void findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"Code2": "static void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "cpp-java",
"Code1": "void printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "static void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_AREA_QUADRILATERAL",
"pair": "cpp-java",
"Code1": "double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"Code2": "static double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n\n"
},
{
"id": "cpp-java-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "cpp-java",
"Code1": "int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"Code2": "static int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n\n"
},
{
"id": "cpp-java-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "cpp-java",
"Code1": "int printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n ",
"Code2": "static void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n \n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "cpp-java",
"Code1": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"Code2": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "cpp-java",
"Code1": "int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n",
"Code2": "public static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n\n"
},
{
"id": "cpp-java-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "cpp-java",
"Code1": "int countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"Code2": "static int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "cpp-java",
"Code1": "void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n",
"Code2": "static void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "cpp-java",
"Code1": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "cpp-java",
"Code1": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"Code2": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "cpp-java",
"Code1": "bool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "static boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "cpp-java",
"Code1": "int getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "static int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-PRIME_FACTORS_BIG_NUMBER",
"pair": "cpp-java",
"Code1": "void factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n",
"Code2": "static void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "cpp-java",
"Code1": "int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"Code2": "static int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "cpp-java",
"Code1": "bool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "public static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "cpp-java",
"Code1": "bool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n",
"Code2": "static boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "cpp-java",
"Code1": "void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n",
"Code2": "static void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n\n"
},
{
"id": "cpp-java-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "cpp-java",
"Code1": "int solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"Code2": "static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n\n"
},
{
"id": "cpp-java-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "cpp-java",
"Code1": "void direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n",
"Code2": "static void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-java-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "cpp-java",
"Code1": "void splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n",
"Code2": "static void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "cpp-java",
"Code1": "int binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"Code2": "static int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n\n"
},
{
"id": "cpp-java-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "cpp-java",
"Code1": "void printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n",
"Code2": "private static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "cpp-java",
"Code1": "void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n",
"Code2": "static void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n\n"
},
{
"id": "cpp-java-SWAP_TWO_NIBBLES_BYTE",
"pair": "cpp-java",
"Code1": "int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"Code2": "static int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "cpp-java-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "cpp-java",
"Code1": "int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"Code2": "static int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SUM_DIVISORS_1_N_1",
"pair": "cpp-java",
"Code1": "int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"Code2": "static int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "cpp-java",
"Code1": "int addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"Code2": "static int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "cpp-java",
"Code1": "int check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "cpp-java",
"Code1": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n ",
"Code2": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n \n"
},
{
"id": "cpp-java-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "cpp-java",
"Code1": "int minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"Code2": "static int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n\n"
},
{
"id": "cpp-java-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "cpp-java",
"Code1": "void computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n",
"Code2": "void computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "cpp-java",
"Code1": "int numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-STOOGE_SORT",
"pair": "cpp-java",
"Code1": "void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"Code2": "static void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "cpp-java",
"Code1": "void solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n",
"Code2": "static void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "cpp-java",
"Code1": "int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"Code2": "static int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "cpp-java",
"Code1": "void printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n",
"Code2": "static void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "cpp-java",
"Code1": "int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "static int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "cpp-java",
"Code1": "int stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n ",
"Code2": "static int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n \n"
},
{
"id": "cpp-java-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "cpp-java",
"Code1": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"Code2": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n\n"
},
{
"id": "cpp-java-SUM_PAIRWISE_PRODUCTS_1",
"pair": "cpp-java",
"Code1": "long long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"Code2": "static int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "cpp-java",
"Code1": "void recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n",
"Code2": "public static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "cpp-java",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "cpp-java",
"Code1": "int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n",
"Code2": "static int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "cpp-java",
"Code1": "unsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"Code2": "static int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "cpp-java",
"Code1": "bool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "cpp-java",
"Code1": "long long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n",
"Code2": "static int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "cpp-java",
"Code1": "long long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n",
"Code2": "public static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNTING_INVERSIONS",
"pair": "cpp-java",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"Code2": "static int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n\n"
},
{
"id": "cpp-java-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "cpp-java",
"Code1": "void printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n",
"Code2": "static void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-DELANNOY_NUMBER_1",
"pair": "cpp-java",
"Code1": "int dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "static int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "cpp-java",
"Code1": "int power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"Code2": "static int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CHECK_ISBN",
"pair": "cpp-java",
"Code1": "bool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"Code2": "static boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "cpp-java",
"Code1": "void NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n ",
"Code2": "static void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n \n"
},
{
"id": "cpp-java-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "cpp-java",
"Code1": "int swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )",
"Code2": "static int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )\n"
},
{
"id": "cpp-java-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "cpp-java",
"Code1": "void printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"Code2": "static void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]\n"
},
{
"id": "cpp-java-HYPERCUBE_GRAPH",
"pair": "cpp-java",
"Code1": "int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"Code2": "static int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "cpp-java",
"Code1": "void findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "static void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "cpp-java",
"Code1": "int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"Code2": "static int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "cpp-java",
"Code1": "void reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n",
"Code2": "static void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "cpp-java",
"Code1": "int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n",
"Code2": "static int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "cpp-java",
"Code1": "int longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"Code2": "static int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n\n"
},
{
"id": "cpp-java-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "cpp-java",
"Code1": "int MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"Code2": "static int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "cpp-java",
"Code1": "void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"Code2": "static void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "cpp-java",
"Code1": "void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n",
"Code2": "static void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "cpp-java",
"Code1": "bool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n",
"Code2": "static boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "cpp-java",
"Code1": "int findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "cpp-java",
"Code1": "int countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-KNAPSACK_PROBLEM_1",
"pair": "cpp-java",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "cpp-java",
"Code1": "void multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"Code2": "static void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "cpp-java",
"Code1": "int maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"Code2": "static int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "cpp-java",
"Code1": "int findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "static int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_SINK_NODES_GRAPH",
"pair": "cpp-java",
"Code1": "int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "cpp-java",
"Code1": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"Code2": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "cpp-java",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "cpp-java",
"Code1": "int countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n ",
"Code2": "static int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n \n"
},
{
"id": "cpp-java-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "cpp-java",
"Code1": "bool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n",
"Code2": "boolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-LINEAR_SEARCH",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "public static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "cpp-java",
"Code1": "bool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"Code2": "static boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "cpp-java",
"Code1": "int binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"Code2": "static int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "cpp-java",
"Code1": "long countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"Code2": "static long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-MIRROR_CHARACTERS_STRING",
"pair": "cpp-java",
"Code1": "string compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n",
"Code2": "static String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "cpp-java",
"Code1": "int maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"Code2": "public static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "cpp-java",
"Code1": "long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"Code2": "static long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n\n"
},
{
"id": "cpp-java-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "cpp-java",
"Code1": "int sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"Code2": "static int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"Code2": "static int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "cpp-java",
"Code1": "int maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"Code2": "static int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "cpp-java",
"Code1": "int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"Code2": "static int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "cpp-java",
"Code1": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "cpp-java",
"Code1": "bool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n",
"Code2": "static boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "cpp-java",
"Code1": "bool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"Code2": "static boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "cpp-java",
"Code1": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n",
"Code2": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "cpp-java",
"Code1": "int maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n ",
"Code2": "static int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n \n"
},
{
"id": "cpp-java-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "cpp-java",
"Code1": "int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"Code2": "static int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "cpp-java",
"Code1": "int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"Code2": "static int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "cpp-java",
"Code1": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"Code2": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "cpp-java",
"Code1": "int minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n",
"Code2": "public static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "cpp-java",
"Code1": "void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"Code2": "static void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n\n"
},
{
"id": "cpp-java-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "cpp-java",
"Code1": "void spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "static void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "cpp-java",
"Code1": "int findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n",
"Code2": "static int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n\n"
},
{
"id": "cpp-java-NTH_PENTAGONAL_NUMBER",
"pair": "cpp-java",
"Code1": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"Code2": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "cpp-java",
"Code1": "long long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"Code2": "static long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FREQUENT_ELEMENT_ARRAY_1",
"pair": "cpp-java",
"Code1": "int mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n",
"Code2": "static int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "cpp-java",
"Code1": "int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"Code2": "static int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "cpp-java",
"Code1": "int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"Code2": "static int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n\n"
},
{
"id": "cpp-java-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "cpp-java",
"Code1": "string firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"Code2": "static String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "cpp-java",
"Code1": "void assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"Code2": "static void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "cpp-java",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "static void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "cpp-java",
"Code1": "int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "cpp-java",
"Code1": "void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n",
"Code2": "static void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "cpp-java",
"Code1": "int findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n ",
"Code2": "static int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n \n"
},
{
"id": "cpp-java-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "cpp-java",
"Code1": "int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"Code2": "static int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "cpp-java",
"Code1": "bool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"Code2": "static boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "cpp-java",
"Code1": "int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "cpp-java",
"Code1": "bool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "cpp-java",
"Code1": "int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"Code2": "static int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n\n"
},
{
"id": "cpp-java-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "cpp-java",
"Code1": "string decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"Code2": "static String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "cpp-java",
"Code1": "int minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"Code2": "static int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "cpp-java",
"Code1": "bool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"Code2": "static boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "cpp-java",
"Code1": "int countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "cpp-java",
"Code1": "int findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n",
"Code2": "static int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "cpp-java",
"Code1": "e9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n",
"Code2": "static void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ne9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "cpp-java",
"Code1": "void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n",
"Code2": "static void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-NUMBER_RECTANGLES_NM_GRID",
"pair": "cpp-java",
"Code1": "int rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"Code2": "public static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n\n"
},
{
"id": "cpp-java-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "cpp-java",
"Code1": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"Code2": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n \n"
},
{
"id": "cpp-java-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "cpp-java",
"Code1": "void subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "static void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "cpp-java",
"Code1": "bool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n",
"Code2": "static boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "cpp-java",
"Code1": "int divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"Code2": "static int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n\n"
},
{
"id": "cpp-java-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "cpp-java",
"Code1": "int superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"Code2": "static int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "cpp-java",
"Code1": "void swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "cpp-java",
"Code1": "int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"Code2": "public static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "cpp-java",
"Code1": "bool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"Code2": "static boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "cpp-java",
"Code1": "bool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "cpp-java",
"Code1": "int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n",
"Code2": "static int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n\n"
},
{
"id": "cpp-java-REVERSE_A_STRING_USING_RECURSION",
"pair": "cpp-java",
"Code1": "void reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n",
"Code2": "void reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "cpp-java",
"Code1": "long long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"Code2": "static long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "cpp-java",
"Code1": "bool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"Code2": "static boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "cpp-java",
"Code1": "int maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"Code2": "static int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "cpp-java",
"Code1": "string lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"Code2": "static String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "cpp-java",
"Code1": "int maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"Code2": "public static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "cpp-java",
"Code1": "int xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"Code2": "static int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n\n"
},
{
"id": "cpp-java-N_TH_ROOT_NUMBER",
"pair": "cpp-java",
"Code1": "double nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"Code2": "static double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n\n"
},
{
"id": "cpp-java-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "cpp-java",
"Code1": "string findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n",
"Code2": "static StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "cpp-java",
"Code1": "int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n",
"Code2": "public static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "cpp-java",
"Code1": "void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n",
"Code2": "static void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n\n"
},
{
"id": "cpp-java-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "cpp-java",
"Code1": "int findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n",
"Code2": "static int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "cpp-java",
"Code1": "void printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n",
"Code2": "static void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "cpp-java",
"Code1": "int evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "static int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "cpp-java",
"Code1": "int getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n",
"Code2": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "cpp-java",
"Code1": "void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "static void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "cpp-java",
"Code1": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n",
"Code2": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "cpp-java",
"Code1": "bool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"Code2": "static boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "cpp-java",
"Code1": "void printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n",
"Code2": "static void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "cpp-java",
"Code1": "int countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"Code2": "int countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "cpp-java",
"Code1": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n",
"Code2": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "cpp-java",
"Code1": "int calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n",
"Code2": "static int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-java",
"Code1": "void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "cpp-java",
"Code1": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"Code2": "static void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n\n"
},
{
"id": "cpp-java-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "cpp-java",
"Code1": "bool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "static boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "cpp-java",
"Code1": "unsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"Code2": "static int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "cpp-java",
"Code1": "int minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "static int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "cpp-java",
"Code1": "bool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "public static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "cpp-java",
"Code1": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"Code2": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "cpp-java",
"Code1": "bool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n",
"Code2": "public static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "cpp-java",
"Code1": "int getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"Code2": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "cpp-java",
"Code1": "int maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n",
"Code2": "static int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "cpp-java",
"Code1": "int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"Code2": "static int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "cpp-java",
"Code1": "void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n",
"Code2": "public static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-java-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "cpp-java",
"Code1": "int nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "public static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "cpp-java",
"Code1": "int countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"Code2": "static int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "cpp-java",
"Code1": "int selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"Code2": "static int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "cpp-java",
"Code1": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n",
"Code2": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n\n"
},
{
"id": "cpp-java-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "cpp-java",
"Code1": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "static boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "cpp-java",
"Code1": "int cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n",
"Code2": "static int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n\n"
},
{
"id": "cpp-java-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "cpp-java",
"Code1": "int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"Code2": "static int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "cpp-java",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "cpp-java",
"Code1": "double surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"Code2": "static double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n\n"
},
{
"id": "cpp-java-GNOME_SORT_A_STUPID_ONE",
"pair": "cpp-java",
"Code1": "void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n",
"Code2": "static void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "cpp-java",
"Code1": "int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"Code2": "public static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n\n"
},
{
"id": "cpp-java-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "cpp-java",
"Code1": "int countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"Code2": "static int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n\n"
},
{
"id": "cpp-java-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "cpp-java",
"Code1": "void generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n",
"Code2": "static void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n\n"
},
{
"id": "cpp-java-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "cpp-java",
"Code1": "void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n",
"Code2": "static void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "cpp-java",
"Code1": "void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"Code2": "static void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-FRIENDS_PAIRING_PROBLEM",
"pair": "cpp-java",
"Code1": "int countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "static int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "cpp-java",
"Code1": "int remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"Code2": "static int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n\n"
},
{
"id": "cpp-java-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "cpp-java",
"Code1": "int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n",
"Code2": "public static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "cpp-java",
"Code1": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "static int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "cpp-java",
"Code1": "int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"Code2": "static int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "cpp-java",
"Code1": "void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"Code2": "static void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "cpp-java",
"Code1": "bool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n",
"Code2": "static boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "cpp-java",
"Code1": "double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n",
"Code2": "static double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "cpp-java",
"Code1": "int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-BINARY_SEARCH",
"pair": "cpp-java",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "cpp-java",
"Code1": "int numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "cpp-java",
"Code1": "long long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"Code2": "static long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "cpp-java",
"Code1": "int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"Code2": "static int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "cpp-java",
"Code1": "int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"Code2": "static int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n\n"
},
{
"id": "cpp-java-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "cpp-java",
"Code1": "void moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n",
"Code2": "static void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n\n"
},
{
"id": "cpp-java-RECAMANS_SEQUENCE",
"pair": "cpp-java",
"Code1": "int recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n",
"Code2": "static void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "cpp-java",
"Code1": "int findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "cpp-java",
"Code1": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"Code2": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-java-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "cpp-java",
"Code1": "int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n",
"Code2": "static int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n\n"
},
{
"id": "cpp-java-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"Code2": "static int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "cpp-java",
"Code1": "int countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"Code2": "static int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n\n"
},
{
"id": "cpp-java-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "cpp-java",
"Code1": "int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"Code2": "static int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "cpp-java",
"Code1": "int substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"Code2": "static void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "cpp-java",
"Code1": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"Code2": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "cpp-java",
"Code1": "string longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n",
"Code2": "static String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "cpp-java",
"Code1": "bool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n",
"Code2": "static boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "cpp-java",
"Code1": "int calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"Code2": "public static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n\n"
},
{
"id": "cpp-java-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "cpp-java",
"Code1": "void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n",
"Code2": "static void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n\n"
},
{
"id": "cpp-java-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "cpp-java",
"Code1": "void antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n",
"Code2": "public static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "cpp-java",
"Code1": "void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n",
"Code2": "static void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "cpp-java",
"Code1": "int findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "static int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "cpp-java",
"Code1": "int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"Code2": "static int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n\n"
},
{
"id": "cpp-java-BUBBLE_SORT",
"pair": "cpp-java",
"Code1": "void bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n",
"Code2": "void bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "cpp-java",
"Code1": "int superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "static int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "cpp-java",
"Code1": "int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"Code2": "static int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "cpp-java",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"Code2": "static int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "cpp-java",
"Code1": "int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"Code2": "static int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n",
"Code2": "public static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "cpp-java",
"Code1": "INT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"Code2": "static int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nINT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "cpp-java",
"Code1": "string reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n",
"Code2": "static String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-java-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "cpp-java",
"Code1": "int minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "static int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "cpp-java",
"Code1": "int MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"Code2": "public static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-java-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "cpp-java",
"Code1": "void bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n",
"Code2": "static void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "cpp-java",
"Code1": "int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "cpp-java",
"Code1": "void printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n",
"Code2": "static void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "cpp-java",
"Code1": "int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "static int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "cpp-java",
"Code1": "void pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"Code2": "static void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "cpp-java",
"Code1": "int minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"Code2": "static int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "static int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "cpp-java",
"Code1": "string censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n",
"Code2": "static String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "cpp-java",
"Code1": "public : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"Code2": "static int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-java-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "cpp-java",
"Code1": "float getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n",
"Code2": "static float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "cpp-java",
"Code1": "int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"Code2": "static int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "cpp-java",
"Code1": "void findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n",
"Code2": "static void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n\n"
},
{
"id": "cpp-java-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "cpp-java",
"Code1": "int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"Code2": "static int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n\n"
},
{
"id": "cpp-java-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "cpp-java",
"Code1": "int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n",
"Code2": "static int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "cpp-java",
"Code1": "bool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n",
"Code2": "static boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-HOSOYAS_TRIANGLE",
"pair": "cpp-java",
"Code1": "void printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "cpp-java",
"Code1": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n",
"Code2": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVE_INSERTION_SORT",
"pair": "cpp-java",
"Code1": "void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"Code2": "static void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n\n"
},
{
"id": "cpp-java-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "static int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "cpp-java-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "cpp-java",
"Code1": "int playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n",
"Code2": "public static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "cpp-java",
"Code1": "int subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n",
"Code2": "static int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "cpp-java",
"Code1": "bool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"Code2": "static boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "cpp-java",
"Code1": "double largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n ",
"Code2": "static double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n \n"
},
{
"id": "cpp-java-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "cpp-java",
"Code1": "int getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"Code2": "static int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n \n"
},
{
"id": "cpp-java-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "cpp-java",
"Code1": "int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"Code2": "public static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "cpp-java",
"Code1": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "static int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "cpp-java",
"Code1": "int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"Code2": "static int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "cpp-java",
"Code1": "int count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n",
"Code2": "public static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "cpp-java",
"Code1": "int findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"Code2": "static int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n\n"
},
{
"id": "cpp-java-SHUFFLE_A_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "void randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n",
"Code2": "static void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "cpp-java",
"Code1": "int findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "cpp-java",
"Code1": "void translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n",
"Code2": "static void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "cpp-java",
"Code1": "int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"Code2": "static int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "cpp-java",
"Code1": "unsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n",
"Code2": "int catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SUM_SERIES_12_32_52_2N_12",
"pair": "cpp-java",
"Code1": "int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"Code2": "static int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "cpp-java",
"Code1": "int minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n",
"Code2": "static double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "cpp-java",
"Code1": "void printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n",
"Code2": "static void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n\n"
},
{
"id": "cpp-java-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "cpp-java",
"Code1": "int largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n",
"Code2": "static int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-PASCAL_TRIANGLE",
"pair": "cpp-java",
"Code1": "void printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "public static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "cpp-java",
"Code1": "int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"Code2": "static int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-CASSINIS_IDENTITY",
"pair": "cpp-java",
"Code1": "int cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n",
"Code2": "static int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n\n"
},
{
"id": "cpp-java-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "cpp-java",
"Code1": "int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"Code2": "static int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "cpp-java",
"Code1": "int waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"Code2": "static int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "cpp-java",
"Code1": "void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n",
"Code2": "static void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "cpp-java",
"Code1": "int maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"Code2": "static int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "cpp-java",
"Code1": "long long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "static int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "cpp-java",
"Code1": "int findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"Code2": "static int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "cpp-java",
"Code1": "int findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "static int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "cpp-java",
"Code1": "int maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n ",
"Code2": "static int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n \n"
},
{
"id": "cpp-java-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "cpp-java",
"Code1": "void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "static void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-NTH_EVEN_LENGTH_PALINDROME",
"pair": "cpp-java",
"Code1": "string evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n",
"Code2": "static String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "cpp-java",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "cpp-java",
"Code1": "int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "static int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "cpp-java",
"Code1": "int numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "static int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "cpp-java",
"Code1": "double circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"Code2": "static double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "cpp-java",
"Code1": "int substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n",
"Code2": "static void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "cpp-java",
"Code1": "int maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"Code2": "static int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "cpp-java",
"Code1": "int SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n",
"Code2": "public static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "cpp-java",
"Code1": "int fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n",
"Code2": "static int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "cpp-java",
"Code1": "pair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n",
"Code2": "static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "cpp-java",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "static void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "cpp-java",
"Code1": "int printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n",
"Code2": "static void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"Code2": "static int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "cpp-java",
"Code1": "string arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n ",
"Code2": "static String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n \n"
},
{
"id": "cpp-java-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "cpp-java",
"Code1": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"Code2": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "cpp-java",
"Code1": "int minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"Code2": "static int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "cpp-java",
"Code1": "string printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"Code2": "static String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n\n"
},
{
"id": "cpp-java-ROTATE_MATRIX_ELEMENTS",
"pair": "cpp-java",
"Code1": "void rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "cpp-java",
"Code1": "int maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"Code2": "static int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "cpp-java",
"Code1": "double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n",
"Code2": "static double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n\n"
},
{
"id": "cpp-java-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "cpp-java",
"Code1": "void sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n ",
"Code2": "static void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n \n"
},
{
"id": "cpp-java-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "cpp-java",
"Code1": "void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"Code2": "public static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"Code2": "private static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "cpp-java",
"Code1": "float find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n",
"Code2": "static float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "cpp-java",
"Code1": "int waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"Code2": "static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "cpp-java",
"Code1": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n\n"
},
{
"id": "cpp-java-STERN_BROCOT_SEQUENCE",
"pair": "cpp-java",
"Code1": "void SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n",
"Code2": "static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-PRUFER_CODE_TREE_CREATION",
"pair": "cpp-java",
"Code1": "void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n",
"Code2": "static void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "cpp-java",
"Code1": "int countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"Code2": "static int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "cpp-java",
"Code1": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"Code2": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "cpp-java",
"Code1": "int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"Code2": "static int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_BRACKET_NUMBER",
"pair": "cpp-java",
"Code1": "void printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"Code2": "static void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "cpp-java",
"Code1": "int countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"Code2": "static int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "cpp-java",
"Code1": "int largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"Code2": "static int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "cpp-java",
"Code1": "int findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n",
"Code2": "static int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "int maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"Code2": "static int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "cpp-java",
"Code1": "float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"Code2": "public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n\n"
},
{
"id": "cpp-java-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "cpp-java",
"Code1": "int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"Code2": "static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_ENDLESS_POINTS",
"pair": "cpp-java",
"Code1": "int countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "static int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-java",
"Code1": "void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "cpp-java",
"Code1": "int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n",
"Code2": "static int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "cpp-java",
"Code1": "bool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n",
"Code2": "public static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-java-DIAGONALLY_DOMINANT_MATRIX",
"pair": "cpp-java",
"Code1": "bool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"Code2": "static boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "cpp-java",
"Code1": "void transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"Code2": "static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "cpp-java",
"Code1": "int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"Code2": "static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "cpp-java",
"Code1": "int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"Code2": "static int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n\n"
},
{
"id": "cpp-java-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "cpp-java",
"Code1": "INT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"Code2": "public static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nINT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "cpp-java",
"Code1": "long long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"Code2": "static long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "cpp-java",
"Code1": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "cpp-java",
"Code1": "void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"Code2": "static void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n\n"
},
{
"id": "cpp-java-K_TH_DIGIT_RAISED_POWER_B",
"pair": "cpp-java",
"Code1": "int kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"Code2": "public static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "cpp-java",
"Code1": "bool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n",
"Code2": "public static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "cpp-java",
"Code1": "void printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n",
"Code2": "static void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "cpp-java",
"Code1": "bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"Code2": "public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "cpp-java",
"Code1": "bool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "static boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "cpp-java",
"Code1": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "cpp-java",
"Code1": "int maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"Code2": "static int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "cpp-java",
"Code1": "int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"Code2": "static int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "cpp-java",
"Code1": "double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"Code2": "static double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "cpp-java",
"Code1": "int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"Code2": "static int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "cpp-java",
"Code1": "int getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"Code2": "static int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "cpp-java",
"Code1": "bool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "cpp-java",
"Code1": "void printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n",
"Code2": "static void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "cpp-java",
"Code1": "bool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"Code2": "static boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "cpp-java",
"Code1": "int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"Code2": "static int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos\n"
},
{
"id": "cpp-java-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "cpp-java",
"Code1": "int minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"Code2": "static int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "cpp-java",
"Code1": "void GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"Code2": "static void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n\n"
},
{
"id": "cpp-java-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "cpp-java",
"Code1": "int countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"Code2": "static int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "cpp-java",
"Code1": "int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n",
"Code2": "static int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "cpp-java",
"Code1": "bool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "cpp-java",
"Code1": "int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"Code2": "static int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n\n"
},
{
"id": "cpp-java-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "cpp-java",
"Code1": "int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"Code2": "static int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-NTH_NON_FIBONACCI_NUMBER",
"pair": "cpp-java",
"Code1": "int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"Code2": "static int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "cpp-java",
"Code1": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n\n"
},
{
"id": "cpp-java-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "cpp-java",
"Code1": "void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n",
"Code2": "static void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "cpp-java",
"Code1": "string repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"Code2": "static String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "cpp-java",
"Code1": "string findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"Code2": "static String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n \n"
},
{
"id": "cpp-java-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "cpp-java",
"Code1": "public : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"Code2": "public static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "cpp-java",
"Code1": "void printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "static void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "cpp-java",
"Code1": "int minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"Code2": "static int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n\n"
},
{
"id": "cpp-java-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "cpp-java",
"Code1": "void luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "cpp-java",
"Code1": "void bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n",
"Code2": "static void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "cpp-java",
"Code1": "int CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "static int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "cpp-java",
"Code1": "void modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n",
"Code2": "static void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n\n"
},
{
"id": "cpp-java-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "cpp-java",
"Code1": "int minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"Code2": "static int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "cpp-java",
"Code1": "int maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"Code2": "static int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "cpp-java",
"Code1": "long long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"Code2": "static long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "cpp-java",
"Code1": "void deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n",
"Code2": "static void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "cpp-java",
"Code1": "char first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n",
"Code2": "static char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "cpp-java",
"Code1": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n",
"Code2": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n\n"
},
{
"id": "cpp-java-ARC_LENGTH_ANGLE",
"pair": "cpp-java",
"Code1": "double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"Code2": "static double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n\n"
},
{
"id": "cpp-java-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "cpp-java",
"Code1": "void findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n",
"Code2": "static void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "cpp-java",
"Code1": "bool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n ",
"Code2": "static boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-java-PRIME_NUMBERS",
"pair": "cpp-java",
"Code1": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "cpp-java",
"Code1": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n",
"Code2": "static int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "cpp-java-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "cpp-java",
"Code1": "void maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n",
"Code2": "static void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n\n"
},
{
"id": "cpp-java-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "cpp-java",
"Code1": "int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"Code2": "static int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "cpp-java",
"Code1": "void rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"Code2": "static void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n\n"
},
{
"id": "cpp-java-N_BONACCI_NUMBERS_1",
"pair": "cpp-java",
"Code1": "void bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n ",
"Code2": "static void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n \n"
},
{
"id": "cpp-java-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "cpp-java",
"Code1": "int numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"Code2": "static int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "cpp-java",
"Code1": "int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"Code2": "static int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "cpp-java",
"Code1": "int maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"Code2": "static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "cpp-java",
"Code1": "int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"Code2": "static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "cpp-java",
"Code1": "int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"Code2": "static int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "cpp-java",
"Code1": "int minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"Code2": "private static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "cpp-java",
"Code1": "void amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n",
"Code2": "public static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n\n"
},
{
"id": "cpp-java-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "cpp-java",
"Code1": "int countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"Code2": "static int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n\n"
},
{
"id": "cpp-java-BREAK_NUMBER_THREE_PARTS",
"pair": "cpp-java",
"Code1": "ll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"Code2": "static long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "cpp-java",
"Code1": "float sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n",
"Code2": "static double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-java-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "cpp-java",
"Code1": "void findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n",
"Code2": "static void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n\n"
},
{
"id": "cpp-java-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "cpp-java",
"Code1": "int countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-HEXAGONAL_NUMBER",
"pair": "cpp-java",
"Code1": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"Code2": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "cpp-java",
"Code1": "int findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"Code2": "static int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "cpp-java",
"Code1": "void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n",
"Code2": "static void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "cpp-java",
"Code1": "int count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n ",
"Code2": "static int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n \n"
},
{
"id": "cpp-java-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "cpp-java",
"Code1": "int find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n",
"Code2": "static int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n\n"
},
{
"id": "cpp-java-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "cpp-java",
"Code1": "int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "static int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "cpp-java",
"Code1": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n",
"Code2": "static double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-LEONARDO_NUMBER_1",
"pair": "cpp-java",
"Code1": "int leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"Code2": "static int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "cpp-java",
"Code1": "int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "static int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "cpp-java",
"Code1": "bool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"Code2": "static boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "cpp-java",
"Code1": "int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"Code2": "static int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "cpp-java",
"Code1": "int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "static int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-java-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "cpp-java",
"Code1": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "cpp-java",
"Code1": "char getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n ",
"Code2": "static char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n \n"
},
{
"id": "cpp-java-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "cpp-java",
"Code1": "int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"Code2": "static int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "cpp-java",
"Code1": "void printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "static void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "cpp-java",
"Code1": "void findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n",
"Code2": "private static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "cpp-java",
"Code1": "int countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"Code2": "static int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "cpp-java",
"Code1": "int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"Code2": "static int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "cpp-java",
"Code1": "int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"Code2": "static int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "cpp-java",
"Code1": "int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "static int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "cpp-java",
"Code1": "int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"Code2": "static int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n\n"
},
{
"id": "cpp-java-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "cpp-java",
"Code1": "double maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"Code2": "public static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "cpp-java",
"Code1": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "cpp-java",
"Code1": "int longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n",
"Code2": "static int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "cpp-java",
"Code1": "bool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"Code2": "static boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "cpp-java",
"Code1": "int computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"Code2": "static int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "cpp-java",
"Code1": "int minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "static int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_POWER_OF_2_1",
"pair": "cpp-java",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "cpp-java-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "cpp-java",
"Code1": "int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n",
"Code2": "static int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n\n"
},
{
"id": "cpp-java-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "cpp-java",
"Code1": "int numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "static int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "cpp-java",
"Code1": "bool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"Code2": "static boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n\n"
},
{
"id": "cpp-java-NEWMAN_CONWAY_SEQUENCE",
"pair": "cpp-java",
"Code1": "int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"Code2": "static int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "cpp-java",
"Code1": "void generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n",
"Code2": "static void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "cpp-java",
"Code1": "int countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n",
"Code2": "int countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n\n"
},
{
"id": "cpp-java-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "cpp-java",
"Code1": "int findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n",
"Code2": "static int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-LEONARDO_NUMBER",
"pair": "cpp-java",
"Code1": "int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n",
"Code2": "static int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "cpp-java",
"Code1": "int findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"Code2": "static int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "cpp-java",
"Code1": "bool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"Code2": "static boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "cpp-java",
"Code1": "int sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "static int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "cpp-java",
"Code1": "void LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "cpp-java",
"Code1": "int countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n ",
"Code2": "static int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n \n"
},
{
"id": "cpp-java-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "cpp-java",
"Code1": "int countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"Code2": "static int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "cpp-java",
"Code1": "void printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n",
"Code2": "static void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-java-FLOOR_IN_A_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"Code2": "static int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "cpp-java",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "cpp-java-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "cpp-java",
"Code1": "void printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n",
"Code2": "static void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "cpp-java",
"Code1": "void longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "static void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "cpp-java",
"Code1": "int minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"Code2": "static int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "cpp-java",
"Code1": "int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"Code2": "static int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "cpp-java",
"Code1": "void alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n",
"Code2": "static void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "cpp-java",
"Code1": "void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n",
"Code2": "static void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "cpp-java",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"Code2": "static int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "cpp-java-DICE_THROW_PROBLEM",
"pair": "cpp-java",
"Code1": "int findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n",
"Code2": "public static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "cpp-java",
"Code1": "bool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n ",
"Code2": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-java-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "cpp-java",
"Code1": "int findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"Code2": "static int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-TILING_WITH_DOMINOES",
"pair": "cpp-java",
"Code1": "int countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"Code2": "static int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "cpp-java",
"Code1": "int minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"Code2": "static int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "cpp-java",
"Code1": "bool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"Code2": "static boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "cpp-java",
"Code1": "int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"Code2": "static int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n\n"
},
{
"id": "cpp-java-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "cpp-java",
"Code1": "public : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n",
"Code2": "static int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "cpp-java",
"Code1": "int countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "static int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-java",
"Code1": "void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "cpp-java",
"Code1": "int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"Code2": "static int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "cpp-java",
"Code1": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "cpp-java",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-COMMON_CHARACTERS_N_STRINGS",
"pair": "cpp-java",
"Code1": "void commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n ",
"Code2": "public static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n \n"
},
{
"id": "cpp-java-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "cpp-java",
"Code1": "bool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n ",
"Code2": "static boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-java-MAGIC_SQUARE",
"pair": "cpp-java",
"Code1": "void generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "cpp-java",
"Code1": "int count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"Code2": "static int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "cpp-java",
"Code1": "int numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"Code2": "static int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "cpp-java",
"Code1": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"Code2": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "cpp-java",
"Code1": "int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"Code2": "static int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "cpp-java",
"Code1": "string decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"Code2": "static String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n\n"
},
{
"id": "cpp-java-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "cpp-java",
"Code1": "public : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n",
"Code2": "static void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n\n"
},
{
"id": "cpp-java-PREFIX_SUM_2D_ARRAY",
"pair": "cpp-java",
"Code1": "void prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "public static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-EULERIAN_NUMBER",
"pair": "cpp-java",
"Code1": "int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"Code2": "public static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "long long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n",
"Code2": "static int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "cpp-java",
"Code1": "int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n",
"Code2": "static int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n\n"
},
{
"id": "cpp-java-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "cpp-java",
"Code1": "int longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"Code2": "static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_AREA_SQUARE",
"pair": "cpp-java",
"Code1": "int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"Code2": "static int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n\n"
},
{
"id": "cpp-java-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "cpp-java",
"Code1": "void findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n",
"Code2": "static void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n\n"
},
{
"id": "cpp-java-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "cpp-java",
"Code1": "int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n",
"Code2": "static int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "cpp-java",
"Code1": "void findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "static void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "cpp-java",
"Code1": "int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"Code2": "static int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "cpp-java",
"Code1": "int sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n",
"Code2": "static int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "cpp-java",
"Code1": "int calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n ",
"Code2": "static int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n \n"
},
{
"id": "cpp-java-DOUBLE_FACTORIAL_1",
"pair": "cpp-java",
"Code1": "unsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n",
"Code2": "static int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n\n"
},
{
"id": "cpp-java-LONGEST_COMMON_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "cpp-java",
"Code1": "int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "static int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "cpp-java-TEMPLE_OFFERINGS",
"pair": "cpp-java",
"Code1": "int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"Code2": "static int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "cpp-java",
"Code1": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n",
"Code2": "static int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "cpp-java",
"Code1": "string constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n",
"Code2": "static String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "cpp-java",
"Code1": "unsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"Code2": "static int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-CAESAR_CIPHER",
"pair": "cpp-java",
"Code1": "string encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n",
"Code2": "public static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "cpp-java",
"Code1": "long double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n",
"Code2": "public static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "cpp-java",
"Code1": "long int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"Code2": "static long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "cpp-java",
"Code1": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"Code2": "static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a\n"
},
{
"id": "cpp-java-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "cpp-java",
"Code1": "bool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n",
"Code2": "static boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-java-SUM_PAIRWISE_PRODUCTS",
"pair": "cpp-java",
"Code1": "long long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"Code2": "static int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "cpp-java",
"Code1": "int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"Code2": "static int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n\n"
},
{
"id": "cpp-java-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "cpp-java",
"Code1": "int calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"Code2": "public static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "cpp-java",
"Code1": "void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n",
"Code2": "static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINTING_ITEMS_01_KNAPSACK",
"pair": "cpp-java",
"Code1": "void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"Code2": "static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "cpp-java",
"Code1": "int getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"Code2": "static int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "cpp-java",
"Code1": "int findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"Code2": "static int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "cpp-java",
"Code1": "string replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n",
"Code2": "static String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-java-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "cpp-java",
"Code1": "int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"Code2": "static int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "cpp-java",
"Code1": "long long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"Code2": "static long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n\n"
},
{
"id": "cpp-java-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "cpp-java",
"Code1": "bool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n",
"Code2": "static boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "cpp-java",
"Code1": "int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n",
"Code2": "static int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "cpp-java",
"Code1": "int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0",
"Code2": "static int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0\n"
},
{
"id": "cpp-java-REMAINDER_7_LARGE_NUMBERS",
"pair": "cpp-java",
"Code1": "int remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"Code2": "static int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n \n"
},
{
"id": "cpp-java-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "cpp-java",
"Code1": "bool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"Code2": "static boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "cpp-java",
"Code1": "int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"Code2": "static int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "cpp-java",
"Code1": "int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "static int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "cpp-java-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "cpp-java",
"Code1": "public : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"Code2": "static int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "cpp-java",
"Code1": "int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n",
"Code2": "static int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n\n"
},
{
"id": "cpp-java-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "cpp-java",
"Code1": "void mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n",
"Code2": "static void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n\n"
},
{
"id": "cpp-java-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "cpp-java",
"Code1": "void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"Code2": "static void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "cpp-java",
"Code1": "int minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"Code2": "public static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "cpp-java",
"Code1": "void possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n",
"Code2": "static void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_SLOPE_LINE",
"pair": "cpp-java",
"Code1": "float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"Code2": "static float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "cpp-java",
"Code1": "int countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n",
"Code2": "double countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "cpp-java",
"Code1": "int countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"Code2": "static int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "cpp-java",
"Code1": "void findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"Code2": "static void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "cpp-java",
"Code1": "string lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"Code2": "static String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "cpp-java",
"Code1": "void maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n",
"Code2": "public static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "cpp-java",
"Code1": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"Code2": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "cpp-java",
"Code1": "int findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n",
"Code2": "static int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n\n"
},
{
"id": "cpp-java-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "cpp-java",
"Code1": "long long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n",
"Code2": "static long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"Code2": "static int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "cpp-java",
"Code1": "int maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"Code2": "static int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "ll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n",
"Code2": "static int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n\n"
},
{
"id": "cpp-java-PETERSON_GRAPH",
"pair": "cpp-java",
"Code1": "bool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n",
"Code2": "static boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "cpp-java",
"Code1": "bool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n",
"Code2": "static boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "cpp-java",
"Code1": "void generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"Code2": "static void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVE_FUNCTIONS",
"pair": "cpp-java",
"Code1": "void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"Code2": "static void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n\n"
},
{
"id": "cpp-java-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "cpp-java",
"Code1": "int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "static int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "cpp-java",
"Code1": "string minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n",
"Code2": "static String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "cpp-java",
"Code1": "int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"Code2": "static int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "cpp-java",
"Code1": "int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"Code2": "static int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MISSING_NUMBER",
"pair": "cpp-java",
"Code1": "int getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"Code2": "static int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "cpp-java",
"Code1": "void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n",
"Code2": "static void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n\n"
},
{
"id": "cpp-java-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "cpp-java",
"Code1": "bool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "cpp-java",
"Code1": "void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n",
"Code2": "static void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n\n"
},
{
"id": "cpp-java-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "cpp-java",
"Code1": "int findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n",
"Code2": "public static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n\n"
},
{
"id": "cpp-java-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "cpp-java",
"Code1": "void sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n",
"Code2": "public static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "cpp-java",
"Code1": "int countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "cpp-java",
"Code1": "int count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"Code2": "static int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "cpp-java",
"Code1": "int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"Code2": "static int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"Code2": "static int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "cpp-java",
"Code1": "bool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n",
"Code2": "static boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "cpp-java",
"Code1": "int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"Code2": "static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "cpp-java",
"Code1": "int countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-JUMP_SEARCH",
"pair": "cpp-java",
"Code1": "int jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"Code2": "public static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_X_Y_SATISFYING_AX_N",
"pair": "cpp-java",
"Code1": "void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n",
"Code2": "static void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n\n"
},
{
"id": "cpp-java-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "cpp-java",
"Code1": "string longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"Code2": "static String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "cpp-java",
"Code1": "void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n",
"Code2": "static void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "cpp-java",
"Code1": "bool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"Code2": "boolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "cpp-java",
"Code1": "int find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n",
"Code2": "static int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "cpp-java",
"Code1": "void printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n",
"Code2": "static void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n\n"
},
{
"id": "cpp-java-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "cpp-java",
"Code1": "void sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "public static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "cpp-java",
"Code1": "int find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n",
"Code2": "static int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "cpp-java",
"Code1": "char maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "static char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "cpp-java",
"Code1": "int solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n",
"Code2": "static int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "cpp-java",
"Code1": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"Code2": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint Circumference ( int a ) {\n return 4 * a ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "cpp-java",
"Code1": "int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n\n"
},
{
"id": "cpp-java-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "cpp-java",
"Code1": "void pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n",
"Code2": "static void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "cpp-java",
"Code1": "ll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n ",
"Code2": "static int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n \n"
},
{
"id": "cpp-java-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "cpp-java",
"Code1": "void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"Code2": "public static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "cpp-java",
"Code1": "int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"Code2": "static int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n\n"
},
{
"id": "cpp-java-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "cpp-java",
"Code1": "int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"Code2": "static int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "cpp-java",
"Code1": "bool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"Code2": "static Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "cpp-java",
"Code1": "int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"Code2": "static int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "cpp-java",
"Code1": "void CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n",
"Code2": "static void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "cpp-java",
"Code1": "uint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"Code2": "static int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nuint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit\n"
},
{
"id": "cpp-java-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "cpp-java",
"Code1": "bool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "cpp-java",
"Code1": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"Code2": "static int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n\n"
},
{
"id": "cpp-java-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "cpp-java",
"Code1": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n ",
"Code2": "static void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n \n"
},
{
"id": "cpp-java-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "cpp-java",
"Code1": "int nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"Code2": "static int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n\n"
},
{
"id": "cpp-java-COCKTAIL_SORT",
"pair": "cpp-java",
"Code1": "void CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n",
"Code2": "void cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n\n"
},
{
"id": "cpp-java-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "cpp-java",
"Code1": "void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"Code2": "static void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n\n"
},
{
"id": "cpp-java-BINARY_SEARCH_1",
"pair": "cpp-java",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_XOR_VALUE_PAIR",
"pair": "cpp-java",
"Code1": "int minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"Code2": "static int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "cpp-java",
"Code1": "int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "public static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "cpp-java",
"Code1": "char first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n",
"Code2": "static char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "cpp-java",
"Code1": "int maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"Code2": "static int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "cpp-java",
"Code1": "double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"Code2": "static double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "cpp-java",
"Code1": "void rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "static void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "cpp-java",
"Code1": "void greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n",
"Code2": "static void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "cpp-java",
"Code1": "int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"Code2": "static int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_COMMON_SUBSTRING",
"pair": "cpp-java",
"Code1": "int LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"Code2": "static int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "cpp-java",
"Code1": "int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"Code2": "static int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIBONACCI_MODULO_P",
"pair": "cpp-java",
"Code1": "int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"Code2": "static int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n\n"
},
{
"id": "cpp-java-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "cpp-java",
"Code1": "void reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"Code2": "static void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "cpp-java",
"Code1": "int longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n ",
"Code2": "static int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n \n"
},
{
"id": "cpp-java-SUM_FIBONACCI_NUMBERS",
"pair": "cpp-java",
"Code1": "int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "static int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "cpp-java",
"Code1": "INT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nINT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "cpp-java",
"Code1": "int sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"Code2": "static int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "cpp-java",
"Code1": "void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"Code2": "static void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "cpp-java",
"Code1": "int patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n",
"Code2": "static int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n\n"
},
{
"id": "cpp-java-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "cpp-java",
"Code1": "int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"Code2": "public static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "cpp-java",
"Code1": "void parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n",
"Code2": "static void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "cpp-java",
"Code1": "int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"Code2": "static int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "cpp-java",
"Code1": "void longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n ",
"Code2": "static void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n \n"
},
{
"id": "cpp-java-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "cpp-java",
"Code1": "int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"Code2": "static int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n\n"
},
{
"id": "cpp-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "cpp-java",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_POWER_OF_2",
"pair": "cpp-java",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "cpp-java",
"Code1": "int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"Code2": "static int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n\n"
},
{
"id": "cpp-java-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "cpp-java",
"Code1": "void reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n",
"Code2": "static void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "cpp-java",
"Code1": "string nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n",
"Code2": "public static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n\n"
},
{
"id": "cpp-java-SUM_BINOMIAL_COEFFICIENTS",
"pair": "cpp-java",
"Code1": "int binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "static int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "cpp-java",
"Code1": "bool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"Code2": "public static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"Code2": "static int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "cpp-java",
"Code1": "void maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n",
"Code2": "static void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n\n"
},
{
"id": "cpp-java-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "cpp-java",
"Code1": "int bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n",
"Code2": "static boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "cpp-java",
"Code1": "int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"Code2": "static int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "cpp-java",
"Code1": "bool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "static boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "cpp-java",
"Code1": "void decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n",
"Code2": "static void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n\n"
},
{
"id": "cpp-java-FRIENDS_PAIRING_PROBLEM_1",
"pair": "cpp-java",
"Code1": "int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"Code2": "static int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "cpp-java",
"Code1": "int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"Code2": "static int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "cpp-java",
"Code1": "int countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"Code2": "static int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "cpp-java",
"Code1": "bool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"Code2": "static boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "cpp-java",
"Code1": "int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"Code2": "static int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "cpp-java",
"Code1": "public : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npublic : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "cpp-java",
"Code1": "int lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n",
"Code2": "static int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "cpp-java",
"Code1": "unsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"Code2": "static int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n",
"Code2": "static int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "cpp-java",
"Code1": "int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"Code2": "static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "cpp-java",
"Code1": "void carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n",
"Code2": "static void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "cpp-java",
"Code1": "int sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"Code2": "public static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "cpp-java",
"Code1": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"Code2": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "cpp-java",
"Code1": "int maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "cpp-java",
"Code1": "void segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n",
"Code2": "static void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n\n"
},
{
"id": "cpp-java-MERGING_INTERVALS",
"pair": "cpp-java",
"Code1": "void mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n",
"Code2": "public static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "cpp-java",
"Code1": "float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n",
"Code2": "static float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "cpp-java",
"Code1": "int findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"Code2": "static int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n \n"
},
{
"id": "cpp-java-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "cpp-java",
"Code1": "int minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"Code2": "static int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "cpp-java",
"Code1": "int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"Code2": "static int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "cpp-java",
"Code1": "int isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"Code2": "static boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "cpp-java",
"Code1": "void printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "static void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "cpp-java",
"Code1": "int minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"Code2": "static int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "cpp-java",
"Code1": "long long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "static int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "cpp-java",
"Code1": "bool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n",
"Code2": "static boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "cpp-java",
"Code1": "int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"Code2": "static int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "cpp-java",
"Code1": "int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"Code2": "static int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "cpp-java",
"Code1": "int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"Code2": "static int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "cpp-java",
"Code1": "int assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"Code2": "static int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n \n"
},
{
"id": "cpp-java-TRIANGULAR_NUMBERS",
"pair": "cpp-java",
"Code1": "bool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"Code2": "static boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-PANGRAM_CHECKING",
"pair": "cpp-java",
"Code1": "bool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"Code2": "public static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n\n"
},
{
"id": "cpp-java-INTERPOLATION_SEARCH",
"pair": "cpp-java",
"Code1": "int interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "static int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FITTING_SHELVES_PROBLEM",
"pair": "cpp-java",
"Code1": "void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n",
"Code2": "static void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "cpp-java",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n",
"Code2": "static int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n\n"
},
{
"id": "cpp-java-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "cpp-java",
"Code1": "void kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "public static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "cpp-java",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "cpp-java",
"Code1": "bool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n",
"Code2": "static boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "cpp-java",
"Code1": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "cpp-java",
"Code1": "int findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"Code2": "int findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n \n"
},
{
"id": "cpp-java-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "cpp-java",
"Code1": "int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n",
"Code2": "static int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "cpp-java",
"Code1": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"Code2": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n\n"
},
{
"id": "cpp-java-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "cpp-java",
"Code1": "int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"Code2": "static int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "cpp-java",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n",
"Code2": "static void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "cpp-java",
"Code1": "int decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n",
"Code2": "public void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n\n"
},
{
"id": "cpp-java-SUPER_PRIME",
"pair": "cpp-java",
"Code1": "bool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"Code2": "static void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "cpp-java",
"Code1": "int abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "static int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "cpp-java",
"Code1": "int countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n",
"Code2": "static int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "cpp-java",
"Code1": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"Code2": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "cpp-java",
"Code1": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "cpp-java",
"Code1": "int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"Code2": "static int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n\n"
},
{
"id": "cpp-java-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "cpp-java",
"Code1": "void findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n",
"Code2": "public static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-java-MARKOV_MATRIX",
"pair": "cpp-java",
"Code1": "bool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "static boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "cpp-java",
"Code1": "int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"Code2": "static int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "cpp-java",
"Code1": "void recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"Code2": "static void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "cpp-java",
"Code1": "bool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"Code2": "boolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "cpp-java",
"Code1": "double findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"Code2": "static double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n\n"
},
{
"id": "cpp-java-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "cpp-java",
"Code1": "int sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"Code2": "public static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n",
"Code2": "static int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_MISSING_NUMBER_1",
"pair": "cpp-java",
"Code1": "int getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"Code2": "static int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_POWER_OF_2_2",
"pair": "cpp-java",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "cpp-java",
"Code1": "void add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"Code2": "static void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "cpp-java-ENTRINGER_NUMBER_1",
"pair": "cpp-java",
"Code1": "int zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n ",
"Code2": "static int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n \n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "cpp-java",
"Code1": "int eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"Code2": "static int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "cpp-java",
"Code1": "string noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n",
"Code2": "public static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-java-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "cpp-java",
"Code1": "int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"Code2": "static int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "cpp-java",
"Code1": "int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"Code2": "static int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n\n"
},
{
"id": "cpp-java-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "cpp-java",
"Code1": "bool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n",
"Code2": "static boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-HARDY_RAMANUJAN_THEOREM",
"pair": "cpp-java",
"Code1": "int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"Code2": "static int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "cpp-java",
"Code1": "void query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n",
"Code2": "static void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"Code2": "static int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "cpp-java",
"Code1": "void findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n",
"Code2": "static void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "cpp-java",
"Code1": "int countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"Code2": "int countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "cpp-java",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "cpp-java",
"Code1": "void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n",
"Code2": "static void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "cpp-java",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "cpp-java",
"Code1": "- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"Code2": "static int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\n- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "cpp-java",
"Code1": "void printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n",
"Code2": "static void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "cpp-java",
"Code1": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-RECURSION",
"pair": "cpp-java",
"Code1": "void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n",
"Code2": "static void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-java-SHIFT_MATRIX_ELEMENTS_K",
"pair": "cpp-java",
"Code1": "void shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n",
"Code2": "static void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "cpp-java",
"Code1": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"Code2": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n \n"
},
{
"id": "cpp-java-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "cpp-java",
"Code1": "void findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"Code2": "static void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "cpp-java",
"Code1": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n ",
"Code2": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n \n"
},
{
"id": "cpp-java-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "cpp-java",
"Code1": "bool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"Code2": "static boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "cpp-java",
"Code1": "int count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "cpp-java",
"Code1": "int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"Code2": "static int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "cpp-java",
"Code1": "void smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "static void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "cpp-java",
"Code1": "void findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n",
"Code2": "static void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "cpp-java",
"Code1": "int minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n",
"Code2": "static int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "cpp-java",
"Code1": "int singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"Code2": "static int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "cpp-java",
"Code1": "int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "cpp-java",
"Code1": "void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n",
"Code2": "static void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "cpp-java",
"Code1": "bool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n ",
"Code2": "static boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-java-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "cpp-java",
"Code1": "void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n",
"Code2": "static void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n\n"
},
{
"id": "cpp-java-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "cpp-java",
"Code1": "void printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "static void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "cpp-java",
"Code1": "int findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n",
"Code2": "static int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "cpp-java",
"Code1": "void printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n",
"Code2": "static void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "cpp-java",
"Code1": "char * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n",
"Code2": "static String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "cpp-java",
"Code1": "double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n",
"Code2": "static double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-java-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "cpp-java",
"Code1": "int countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "static int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "cpp-java",
"Code1": "int sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n",
"Code2": "static int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "cpp-java",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "cpp-java",
"Code1": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"Code2": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "cpp-java",
"Code1": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n",
"Code2": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n\n"
},
{
"id": "cpp-java-MAJORITY_ELEMENT_1",
"pair": "cpp-java",
"Code1": "void findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n",
"Code2": "private static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "cpp-java",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "cpp-java",
"Code1": "void replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n",
"Code2": "static void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-java-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "cpp-java",
"Code1": "void findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"Code2": "public static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_SUBSTRINGS_STRING",
"pair": "cpp-java",
"Code1": "int countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "static int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "cpp-java",
"Code1": "int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"Code2": "static int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "cpp-java",
"Code1": "int maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n",
"Code2": "static int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "cpp-java",
"Code1": "int countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"Code2": "static int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_PATH_SUM_MATRIX",
"pair": "cpp-java",
"Code1": "int findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n",
"Code2": "static int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "bool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"Code2": "static boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "cpp-java",
"Code1": "int check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "cpp-java",
"Code1": "void swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n",
"Code2": "static void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n\n"
},
{
"id": "cpp-java-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "cpp-java",
"Code1": "int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"Code2": "static int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "cpp-java",
"Code1": "bool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"Code2": "static boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "cpp-java",
"Code1": "void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n",
"Code2": "static void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "cpp-java",
"Code1": "void zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n",
"Code2": "static void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "cpp-java",
"Code1": "int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"Code2": "static int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "cpp-java",
"Code1": "bool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "cpp-java",
"Code1": "bool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"Code2": "static boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "cpp-java",
"Code1": "bool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"Code2": "static boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-KNAPSACK_PROBLEM",
"pair": "cpp-java",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "cpp-java",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"Code2": "static int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "cpp-java",
"Code1": "int breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"Code2": "static int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "cpp-java",
"Code1": "void decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n",
"Code2": "static void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n\n"
},
{
"id": "cpp-java-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "cpp-java",
"Code1": "int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"Code2": "static int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n\n"
},
{
"id": "cpp-java-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "cpp-java",
"Code1": "bool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"Code2": "static boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "cpp-java",
"Code1": "bool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "static boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "cpp-java",
"Code1": "void strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n",
"Code2": "static void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "cpp-java",
"Code1": "void evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n",
"Code2": "static void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "cpp-java",
"Code1": "bool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"Code2": "static Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-java-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "cpp-java",
"Code1": "bool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n",
"Code2": "static boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "cpp-java",
"Code1": "int countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "static int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-java-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "cpp-java",
"Code1": "void findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n",
"Code2": "static void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n\n"
},
{
"id": "cpp-java-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "cpp-java",
"Code1": "void findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n",
"Code2": "static void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n\n"
},
{
"id": "cpp-java-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "cpp-java",
"Code1": "void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "static void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "cpp-java",
"Code1": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-java-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "cpp-java",
"Code1": "int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"Code2": "public static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "cpp-java",
"Code1": "int solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"Code2": "static int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n\n"
},
{
"id": "cpp-java-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "cpp-java",
"Code1": "int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"Code2": "static int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "cpp-java",
"Code1": "int countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"Code2": "static int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-java-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "cpp-java",
"Code1": "void sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"Code2": "static void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "cpp-java",
"Code1": "bool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"Code2": "static boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "cpp-java",
"Code1": "void minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n",
"Code2": "static void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "cpp-java",
"Code1": "void KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n",
"Code2": "static void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n\n"
},
{
"id": "cpp-java-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "cpp-java",
"Code1": "void swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n",
"Code2": "static void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-java-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "cpp-java",
"Code1": "void psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n",
"Code2": "public static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "cpp-java",
"Code1": "int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n ",
"Code2": "static int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n \n"
},
{
"id": "cpp-java-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "cpp-java",
"Code1": "int minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"Code2": "static int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n\n"
},
{
"id": "cpp-java-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "cpp-java",
"Code1": "string maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n",
"Code2": "static String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "cpp-java",
"Code1": "int findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n ",
"Code2": "static int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n \n"
},
{
"id": "cpp-java-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "cpp-java",
"Code1": "void printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n",
"Code2": "static void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "cpp-java",
"Code1": "int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"Code2": "static int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "cpp-java",
"Code1": "int minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"Code2": "public static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "cpp-java",
"Code1": "int largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n",
"Code2": "static int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "cpp-java",
"Code1": "float exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"Code2": "static float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nfloat exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-java-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "cpp-java",
"Code1": "int firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "static int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "cpp-java",
"Code1": "int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"Code2": "static int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "cpp-java",
"Code1": "int maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n",
"Code2": "public static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "cpp-java",
"Code1": "int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "static int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-java-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "cpp-java",
"Code1": "int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "cpp-java",
"Code1": "bool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n ",
"Code2": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-java-SUM_FACTORS_NUMBER",
"pair": "cpp-java",
"Code1": "int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"Code2": "static int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n\n"
},
{
"id": "cpp-java-ROTATE_MATRIX_180_DEGREE",
"pair": "cpp-java",
"Code1": "void rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"Code2": "static void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "cpp-java",
"Code1": "void printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n",
"Code2": "static void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "cpp-java",
"Code1": "int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"Code2": "static int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "cpp-java",
"Code1": "double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n",
"Code2": "static double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\ndouble areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n\n"
},
{
"id": "cpp-java-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "cpp-java",
"Code1": "int findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "static int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-java-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "cpp-java",
"Code1": "void printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n",
"Code2": "static void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "cpp-java",
"Code1": "int numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n ",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n \n"
},
{
"id": "cpp-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "cpp-java",
"Code1": "bool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"Code2": "static int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-java-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "cpp-java",
"Code1": "int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "static int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "cpp-java",
"Code1": "int findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "static int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "cpp-java",
"Code1": "int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"Code2": "static int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n\n"
},
{
"id": "cpp-java-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "cpp-java",
"Code1": "long int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"Code2": "static long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nlong int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n\n"
},
{
"id": "cpp-java-DIVISIBILITY_CHECK",
"pair": "cpp-java",
"Code1": "void divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n",
"Code2": "static void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "cpp-java",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-java-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "cpp-java",
"Code1": "int minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "static int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "cpp-java",
"Code1": "int height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n",
"Code2": "static int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n\n"
},
{
"id": "cpp-java-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "cpp-java",
"Code1": "bool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n",
"Code2": "static boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-java-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "cpp-java",
"Code1": "void removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n",
"Code2": "static void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n\n"
},
{
"id": "cpp-java-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "cpp-java",
"Code1": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "cpp-java-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "cpp-java",
"Code1": "int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"Code2": "public static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-java-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "cpp-java",
"Code1": "int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"Code2": "static int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n\n"
},
{
"id": "cpp-java-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "cpp-java",
"Code1": "int getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"Code2": "static int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n\n"
},
{
"id": "cpp-java-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "cpp-java",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-java-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "cpp-java",
"Code1": "void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"Code2": "static void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n\n"
},
{
"id": "cpp-java-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "cpp-java",
"Code1": "int maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"Code2": "static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n\n"
},
{
"id": "cpp-java-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "cpp-java",
"Code1": "pair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n",
"Code2": "static void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\npair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n\n"
},
{
"id": "cpp-java-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "cpp-java",
"Code1": "int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n",
"Code2": "static int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-java-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "cpp-java",
"Code1": "bool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "boolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-java-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "cpp-java",
"Code1": "void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n",
"Code2": "static void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n\n"
},
{
"id": "cpp-java-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "cpp-java",
"Code1": "int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"Code2": "public static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "cpp-java",
"Code1": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n ",
"Code2": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n \n"
},
{
"id": "cpp-java-DIVISIBILITY_BY_7",
"pair": "cpp-java",
"Code1": "int isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"Code2": "static boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n\n"
},
{
"id": "cpp-java-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "cpp-java",
"Code1": "int findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n ",
"Code2": "static int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n \n"
},
{
"id": "cpp-java-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "cpp-java",
"Code1": "int findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"Code2": "static int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n\n"
},
{
"id": "cpp-java-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "cpp-java",
"Code1": "int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"Code2": "static int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "cpp-java",
"Code1": "bool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-java-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "cpp-java",
"Code1": "string to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n",
"Code2": "static String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n\n"
},
{
"id": "cpp-java-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "cpp-java",
"Code1": "int remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n ",
"Code2": "static int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n \n"
},
{
"id": "cpp-java-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "cpp-java",
"Code1": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n",
"Code2": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-java-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "cpp-java",
"Code1": "string getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n",
"Code2": "static String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-java-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "cpp-java",
"Code1": "bool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"Code2": "static boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nbool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-java-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "cpp-java",
"Code1": "void center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n",
"Code2": "static void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-java-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "cpp-java",
"Code1": "void findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"Code2": "static void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-java-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "cpp-java",
"Code1": "ll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"Code2": "static long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n\n"
},
{
"id": "cpp-java-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "cpp-java",
"Code1": "string Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"Code2": "static String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-java-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "cpp-java",
"Code1": "int minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"Code2": "static int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-java-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "cpp-java",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n",
"Code2": "static int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n\n"
},
{
"id": "cpp-java-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "cpp-java",
"Code1": "char getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n ",
"Code2": "static char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nchar getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n \n"
},
{
"id": "cpp-java-SUM_TWO_LARGE_NUMBERS",
"pair": "cpp-java",
"Code1": "string findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n",
"Code2": "static String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nstring findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n\n"
},
{
"id": "cpp-java-NEXT_GREATER_ELEMENT",
"pair": "cpp-java",
"Code1": "void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n",
"Code2": "static void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n",
"instruction": "Translate the given code from cpp to java. The input Code is marked with and .",
"input": "\nvoid printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "cpp-python",
"Code1": "void printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n",
"Code2": "def printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "cpp-python",
"Code1": "float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"Code2": "def findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "cpp-python",
"Code1": "bool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n",
"Code2": "def isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "cpp-python",
"Code1": "int nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"Code2": "def nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-python",
"Code1": "void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "def firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-NON_REPEATING_ELEMENT_1",
"pair": "cpp-python",
"Code1": "int firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "def firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "cpp-python",
"Code1": "bool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n ",
"Code2": "def distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-python-BREAK_NUMBER_THREE_PARTS_1",
"pair": "cpp-python",
"Code1": "ll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"Code2": "def count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n",
"Code2": "def maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "cpp-python",
"Code1": "int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"Code2": "def calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "cpp-python",
"Code1": "int smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n",
"Code2": "def smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "cpp-python",
"Code1": "char findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"Code2": "def findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n\n"
},
{
"id": "cpp-python-RECAMANS_SEQUENCE_1",
"pair": "cpp-python",
"Code1": "void recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"Code2": "def recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "cpp-python",
"Code1": "int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"Code2": "def findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "cpp-python",
"Code1": "void countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n",
"Code2": "def countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "cpp-python",
"Code1": "int maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "cpp-python",
"Code1": "bool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-FRIENDS_PAIRING_PROBLEM_2",
"pair": "cpp-python",
"Code1": "int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n\n"
},
{
"id": "cpp-python-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "cpp-python",
"Code1": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "cpp-python",
"Code1": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "def findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "cpp-python-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "cpp-python",
"Code1": "void subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n",
"Code2": "def subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "cpp-python",
"Code1": "bool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "cpp-python",
"Code1": "void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"Code2": "def solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n\n"
},
{
"id": "cpp-python-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "cpp-python",
"Code1": "public : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"Code2": "def squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "cpp-python",
"Code1": "int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"Code2": "def CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "cpp-python",
"Code1": "int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"Code2": "def multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "cpp-python",
"Code1": "bool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n",
"Code2": "def prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "cpp-python",
"Code1": "double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n",
"Code2": "def polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n\n"
},
{
"id": "cpp-python-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "cpp-python",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "cpp-python",
"Code1": "int chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n ",
"Code2": "def chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n \n"
},
{
"id": "cpp-python-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "cpp-python",
"Code1": "double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"Code2": "def compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n\n"
},
{
"id": "cpp-python-MAJORITY_ELEMENT",
"pair": "cpp-python",
"Code1": "void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n",
"Code2": "def findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "cpp-python",
"Code1": "bool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "cpp-python",
"Code1": "string findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"Code2": "def findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n \n"
},
{
"id": "cpp-python-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "cpp-python",
"Code1": "int countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"Code2": "def countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "cpp-python",
"Code1": "void pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n",
"Code2": "def pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n\n"
},
{
"id": "cpp-python-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "cpp-python",
"Code1": "int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"Code2": "def nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n\n"
},
{
"id": "cpp-python-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "cpp-python",
"Code1": "void shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n",
"Code2": "def shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "cpp-python",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "cpp-python-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "cpp-python",
"Code1": "int summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n",
"Code2": "def summingSeries ( n ) :\n return math.pow ( n , 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "cpp-python",
"Code1": "bool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"Code2": "def isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"Code2": "def findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "cpp-python",
"Code1": "int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"Code2": "def numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "cpp-python",
"Code1": "int removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"Code2": "def removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "cpp-python",
"Code1": "void find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n",
"Code2": "def find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-NON_REPEATING_ELEMENT",
"pair": "cpp-python",
"Code1": "int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "cpp-python",
"Code1": "void middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n",
"Code2": "def middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n\n"
},
{
"id": "cpp-python-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "cpp-python",
"Code1": "long long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"Code2": "def moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "cpp-python",
"Code1": "void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n",
"Code2": "def pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-SUM_PAIRWISE_PRODUCTS_2",
"pair": "cpp-python",
"Code1": "long long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"Code2": "def findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "cpp-python",
"Code1": "int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"Code2": "def fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "cpp-python",
"Code1": "int largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n",
"Code2": "def largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "cpp-python",
"Code1": "bool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "cpp-python",
"Code1": "int minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "def minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "cpp-python",
"Code1": "void arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n",
"Code2": "def arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "cpp-python",
"Code1": "int getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n ",
"Code2": "def getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n \n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "cpp-python",
"Code1": "int carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"Code2": "def carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "cpp-python",
"Code1": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "cpp-python",
"Code1": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"Code2": "def findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "cpp-python",
"Code1": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n",
"Code2": "def getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "cpp-python",
"Code1": "int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"Code2": "def maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "cpp-python",
"Code1": "void printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n",
"Code2": "def printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "cpp-python",
"Code1": "void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n",
"Code2": "def printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "cpp-python",
"Code1": "int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"Code2": "def circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "cpp-python",
"Code1": "void countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n",
"Code2": "def countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "cpp-python",
"Code1": "float findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "def findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "cpp-python",
"Code1": "int countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "cpp-python",
"Code1": "int lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n",
"Code2": "def lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "cpp-python",
"Code1": "int editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "cpp-python",
"Code1": "int countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"Code2": "def countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "cpp-python",
"Code1": "void longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n",
"Code2": "def longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "cpp-python",
"Code1": "void printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n",
"Code2": "def printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "cpp-python",
"Code1": "bool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n",
"Code2": "def isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "cpp-python",
"Code1": "int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"Code2": "def maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "cpp-python",
"Code1": "void printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n ",
"Code2": "def printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n \n"
},
{
"id": "cpp-python-COUNT_SORTED_ROWS_MATRIX",
"pair": "cpp-python",
"Code1": "int sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"Code2": "def sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "cpp-python",
"Code1": "int countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "def countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "cpp-python",
"Code1": "int findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n",
"Code2": "def findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "void printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n",
"Code2": "def printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "cpp-python",
"Code1": "int maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n",
"Code2": "def maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "cpp-python",
"Code1": "int largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n",
"Code2": "def largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "cpp-python",
"Code1": "char encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n",
"Code2": "def encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "def countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "cpp-python",
"Code1": "int maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"Code2": "def maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "cpp-python",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "cpp-python",
"Code1": "int countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n ",
"Code2": "def countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n \n"
},
{
"id": "cpp-python-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "cpp-python",
"Code1": "int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"Code2": "def nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_1",
"pair": "cpp-python",
"Code1": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"Code2": "def fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "cpp-python",
"Code1": "int countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "def countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "cpp-python",
"Code1": "int countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"Code2": "def countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "cpp-python",
"Code1": "string decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n",
"Code2": "def decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "cpp-python",
"Code1": "int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"Code2": "def countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '\n"
},
{
"id": "cpp-python-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "cpp-python",
"Code1": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"Code2": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "cpp-python",
"Code1": "int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"Code2": "def longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "cpp-python",
"Code1": "int maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"Code2": "def maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "cpp-python",
"Code1": "int evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n",
"Code2": "def evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n\n"
},
{
"id": "cpp-python-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "cpp-python",
"Code1": "int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"Code2": "def findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "cpp-python",
"Code1": "int numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"Code2": "def numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "cpp-python",
"Code1": "int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"Code2": "def countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "cpp-python",
"Code1": "int minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "cpp-python",
"Code1": "void spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n",
"Code2": "def spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "cpp-python",
"Code1": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n",
"Code2": "def printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "cpp-python",
"Code1": "int minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"Code2": "def minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n\n"
},
{
"id": "cpp-python-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "cpp-python",
"Code1": "int findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "def findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "cpp-python",
"Code1": "void convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n",
"Code2": "def convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "cpp-python",
"Code1": "unsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"Code2": "def decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n\n"
},
{
"id": "cpp-python-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "cpp-python",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "cpp-python",
"Code1": "void transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n",
"Code2": "def transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "cpp-python",
"Code1": "void findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"Code2": "def findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "cpp-python",
"Code1": "void printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "def printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_AREA_QUADRILATERAL",
"pair": "cpp-python",
"Code1": "double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"Code2": "def maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n\n"
},
{
"id": "cpp-python-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "cpp-python",
"Code1": "int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"Code2": "def Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n\n"
},
{
"id": "cpp-python-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "cpp-python",
"Code1": "int printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n ",
"Code2": "def printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n \n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "cpp-python",
"Code1": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"Code2": "def isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "cpp-python",
"Code1": "int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n",
"Code2": "def countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n\n"
},
{
"id": "cpp-python-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "cpp-python",
"Code1": "int countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"Code2": "def CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "cpp-python",
"Code1": "void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n",
"Code2": "def twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "cpp-python",
"Code1": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "cpp-python",
"Code1": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"Code2": "def findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "cpp-python",
"Code1": "bool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "cpp-python",
"Code1": "int getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-PRIME_FACTORS_BIG_NUMBER",
"pair": "cpp-python",
"Code1": "void factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n",
"Code2": "def factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "cpp-python",
"Code1": "int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"Code2": "def findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "cpp-python",
"Code1": "bool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "cpp-python",
"Code1": "bool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n",
"Code2": "def isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "cpp-python",
"Code1": "void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n",
"Code2": "def bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n\n"
},
{
"id": "cpp-python-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "cpp-python",
"Code1": "int solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"Code2": "def solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n\n"
},
{
"id": "cpp-python-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "cpp-python",
"Code1": "void direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n",
"Code2": "def direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-python-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "cpp-python",
"Code1": "void splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n",
"Code2": "def splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "cpp-python",
"Code1": "int binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"Code2": "def binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n\n"
},
{
"id": "cpp-python-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "cpp-python",
"Code1": "void printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n",
"Code2": "def printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "cpp-python",
"Code1": "void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n",
"Code2": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n\n"
},
{
"id": "cpp-python-SWAP_TWO_NIBBLES_BYTE",
"pair": "cpp-python",
"Code1": "int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"Code2": "def swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "cpp-python-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "cpp-python",
"Code1": "int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"Code2": "def countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SUM_DIVISORS_1_N_1",
"pair": "cpp-python",
"Code1": "int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"Code2": "def divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "cpp-python",
"Code1": "int addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"Code2": "def addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "cpp-python",
"Code1": "int check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "cpp-python",
"Code1": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n ",
"Code2": "def findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n \n"
},
{
"id": "cpp-python-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "cpp-python",
"Code1": "int minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"Code2": "def minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n\n"
},
{
"id": "cpp-python-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "cpp-python",
"Code1": "void computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n",
"Code2": "def computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "cpp-python",
"Code1": "int numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-STOOGE_SORT",
"pair": "cpp-python",
"Code1": "void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"Code2": "def stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "cpp-python",
"Code1": "void solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n",
"Code2": "def solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "cpp-python",
"Code1": "int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"Code2": "def turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "cpp-python",
"Code1": "void printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n",
"Code2": "def printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "cpp-python",
"Code1": "int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "cpp-python",
"Code1": "int stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n ",
"Code2": "def stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n \n"
},
{
"id": "cpp-python-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "cpp-python",
"Code1": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"Code2": "def KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n\n"
},
{
"id": "cpp-python-SUM_PAIRWISE_PRODUCTS_1",
"pair": "cpp-python",
"Code1": "long long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "cpp-python",
"Code1": "void recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n",
"Code2": "def recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "cpp-python",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"Code2": "def subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "cpp-python",
"Code1": "int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n",
"Code2": "def getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "cpp-python",
"Code1": "unsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"Code2": "def getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "cpp-python",
"Code1": "bool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n",
"Code2": "def allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "cpp-python",
"Code1": "long long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n",
"Code2": "def maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "cpp-python",
"Code1": "long long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n",
"Code2": "def countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNTING_INVERSIONS",
"pair": "cpp-python",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"Code2": "def getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n\n"
},
{
"id": "cpp-python-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "cpp-python",
"Code1": "void printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n",
"Code2": "def printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-DELANNOY_NUMBER_1",
"pair": "cpp-python",
"Code1": "int dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "cpp-python",
"Code1": "int power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"Code2": "def power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CHECK_ISBN",
"pair": "cpp-python",
"Code1": "bool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"Code2": "def isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "cpp-python",
"Code1": "void NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n ",
"Code2": "def NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n \n"
},
{
"id": "cpp-python-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "cpp-python",
"Code1": "int swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )",
"Code2": "def swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )\n"
},
{
"id": "cpp-python-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "cpp-python",
"Code1": "void printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"Code2": "def printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]\n"
},
{
"id": "cpp-python-HYPERCUBE_GRAPH",
"pair": "cpp-python",
"Code1": "int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"Code2": "def power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "cpp-python",
"Code1": "void findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "cpp-python",
"Code1": "int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"Code2": "def lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "cpp-python",
"Code1": "void reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n",
"Code2": "def reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "cpp-python",
"Code1": "int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n",
"Code2": "def findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "cpp-python",
"Code1": "int longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"Code2": "def longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n\n"
},
{
"id": "cpp-python-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "cpp-python",
"Code1": "int MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"Code2": "def MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "cpp-python",
"Code1": "void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"Code2": "def printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "cpp-python",
"Code1": "void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n",
"Code2": "def minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "cpp-python",
"Code1": "bool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n",
"Code2": "def isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "cpp-python",
"Code1": "int findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "cpp-python",
"Code1": "int countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-KNAPSACK_PROBLEM_1",
"pair": "cpp-python",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "cpp-python",
"Code1": "void multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"Code2": "def multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "cpp-python",
"Code1": "int maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"Code2": "def maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "cpp-python",
"Code1": "int findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "def findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_SINK_NODES_GRAPH",
"pair": "cpp-python",
"Code1": "int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n",
"Code2": "def countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "cpp-python",
"Code1": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"Code2": "def countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "cpp-python",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "cpp-python",
"Code1": "int countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n ",
"Code2": "def countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n \n"
},
{
"id": "cpp-python-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "cpp-python",
"Code1": "bool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n",
"Code2": "def findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-LINEAR_SEARCH",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "cpp-python",
"Code1": "bool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"Code2": "def check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "cpp-python",
"Code1": "int binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"Code2": "def binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "cpp-python",
"Code1": "long countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"Code2": "def countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-MIRROR_CHARACTERS_STRING",
"pair": "cpp-python",
"Code1": "string compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n",
"Code2": "def compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "cpp-python",
"Code1": "int maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"Code2": "def maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "cpp-python",
"Code1": "long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"Code2": "def exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n\n"
},
{
"id": "cpp-python-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "cpp-python",
"Code1": "int sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"Code2": "def sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"Code2": "def lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "cpp-python",
"Code1": "int maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"Code2": "def maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "cpp-python",
"Code1": "int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"Code2": "def fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "cpp-python",
"Code1": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "cpp-python",
"Code1": "bool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n",
"Code2": "def flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "cpp-python",
"Code1": "bool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"Code2": "def checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "cpp-python",
"Code1": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n",
"Code2": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "cpp-python",
"Code1": "int maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n ",
"Code2": "def maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n \n"
},
{
"id": "cpp-python-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "cpp-python",
"Code1": "int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"Code2": "def longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "cpp-python",
"Code1": "int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"Code2": "def maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "cpp-python",
"Code1": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"Code2": "def maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "cpp-python",
"Code1": "int minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n",
"Code2": "def minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "cpp-python",
"Code1": "void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"Code2": "def kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n\n"
},
{
"id": "cpp-python-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "cpp-python",
"Code1": "void spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "def spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "cpp-python",
"Code1": "int findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n",
"Code2": "def findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n\n"
},
{
"id": "cpp-python-NTH_PENTAGONAL_NUMBER",
"pair": "cpp-python",
"Code1": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"Code2": "def pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "cpp-python",
"Code1": "long long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"Code2": "def countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FREQUENT_ELEMENT_ARRAY_1",
"pair": "cpp-python",
"Code1": "int mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n",
"Code2": "def mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "cpp-python",
"Code1": "int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"Code2": "def kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "cpp-python",
"Code1": "int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"Code2": "def binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n\n"
},
{
"id": "cpp-python-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "cpp-python",
"Code1": "string firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"Code2": "def firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "cpp-python",
"Code1": "void assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"Code2": "def assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "cpp-python",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "cpp-python",
"Code1": "int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"Code2": "def countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "cpp-python",
"Code1": "void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n",
"Code2": "def relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "cpp-python",
"Code1": "int findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n ",
"Code2": "def findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n \n"
},
{
"id": "cpp-python-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "cpp-python",
"Code1": "int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"Code2": "def findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "cpp-python",
"Code1": "bool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"Code2": "def isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "cpp-python",
"Code1": "int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "cpp-python",
"Code1": "bool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n",
"Code2": "def isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "cpp-python",
"Code1": "int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"Code2": "def maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n\n"
},
{
"id": "cpp-python-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "cpp-python",
"Code1": "string decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"Code2": "def decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "cpp-python",
"Code1": "int minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"Code2": "def minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "cpp-python",
"Code1": "bool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"Code2": "def isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "cpp-python",
"Code1": "int countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n",
"Code2": "def countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "cpp-python",
"Code1": "int findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n",
"Code2": "def findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "cpp-python",
"Code1": "e9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n",
"Code2": "def minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ne9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "cpp-python",
"Code1": "void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n",
"Code2": "def constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-NUMBER_RECTANGLES_NM_GRID",
"pair": "cpp-python",
"Code1": "int rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"Code2": "def rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n\n"
},
{
"id": "cpp-python-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "cpp-python",
"Code1": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"Code2": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n \n"
},
{
"id": "cpp-python-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "cpp-python",
"Code1": "void subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "cpp-python",
"Code1": "bool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n",
"Code2": "def isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "cpp-python",
"Code1": "int divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"Code2": "def divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n\n"
},
{
"id": "cpp-python-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "cpp-python",
"Code1": "int superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"Code2": "def superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "cpp-python",
"Code1": "void swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "cpp-python",
"Code1": "int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"Code2": "def kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "cpp-python",
"Code1": "bool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "cpp-python",
"Code1": "bool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"Code2": "def isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "cpp-python",
"Code1": "int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n",
"Code2": "def longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n\n"
},
{
"id": "cpp-python-REVERSE_A_STRING_USING_RECURSION",
"pair": "cpp-python",
"Code1": "void reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n",
"Code2": "def reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "cpp-python",
"Code1": "long long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"Code2": "def arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "cpp-python",
"Code1": "bool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"Code2": "def isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "cpp-python",
"Code1": "int maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"Code2": "def maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "cpp-python",
"Code1": "string lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"Code2": "def lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "cpp-python",
"Code1": "int maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"Code2": "def maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "cpp-python",
"Code1": "int xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"Code2": "def xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n\n"
},
{
"id": "cpp-python-N_TH_ROOT_NUMBER",
"pair": "cpp-python",
"Code1": "double nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"Code2": "def nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n\n"
},
{
"id": "cpp-python-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "cpp-python",
"Code1": "string findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n",
"Code2": "def findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "cpp-python",
"Code1": "int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n",
"Code2": "def subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "cpp-python",
"Code1": "void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n",
"Code2": "def minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n\n"
},
{
"id": "cpp-python-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "cpp-python",
"Code1": "int findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n",
"Code2": "def findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "cpp-python",
"Code1": "void printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n",
"Code2": "def printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "cpp-python",
"Code1": "int evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "def evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "cpp-python",
"Code1": "int getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n",
"Code2": "def getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "cpp-python",
"Code1": "void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "cpp-python",
"Code1": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n",
"Code2": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "cpp-python",
"Code1": "bool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"Code2": "def areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "cpp-python",
"Code1": "void printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n",
"Code2": "def printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "cpp-python",
"Code1": "int countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"Code2": "def countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "cpp-python",
"Code1": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n",
"Code2": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "cpp-python",
"Code1": "int calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n",
"Code2": "def calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-python",
"Code1": "void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "def bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "cpp-python",
"Code1": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"Code2": "def countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n\n"
},
{
"id": "cpp-python-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "cpp-python",
"Code1": "bool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "cpp-python",
"Code1": "unsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"Code2": "def getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "cpp-python",
"Code1": "int minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "def minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "cpp-python",
"Code1": "bool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "def containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "cpp-python",
"Code1": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"Code2": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "cpp-python",
"Code1": "bool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n",
"Code2": "def isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "cpp-python",
"Code1": "int getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"Code2": "def getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "cpp-python",
"Code1": "int maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n",
"Code2": "def maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "cpp-python",
"Code1": "int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"Code2": "def maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "cpp-python",
"Code1": "void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n",
"Code2": "def checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-python-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "cpp-python",
"Code1": "int nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "def nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "cpp-python",
"Code1": "int countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"Code2": "def countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "cpp-python",
"Code1": "int selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"Code2": "def selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "cpp-python",
"Code1": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n",
"Code2": "def productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n\n"
},
{
"id": "cpp-python-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "cpp-python",
"Code1": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "cpp-python",
"Code1": "int cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n",
"Code2": "def cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n\n"
},
{
"id": "cpp-python-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "cpp-python",
"Code1": "int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"Code2": "def minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "cpp-python",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"Code2": "def getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "cpp-python",
"Code1": "double surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"Code2": "def surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n\n"
},
{
"id": "cpp-python-GNOME_SORT_A_STUPID_ONE",
"pair": "cpp-python",
"Code1": "void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n",
"Code2": "def gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "cpp-python",
"Code1": "int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"Code2": "def find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n\n"
},
{
"id": "cpp-python-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "cpp-python",
"Code1": "int countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"Code2": "def countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n\n"
},
{
"id": "cpp-python-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "cpp-python",
"Code1": "void generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n",
"Code2": "def generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n\n"
},
{
"id": "cpp-python-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "cpp-python",
"Code1": "void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n",
"Code2": "def midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "cpp-python",
"Code1": "void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"Code2": "def printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-FRIENDS_PAIRING_PROBLEM",
"pair": "cpp-python",
"Code1": "int countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "cpp-python",
"Code1": "int remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"Code2": "def remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n\n"
},
{
"id": "cpp-python-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "cpp-python",
"Code1": "int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n",
"Code2": "def findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "cpp-python",
"Code1": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "cpp-python",
"Code1": "int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"Code2": "def maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "cpp-python",
"Code1": "void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"Code2": "def printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "cpp-python",
"Code1": "bool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n",
"Code2": "def checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "cpp-python",
"Code1": "double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n",
"Code2": "def vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "cpp-python",
"Code1": "int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-BINARY_SEARCH",
"pair": "cpp-python",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "cpp-python",
"Code1": "int numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "cpp-python",
"Code1": "long long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"Code2": "def answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "cpp-python",
"Code1": "int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"Code2": "def maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "cpp-python",
"Code1": "int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"Code2": "def maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n\n"
},
{
"id": "cpp-python-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "cpp-python",
"Code1": "void moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n",
"Code2": "def moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n\n"
},
{
"id": "cpp-python-RECAMANS_SEQUENCE",
"pair": "cpp-python",
"Code1": "int recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n",
"Code2": "def recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "cpp-python",
"Code1": "int findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "cpp-python",
"Code1": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"Code2": "def KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-python-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "cpp-python",
"Code1": "int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n",
"Code2": "def modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n\n"
},
{
"id": "cpp-python-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"Code2": "def lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "cpp-python",
"Code1": "int countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"Code2": "def countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n\n"
},
{
"id": "cpp-python-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "cpp-python",
"Code1": "int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"Code2": "def findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "cpp-python",
"Code1": "int substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"Code2": "def substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "cpp-python",
"Code1": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"Code2": "def maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "cpp-python",
"Code1": "string longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n",
"Code2": "def longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "cpp-python",
"Code1": "bool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "cpp-python",
"Code1": "int calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"Code2": "def calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n\n"
},
{
"id": "cpp-python-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "cpp-python",
"Code1": "void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n",
"Code2": "def rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n\n"
},
{
"id": "cpp-python-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "cpp-python",
"Code1": "void antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n",
"Code2": "def antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "cpp-python",
"Code1": "void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "cpp-python",
"Code1": "int findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "def findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "cpp-python",
"Code1": "int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"Code2": "def Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n\n"
},
{
"id": "cpp-python-BUBBLE_SORT",
"pair": "cpp-python",
"Code1": "void bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n",
"Code2": "def bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "cpp-python",
"Code1": "int superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "cpp-python",
"Code1": "int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"Code2": "def countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "cpp-python",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"Code2": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "cpp-python",
"Code1": "int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"Code2": "def minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n",
"Code2": "def kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "cpp-python",
"Code1": "INT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"Code2": "def minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nINT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "cpp-python",
"Code1": "string reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n",
"Code2": "def reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-python-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "cpp-python",
"Code1": "int minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "def minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "cpp-python",
"Code1": "int MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"Code2": "def MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-python-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "cpp-python",
"Code1": "void bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n",
"Code2": "def bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "cpp-python",
"Code1": "int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"Code2": "def countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"Code2": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "cpp-python",
"Code1": "void printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n",
"Code2": "def printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "cpp-python",
"Code1": "int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "cpp-python",
"Code1": "void pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"Code2": "def pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "cpp-python",
"Code1": "int minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"Code2": "def minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "cpp-python",
"Code1": "string censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n",
"Code2": "def censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "cpp-python",
"Code1": "public : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-python-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "cpp-python",
"Code1": "float getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n",
"Code2": "def getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "cpp-python",
"Code1": "int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"Code2": "def distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "cpp-python",
"Code1": "void findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n",
"Code2": "def findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n\n"
},
{
"id": "cpp-python-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "cpp-python",
"Code1": "int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"Code2": "def lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n\n"
},
{
"id": "cpp-python-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "cpp-python",
"Code1": "int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n",
"Code2": "def evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "cpp-python",
"Code1": "bool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n",
"Code2": "def isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-HOSOYAS_TRIANGLE",
"pair": "cpp-python",
"Code1": "void printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "cpp-python",
"Code1": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n",
"Code2": "def findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVE_INSERTION_SORT",
"pair": "cpp-python",
"Code1": "void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"Code2": "def insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n\n"
},
{
"id": "cpp-python-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "def findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "cpp-python-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "cpp-python",
"Code1": "int playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n",
"Code2": "def playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "cpp-python",
"Code1": "int subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n",
"Code2": "def subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "cpp-python",
"Code1": "bool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"Code2": "def isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "cpp-python",
"Code1": "double largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n ",
"Code2": "def largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n \n"
},
{
"id": "cpp-python-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "cpp-python",
"Code1": "int getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"Code2": "def getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n ",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n \n"
},
{
"id": "cpp-python-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "cpp-python",
"Code1": "int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"Code2": "def nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "cpp-python",
"Code1": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "def findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "cpp-python",
"Code1": "int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"Code2": "def eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "cpp-python",
"Code1": "int count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n",
"Code2": "def count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "cpp-python",
"Code1": "int findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"Code2": "def findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n\n"
},
{
"id": "cpp-python-SHUFFLE_A_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "void randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n",
"Code2": "def randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "cpp-python",
"Code1": "int findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "cpp-python",
"Code1": "void translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n",
"Code2": "def translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "cpp-python",
"Code1": "int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"Code2": "def maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "cpp-python",
"Code1": "unsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n",
"Code2": "def catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SUM_SERIES_12_32_52_2N_12",
"pair": "cpp-python",
"Code1": "int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"Code2": "def sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "cpp-python",
"Code1": "int minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n",
"Code2": "def minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "cpp-python",
"Code1": "void printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n",
"Code2": "def printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n\n"
},
{
"id": "cpp-python-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "cpp-python",
"Code1": "int largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n",
"Code2": "def largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-PASCAL_TRIANGLE",
"pair": "cpp-python",
"Code1": "void printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "def printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "cpp-python",
"Code1": "int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"Code2": "def answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-CASSINIS_IDENTITY",
"pair": "cpp-python",
"Code1": "int cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n",
"Code2": "def cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n\n"
},
{
"id": "cpp-python-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "cpp-python",
"Code1": "int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"Code2": "def compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "cpp-python",
"Code1": "int waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"Code2": "def waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "cpp-python",
"Code1": "void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n",
"Code2": "def findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "cpp-python",
"Code1": "int maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"Code2": "def maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "cpp-python",
"Code1": "long long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "def MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "cpp-python",
"Code1": "int findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"Code2": "def findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "cpp-python",
"Code1": "int findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "def findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "cpp-python",
"Code1": "int maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n ",
"Code2": "def maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n \n"
},
{
"id": "cpp-python-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "cpp-python",
"Code1": "void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "def findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-NTH_EVEN_LENGTH_PALINDROME",
"pair": "cpp-python",
"Code1": "string evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n",
"Code2": "def evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "cpp-python",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "cpp-python",
"Code1": "int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "def possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "cpp-python",
"Code1": "int numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "def numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "cpp-python",
"Code1": "double circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"Code2": "def circumference ( r ) :\n return ( 2 * PI * r )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "cpp-python",
"Code1": "int substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n",
"Code2": "def substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "cpp-python",
"Code1": "int maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"Code2": "def maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "cpp-python",
"Code1": "int SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n",
"Code2": "def SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "cpp-python",
"Code1": "int fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n",
"Code2": "def fun ( n ) :\n return n & ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "cpp-python",
"Code1": "pair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n",
"Code2": "def mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "cpp-python",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "cpp-python",
"Code1": "int printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n",
"Code2": "def printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "cpp-python",
"Code1": "string arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n ",
"Code2": "def arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n \n"
},
{
"id": "cpp-python-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "cpp-python",
"Code1": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"Code2": "def countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "cpp-python",
"Code1": "int minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"Code2": "def minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "cpp-python",
"Code1": "string printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"Code2": "def printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n\n"
},
{
"id": "cpp-python-ROTATE_MATRIX_ELEMENTS",
"pair": "cpp-python",
"Code1": "void rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "cpp-python",
"Code1": "int maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"Code2": "def maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "cpp-python",
"Code1": "double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n\n"
},
{
"id": "cpp-python-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "cpp-python",
"Code1": "void sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n ",
"Code2": "def sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n \n"
},
{
"id": "cpp-python-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "cpp-python",
"Code1": "void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"Code2": "def rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"Code2": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "cpp-python",
"Code1": "float find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n",
"Code2": "def find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "cpp-python",
"Code1": "int waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"Code2": "def waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "cpp-python",
"Code1": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"Code2": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n\n"
},
{
"id": "cpp-python-STERN_BROCOT_SEQUENCE",
"pair": "cpp-python",
"Code1": "void SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n",
"Code2": "def SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-PRUFER_CODE_TREE_CREATION",
"pair": "cpp-python",
"Code1": "void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n",
"Code2": "def printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "cpp-python",
"Code1": "int countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"Code2": "def countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "cpp-python",
"Code1": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"Code2": "def countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "cpp-python",
"Code1": "int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"Code2": "def maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_BRACKET_NUMBER",
"pair": "cpp-python",
"Code1": "void printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"Code2": "def printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "cpp-python",
"Code1": "int countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"Code2": "def countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "cpp-python",
"Code1": "int largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"Code2": "def largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "cpp-python",
"Code1": "int findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n",
"Code2": "def findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "int maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"Code2": "def maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "cpp-python",
"Code1": "float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"Code2": "def volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n\n"
},
{
"id": "cpp-python-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "cpp-python",
"Code1": "int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"Code2": "def lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_ENDLESS_POINTS",
"pair": "cpp-python",
"Code1": "int countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-python",
"Code1": "void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "def NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "cpp-python",
"Code1": "int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n",
"Code2": "def lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "cpp-python",
"Code1": "bool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n",
"Code2": "def checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-python-DIAGONALLY_DOMINANT_MATRIX",
"pair": "cpp-python",
"Code1": "bool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "cpp-python",
"Code1": "void transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"Code2": "def transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "cpp-python",
"Code1": "int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"Code2": "def returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "cpp-python",
"Code1": "int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"Code2": "def sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n\n"
},
{
"id": "cpp-python-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "cpp-python",
"Code1": "INT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"Code2": "def shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nINT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "cpp-python",
"Code1": "long long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"Code2": "def calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "cpp-python",
"Code1": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"Code2": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "cpp-python",
"Code1": "void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"Code2": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n\n"
},
{
"id": "cpp-python-K_TH_DIGIT_RAISED_POWER_B",
"pair": "cpp-python",
"Code1": "int kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"Code2": "def kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "cpp-python",
"Code1": "bool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n",
"Code2": "def isEven ( n ) :\n return ( not ( n & 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "cpp-python",
"Code1": "void printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n",
"Code2": "def printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "cpp-python",
"Code1": "bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"Code2": "def checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "cpp-python",
"Code1": "bool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "cpp-python",
"Code1": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "cpp-python",
"Code1": "int maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"Code2": "def maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "cpp-python",
"Code1": "int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"Code2": "def findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "cpp-python",
"Code1": "double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"Code2": "def seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "cpp-python",
"Code1": "int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"Code2": "def countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "cpp-python",
"Code1": "int getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"Code2": "def getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "cpp-python",
"Code1": "bool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "def isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "cpp-python",
"Code1": "void printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n",
"Code2": "def printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "cpp-python",
"Code1": "bool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"Code2": "def isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "cpp-python",
"Code1": "int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"Code2": "def getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos\n"
},
{
"id": "cpp-python-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "cpp-python",
"Code1": "int minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"Code2": "def minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "cpp-python",
"Code1": "void GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"Code2": "def rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n\n"
},
{
"id": "cpp-python-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "cpp-python",
"Code1": "int countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"Code2": "def countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "cpp-python",
"Code1": "int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n",
"Code2": "def largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "cpp-python",
"Code1": "bool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n",
"Code2": "def isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "cpp-python",
"Code1": "int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"Code2": "def CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n\n"
},
{
"id": "cpp-python-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "cpp-python",
"Code1": "int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"Code2": "def minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-NTH_NON_FIBONACCI_NUMBER",
"pair": "cpp-python",
"Code1": "int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"Code2": "def nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "cpp-python",
"Code1": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"Code2": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n\n"
},
{
"id": "cpp-python-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "cpp-python",
"Code1": "void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n",
"Code2": "def leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "cpp-python",
"Code1": "string repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"Code2": "def repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "cpp-python",
"Code1": "string findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"Code2": "def findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n \n"
},
{
"id": "cpp-python-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "cpp-python",
"Code1": "public : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"Code2": "def findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "cpp-python",
"Code1": "void printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "def printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "cpp-python",
"Code1": "int minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"Code2": "def minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n\n"
},
{
"id": "cpp-python-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "cpp-python",
"Code1": "void luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n",
"Code2": "def luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "cpp-python",
"Code1": "void bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n",
"Code2": "def bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "cpp-python",
"Code1": "int CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "cpp-python",
"Code1": "void modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n",
"Code2": "def modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n\n"
},
{
"id": "cpp-python-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "cpp-python",
"Code1": "int minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"Code2": "def minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "cpp-python",
"Code1": "int maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"Code2": "def maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "cpp-python",
"Code1": "long long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"Code2": "def findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "cpp-python",
"Code1": "void deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n",
"Code2": "def deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "cpp-python",
"Code1": "char first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n",
"Code2": "def first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "cpp-python",
"Code1": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n",
"Code2": "def minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n\n"
},
{
"id": "cpp-python-ARC_LENGTH_ANGLE",
"pair": "cpp-python",
"Code1": "double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"Code2": "def arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n\n"
},
{
"id": "cpp-python-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "cpp-python",
"Code1": "void findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n",
"Code2": "def findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "cpp-python",
"Code1": "bool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n ",
"Code2": "def isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-python-PRIME_NUMBERS",
"pair": "cpp-python",
"Code1": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"Code2": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "cpp-python",
"Code1": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n",
"Code2": "def findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "cpp-python-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "cpp-python",
"Code1": "void maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n",
"Code2": "def maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n\n"
},
{
"id": "cpp-python-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "cpp-python",
"Code1": "int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"Code2": "def horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "cpp-python",
"Code1": "void rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"Code2": "def rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n\n"
},
{
"id": "cpp-python-N_BONACCI_NUMBERS_1",
"pair": "cpp-python",
"Code1": "void bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n ",
"Code2": "def bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n \n"
},
{
"id": "cpp-python-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "cpp-python",
"Code1": "int numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"Code2": "def numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "cpp-python",
"Code1": "int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"Code2": "def findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "cpp-python",
"Code1": "int maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"Code2": "def maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "cpp-python",
"Code1": "int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"Code2": "def isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "cpp-python",
"Code1": "int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"Code2": "def fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "cpp-python",
"Code1": "int minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"Code2": "def minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "cpp-python",
"Code1": "void amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n",
"Code2": "def amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n\n"
},
{
"id": "cpp-python-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "cpp-python",
"Code1": "int countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"Code2": "def countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n\n"
},
{
"id": "cpp-python-BREAK_NUMBER_THREE_PARTS",
"pair": "cpp-python",
"Code1": "ll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"Code2": "def count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "cpp-python",
"Code1": "float sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n",
"Code2": "def sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-python-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "cpp-python",
"Code1": "void findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n",
"Code2": "def findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n\n"
},
{
"id": "cpp-python-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "cpp-python",
"Code1": "int countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"Code2": "def countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-HEXAGONAL_NUMBER",
"pair": "cpp-python",
"Code1": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"Code2": "def hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "cpp-python",
"Code1": "int findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"Code2": "def findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "cpp-python",
"Code1": "void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n",
"Code2": "def squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "cpp-python",
"Code1": "int count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n ",
"Code2": "def count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n \n"
},
{
"id": "cpp-python-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "cpp-python",
"Code1": "int find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n",
"Code2": "def find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n\n"
},
{
"id": "cpp-python-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "cpp-python",
"Code1": "int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "cpp-python",
"Code1": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n",
"Code2": "def sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-LEONARDO_NUMBER_1",
"pair": "cpp-python",
"Code1": "int leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"Code2": "def leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "cpp-python",
"Code1": "int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "def countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "cpp-python",
"Code1": "bool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"Code2": "def check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "cpp-python",
"Code1": "int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"Code2": "def evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "cpp-python",
"Code1": "int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-python-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "cpp-python",
"Code1": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "cpp-python",
"Code1": "char getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n ",
"Code2": "def getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n \n"
},
{
"id": "cpp-python-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "cpp-python",
"Code1": "int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"Code2": "def countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "cpp-python",
"Code1": "void printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"Code2": "def printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "cpp-python",
"Code1": "void findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n",
"Code2": "def findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "cpp-python",
"Code1": "int countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"Code2": "def countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "cpp-python",
"Code1": "int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"Code2": "def intersection ( n ) :\n return n * ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "cpp-python",
"Code1": "int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "cpp-python",
"Code1": "int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "cpp-python",
"Code1": "int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"Code2": "def smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n\n"
},
{
"id": "cpp-python-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "cpp-python",
"Code1": "double maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"Code2": "def maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "cpp-python",
"Code1": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "cpp-python",
"Code1": "int longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n",
"Code2": "def longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "cpp-python",
"Code1": "bool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"Code2": "def isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "cpp-python",
"Code1": "int computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"Code2": "def computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "cpp-python",
"Code1": "int minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "def minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_POWER_OF_2_1",
"pair": "cpp-python",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "cpp-python-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "cpp-python",
"Code1": "int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n",
"Code2": "def getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n\n"
},
{
"id": "cpp-python-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "cpp-python",
"Code1": "int numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "def numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "cpp-python",
"Code1": "bool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"Code2": "def check ( n ) :\n return 1162261467 % n == 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n\n"
},
{
"id": "cpp-python-NEWMAN_CONWAY_SEQUENCE",
"pair": "cpp-python",
"Code1": "int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"Code2": "def sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "cpp-python",
"Code1": "void generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n",
"Code2": "def generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "cpp-python",
"Code1": "int countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n",
"Code2": "def countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n\n"
},
{
"id": "cpp-python-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "cpp-python",
"Code1": "int findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n",
"Code2": "def findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-LEONARDO_NUMBER",
"pair": "cpp-python",
"Code1": "int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n",
"Code2": "def leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "cpp-python",
"Code1": "int findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"Code2": "def findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "cpp-python",
"Code1": "bool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"Code2": "def HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "cpp-python",
"Code1": "int sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "def sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "cpp-python",
"Code1": "void LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "cpp-python",
"Code1": "int countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n ",
"Code2": "def countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n \n"
},
{
"id": "cpp-python-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "cpp-python",
"Code1": "int countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"Code2": "def countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "cpp-python",
"Code1": "void printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n",
"Code2": "def printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-python-FLOOR_IN_A_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"Code2": "def floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "cpp-python",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "cpp-python-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "cpp-python",
"Code1": "void printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n",
"Code2": "def printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "cpp-python",
"Code1": "void longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "def longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "cpp-python",
"Code1": "int minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"Code2": "def minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "cpp-python",
"Code1": "int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"Code2": "def breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"Code2": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "cpp-python",
"Code1": "void alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n",
"Code2": "def alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "cpp-python",
"Code1": "void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n",
"Code2": "def subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "cpp-python",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "cpp-python-DICE_THROW_PROBLEM",
"pair": "cpp-python",
"Code1": "int findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n",
"Code2": "def findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "cpp-python",
"Code1": "bool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n ",
"Code2": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-python-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "cpp-python",
"Code1": "int findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"Code2": "def findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-TILING_WITH_DOMINOES",
"pair": "cpp-python",
"Code1": "int countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"Code2": "def countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "cpp-python",
"Code1": "int minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"Code2": "def minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "cpp-python",
"Code1": "bool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"Code2": "def isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "cpp-python",
"Code1": "int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"Code2": "def MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n\n"
},
{
"id": "cpp-python-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "cpp-python",
"Code1": "public : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n",
"Code2": "def multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "cpp-python",
"Code1": "int countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "def countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "cpp-python",
"Code1": "void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"Code2": "def worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "cpp-python",
"Code1": "int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"Code2": "def maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "cpp-python",
"Code1": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "def findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "cpp-python",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"Code2": "def subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-COMMON_CHARACTERS_N_STRINGS",
"pair": "cpp-python",
"Code1": "void commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n ",
"Code2": "def commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n \n"
},
{
"id": "cpp-python-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "cpp-python",
"Code1": "bool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n ",
"Code2": "def canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-python-MAGIC_SQUARE",
"pair": "cpp-python",
"Code1": "void generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "cpp-python",
"Code1": "int count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"Code2": "def count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "cpp-python",
"Code1": "int numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"Code2": "def numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "cpp-python",
"Code1": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"Code2": "def countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "cpp-python",
"Code1": "int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"Code2": "def ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "cpp-python",
"Code1": "string decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"Code2": "def decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n\n"
},
{
"id": "cpp-python-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "cpp-python",
"Code1": "public : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n",
"Code2": "def printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n\n"
},
{
"id": "cpp-python-PREFIX_SUM_2D_ARRAY",
"pair": "cpp-python",
"Code1": "void prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "def prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-EULERIAN_NUMBER",
"pair": "cpp-python",
"Code1": "int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"Code2": "def eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "long long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n",
"Code2": "def findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "cpp-python",
"Code1": "int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n",
"Code2": "def isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n\n"
},
{
"id": "cpp-python-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "cpp-python",
"Code1": "int longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"Code2": "def longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_AREA_SQUARE",
"pair": "cpp-python",
"Code1": "int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"Code2": "def areaSquare ( side ) :\n area = side * side\n return area\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n\n"
},
{
"id": "cpp-python-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "cpp-python",
"Code1": "void findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n",
"Code2": "def findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n\n"
},
{
"id": "cpp-python-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "cpp-python",
"Code1": "int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n",
"Code2": "def lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "cpp-python",
"Code1": "void findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "cpp-python",
"Code1": "int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"Code2": "def spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"Code2": "def countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "cpp-python",
"Code1": "int sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n",
"Code2": "def sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "cpp-python",
"Code1": "int calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n ",
"Code2": "def calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n \n"
},
{
"id": "cpp-python-DOUBLE_FACTORIAL_1",
"pair": "cpp-python",
"Code1": "unsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n",
"Code2": "def doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n\n"
},
{
"id": "cpp-python-LONGEST_COMMON_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "cpp-python",
"Code1": "int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "def maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "cpp-python-TEMPLE_OFFERINGS",
"pair": "cpp-python",
"Code1": "int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"Code2": "def offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "cpp-python",
"Code1": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n",
"Code2": "def SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "cpp-python",
"Code1": "string constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n",
"Code2": "def constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "cpp-python",
"Code1": "unsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"Code2": "def russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-CAESAR_CIPHER",
"pair": "cpp-python",
"Code1": "string encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n",
"Code2": "def encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "cpp-python",
"Code1": "long double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n",
"Code2": "def distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "cpp-python",
"Code1": "long int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"Code2": "def evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "cpp-python",
"Code1": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"Code2": "def gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a\n"
},
{
"id": "cpp-python-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "cpp-python",
"Code1": "bool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n",
"Code2": "def isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-python-SUM_PAIRWISE_PRODUCTS",
"pair": "cpp-python",
"Code1": "long long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "cpp-python",
"Code1": "int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"Code2": "def binomialCoeffSum ( n ) :\n return ( 1 << n )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n\n"
},
{
"id": "cpp-python-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "cpp-python",
"Code1": "int calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"Code2": "def calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "cpp-python",
"Code1": "void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n",
"Code2": "def checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINTING_ITEMS_01_KNAPSACK",
"pair": "cpp-python",
"Code1": "void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"Code2": "def printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "cpp-python",
"Code1": "int getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"Code2": "def getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "cpp-python",
"Code1": "int findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "cpp-python",
"Code1": "string replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n",
"Code2": "def replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-python-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "cpp-python",
"Code1": "int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"Code2": "def discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "cpp-python",
"Code1": "long long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"Code2": "def maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n\n"
},
{
"id": "cpp-python-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "cpp-python",
"Code1": "bool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n",
"Code2": "def isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "cpp-python",
"Code1": "int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n",
"Code2": "def numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "cpp-python",
"Code1": "int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0",
"Code2": "def solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0\n"
},
{
"id": "cpp-python-REMAINDER_7_LARGE_NUMBERS",
"pair": "cpp-python",
"Code1": "int remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"Code2": "def remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n \n"
},
{
"id": "cpp-python-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "cpp-python",
"Code1": "bool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"Code2": "def isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "cpp-python",
"Code1": "int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"Code2": "def getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "cpp-python",
"Code1": "int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "def minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "cpp-python-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "cpp-python",
"Code1": "public : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"Code2": "def getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "cpp-python",
"Code1": "int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n",
"Code2": "def findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n\n"
},
{
"id": "cpp-python-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "cpp-python",
"Code1": "void mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n",
"Code2": "def mergeTwoHalf ( A , n ) :\n A.sort ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n\n"
},
{
"id": "cpp-python-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "cpp-python",
"Code1": "void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"Code2": "def fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "cpp-python",
"Code1": "int minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"Code2": "def minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "cpp-python",
"Code1": "void possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n",
"Code2": "def possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_SLOPE_LINE",
"pair": "cpp-python",
"Code1": "float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"Code2": "def slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "cpp-python",
"Code1": "int countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n",
"Code2": "def CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "cpp-python",
"Code1": "int countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"Code2": "def countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "cpp-python",
"Code1": "void findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"Code2": "def findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "cpp-python",
"Code1": "string lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"Code2": "def lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "cpp-python",
"Code1": "void maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n",
"Code2": "def maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "cpp-python",
"Code1": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"Code2": "def countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "cpp-python",
"Code1": "int findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n",
"Code2": "def findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n\n"
},
{
"id": "cpp-python-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "cpp-python",
"Code1": "long long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n",
"Code2": "def yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"Code2": "def maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "cpp-python",
"Code1": "int maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"Code2": "def maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "ll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n",
"Code2": "def lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n\n"
},
{
"id": "cpp-python-PETERSON_GRAPH",
"pair": "cpp-python",
"Code1": "bool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n",
"Code2": "def findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "cpp-python",
"Code1": "bool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n",
"Code2": "def checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "cpp-python",
"Code1": "void generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"Code2": "def generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVE_FUNCTIONS",
"pair": "cpp-python",
"Code1": "void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"Code2": "def tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n\n"
},
{
"id": "cpp-python-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "cpp-python",
"Code1": "int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "def findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "cpp-python",
"Code1": "string minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n",
"Code2": "def minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "cpp-python",
"Code1": "int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"Code2": "def findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "cpp-python",
"Code1": "int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"Code2": "def octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MISSING_NUMBER",
"pair": "cpp-python",
"Code1": "int getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"Code2": "def getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "cpp-python",
"Code1": "void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n",
"Code2": "def printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n\n"
},
{
"id": "cpp-python-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "cpp-python",
"Code1": "bool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"Code2": "def isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "cpp-python",
"Code1": "void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n",
"Code2": "def fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n\n"
},
{
"id": "cpp-python-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "cpp-python",
"Code1": "int findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n",
"Code2": "def findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n\n"
},
{
"id": "cpp-python-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "cpp-python",
"Code1": "void sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n",
"Code2": "def sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "cpp-python",
"Code1": "int countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "cpp-python",
"Code1": "int count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"Code2": "def count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "cpp-python",
"Code1": "int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"Code2": "def maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"Code2": "def findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "cpp-python",
"Code1": "bool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n",
"Code2": "def isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "cpp-python",
"Code1": "int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"Code2": "def getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "cpp-python",
"Code1": "int countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"Code2": "def countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-JUMP_SEARCH",
"pair": "cpp-python",
"Code1": "int jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"Code2": "def jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_X_Y_SATISFYING_AX_N",
"pair": "cpp-python",
"Code1": "void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n",
"Code2": "def solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n\n"
},
{
"id": "cpp-python-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "cpp-python",
"Code1": "string longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"Code2": "def longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "cpp-python",
"Code1": "void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n",
"Code2": "def sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "cpp-python",
"Code1": "bool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"Code2": "def canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "cpp-python",
"Code1": "int find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n",
"Code2": "def find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "cpp-python",
"Code1": "void printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n",
"Code2": "def printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n\n"
},
{
"id": "cpp-python-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "cpp-python",
"Code1": "void sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "def sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "cpp-python",
"Code1": "int find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n",
"Code2": "def find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "cpp-python",
"Code1": "char maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "cpp-python",
"Code1": "int solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n",
"Code2": "def solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "cpp-python",
"Code1": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"Code2": "def Circumference ( a ) :\n return ( 4 * a )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint Circumference ( int a ) {\n return 4 * a ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "cpp-python",
"Code1": "int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n\n"
},
{
"id": "cpp-python-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "cpp-python",
"Code1": "void pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n",
"Code2": "def pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "cpp-python",
"Code1": "ll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n ",
"Code2": "def pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n \n"
},
{
"id": "cpp-python-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "cpp-python",
"Code1": "void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"Code2": "def splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "cpp-python",
"Code1": "int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"Code2": "def smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n\n"
},
{
"id": "cpp-python-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "cpp-python",
"Code1": "int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"Code2": "def winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "cpp-python",
"Code1": "bool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"Code2": "def divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "cpp-python",
"Code1": "int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"Code2": "def countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "cpp-python",
"Code1": "void CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n",
"Code2": "def CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "cpp-python",
"Code1": "uint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"Code2": "def snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nuint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit\n"
},
{
"id": "cpp-python-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "cpp-python",
"Code1": "bool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"Code2": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "cpp-python",
"Code1": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n\n"
},
{
"id": "cpp-python-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "cpp-python",
"Code1": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n ",
"Code2": "def countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n \n"
},
{
"id": "cpp-python-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "cpp-python",
"Code1": "int nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"Code2": "def nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n\n"
},
{
"id": "cpp-python-COCKTAIL_SORT",
"pair": "cpp-python",
"Code1": "void CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n",
"Code2": "def cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n\n"
},
{
"id": "cpp-python-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "cpp-python",
"Code1": "void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"Code2": "def solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n\n"
},
{
"id": "cpp-python-BINARY_SEARCH_1",
"pair": "cpp-python",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_XOR_VALUE_PAIR",
"pair": "cpp-python",
"Code1": "int minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"Code2": "def minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "cpp-python",
"Code1": "int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "def sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "cpp-python",
"Code1": "char first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n",
"Code2": "def first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "cpp-python",
"Code1": "int maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"Code2": "def maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "cpp-python",
"Code1": "double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"Code2": "def procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "cpp-python",
"Code1": "void rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "def rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "cpp-python",
"Code1": "void greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n",
"Code2": "def greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "cpp-python",
"Code1": "int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"Code2": "def isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_COMMON_SUBSTRING",
"pair": "cpp-python",
"Code1": "int LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"Code2": "def LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "cpp-python",
"Code1": "int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"Code2": "def maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIBONACCI_MODULO_P",
"pair": "cpp-python",
"Code1": "int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"Code2": "def findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n\n"
},
{
"id": "cpp-python-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "cpp-python",
"Code1": "void reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"Code2": "def reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "cpp-python",
"Code1": "int longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n ",
"Code2": "def longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n \n"
},
{
"id": "cpp-python-SUM_FIBONACCI_NUMBERS",
"pair": "cpp-python",
"Code1": "int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "def calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "cpp-python",
"Code1": "INT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "def shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nINT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "cpp-python",
"Code1": "int sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"Code2": "def sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "cpp-python",
"Code1": "void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"Code2": "def constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "cpp-python",
"Code1": "int patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n",
"Code2": "def patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n\n"
},
{
"id": "cpp-python-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "cpp-python",
"Code1": "int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"Code2": "def findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "cpp-python",
"Code1": "void parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n",
"Code2": "def parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "cpp-python",
"Code1": "int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"Code2": "def minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "cpp-python",
"Code1": "void longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n ",
"Code2": "def longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n \n"
},
{
"id": "cpp-python-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "cpp-python",
"Code1": "int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"Code2": "def pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n\n"
},
{
"id": "cpp-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "cpp-python",
"Code1": "int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_POWER_OF_2",
"pair": "cpp-python",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "cpp-python",
"Code1": "int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"Code2": "def maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n\n"
},
{
"id": "cpp-python-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "cpp-python",
"Code1": "void reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n",
"Code2": "def reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "cpp-python",
"Code1": "string nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n",
"Code2": "def nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n\n"
},
{
"id": "cpp-python-SUM_BINOMIAL_COEFFICIENTS",
"pair": "cpp-python",
"Code1": "int binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "def binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "cpp-python",
"Code1": "bool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"Code2": "def isEven ( n ) :\n return ( n % 2 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"Code2": "def binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "cpp-python",
"Code1": "void maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n",
"Code2": "def MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n\n"
},
{
"id": "cpp-python-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "cpp-python",
"Code1": "int bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n",
"Code2": "def isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "cpp-python",
"Code1": "int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"Code2": "def countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "cpp-python",
"Code1": "bool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "def isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "cpp-python",
"Code1": "void decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n",
"Code2": "def decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n\n"
},
{
"id": "cpp-python-FRIENDS_PAIRING_PROBLEM_1",
"pair": "cpp-python",
"Code1": "int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "cpp-python",
"Code1": "int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"Code2": "def maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "cpp-python",
"Code1": "int countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"Code2": "def countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "cpp-python",
"Code1": "bool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"Code2": "def checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "cpp-python",
"Code1": "int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "cpp-python",
"Code1": "public : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npublic : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "cpp-python",
"Code1": "int lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n",
"Code2": "def lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "cpp-python",
"Code1": "unsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "int minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n",
"Code2": "def minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "cpp-python",
"Code1": "int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"Code2": "def minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "cpp-python",
"Code1": "void carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n",
"Code2": "def carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "cpp-python",
"Code1": "int sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"Code2": "def sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "cpp-python",
"Code1": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"Code2": "def findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "cpp-python",
"Code1": "int maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "cpp-python",
"Code1": "void segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n",
"Code2": "def segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n\n"
},
{
"id": "cpp-python-MERGING_INTERVALS",
"pair": "cpp-python",
"Code1": "void mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n",
"Code2": "def mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "cpp-python",
"Code1": "float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n",
"Code2": "def correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "cpp-python",
"Code1": "int findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"Code2": "def findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n \n"
},
{
"id": "cpp-python-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "cpp-python",
"Code1": "int minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"Code2": "def minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "cpp-python",
"Code1": "int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"Code2": "def floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "cpp-python",
"Code1": "int isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"Code2": "def isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "cpp-python",
"Code1": "void printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n",
"Code2": "def printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "cpp-python",
"Code1": "int minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"Code2": "def minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "cpp-python",
"Code1": "long long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "cpp-python",
"Code1": "bool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n",
"Code2": "def isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "cpp-python",
"Code1": "int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"Code2": "def maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "cpp-python",
"Code1": "int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"Code2": "def findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "cpp-python",
"Code1": "int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"Code2": "def rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "cpp-python",
"Code1": "int assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"Code2": "def assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n \n"
},
{
"id": "cpp-python-TRIANGULAR_NUMBERS",
"pair": "cpp-python",
"Code1": "bool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-PANGRAM_CHECKING",
"pair": "cpp-python",
"Code1": "bool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"Code2": "def checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n\n"
},
{
"id": "cpp-python-INTERPOLATION_SEARCH",
"pair": "cpp-python",
"Code1": "int interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "def interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FITTING_SHELVES_PROBLEM",
"pair": "cpp-python",
"Code1": "void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n",
"Code2": "def minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "cpp-python",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n\n"
},
{
"id": "cpp-python-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "cpp-python",
"Code1": "void kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "cpp-python",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "cpp-python",
"Code1": "bool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "cpp-python",
"Code1": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "cpp-python",
"Code1": "int findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"Code2": "def findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n \n"
},
{
"id": "cpp-python-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "cpp-python",
"Code1": "int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n",
"Code2": "def kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "cpp-python",
"Code1": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"Code2": "def findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n\n"
},
{
"id": "cpp-python-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "cpp-python",
"Code1": "int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"Code2": "def kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "cpp-python",
"Code1": "void printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "cpp-python",
"Code1": "int decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n",
"Code2": "def decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n\n"
},
{
"id": "cpp-python-SUPER_PRIME",
"pair": "cpp-python",
"Code1": "bool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"Code2": "def SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "cpp-python",
"Code1": "int abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "cpp-python",
"Code1": "int countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n",
"Code2": "def countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "cpp-python",
"Code1": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"Code2": "def findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "cpp-python",
"Code1": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "cpp-python",
"Code1": "int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"Code2": "def minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n\n"
},
{
"id": "cpp-python-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "cpp-python",
"Code1": "void findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n",
"Code2": "def findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n\n"
},
{
"id": "cpp-python-MARKOV_MATRIX",
"pair": "cpp-python",
"Code1": "bool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "def checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "cpp-python",
"Code1": "int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"Code2": "def insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "cpp-python",
"Code1": "void recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"Code2": "def recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "cpp-python",
"Code1": "bool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"Code2": "def areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "cpp-python",
"Code1": "double findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"Code2": "def findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n\n"
},
{
"id": "cpp-python-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "cpp-python",
"Code1": "int sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"Code2": "def sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n",
"Code2": "def findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_MISSING_NUMBER_1",
"pair": "cpp-python",
"Code1": "int getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"Code2": "def getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_POWER_OF_2_2",
"pair": "cpp-python",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "cpp-python",
"Code1": "void add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"Code2": "def add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "cpp-python-ENTRINGER_NUMBER_1",
"pair": "cpp-python",
"Code1": "int zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n ",
"Code2": "def zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n \n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "cpp-python",
"Code1": "int eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"Code2": "def eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "cpp-python",
"Code1": "string noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n",
"Code2": "def noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-python-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "cpp-python",
"Code1": "int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"Code2": "def maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "cpp-python",
"Code1": "int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"Code2": "def minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n\n"
},
{
"id": "cpp-python-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "cpp-python",
"Code1": "bool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n",
"Code2": "def isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-HARDY_RAMANUJAN_THEOREM",
"pair": "cpp-python",
"Code1": "int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"Code2": "def exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "cpp-python",
"Code1": "void query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n",
"Code2": "def query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "cpp-python",
"Code1": "void findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n",
"Code2": "def findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "cpp-python",
"Code1": "int countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"Code2": "def countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "cpp-python",
"Code1": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "cpp-python",
"Code1": "void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n",
"Code2": "def print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "cpp-python",
"Code1": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nunsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "cpp-python",
"Code1": "- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"Code2": "def findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\n- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "cpp-python",
"Code1": "void printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n",
"Code2": "def printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "cpp-python",
"Code1": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-RECURSION",
"pair": "cpp-python",
"Code1": "void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n",
"Code2": "def printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n\n"
},
{
"id": "cpp-python-SHIFT_MATRIX_ELEMENTS_K",
"pair": "cpp-python",
"Code1": "void shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n",
"Code2": "def shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "cpp-python",
"Code1": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"Code2": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n \n"
},
{
"id": "cpp-python-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "cpp-python",
"Code1": "void findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"Code2": "def findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "cpp-python",
"Code1": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n ",
"Code2": "def findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n \n"
},
{
"id": "cpp-python-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "cpp-python",
"Code1": "bool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"Code2": "def squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "cpp-python",
"Code1": "int count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "cpp-python",
"Code1": "int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"Code2": "def maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "cpp-python",
"Code1": "void smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "def smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "cpp-python",
"Code1": "void findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n",
"Code2": "def findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "cpp-python",
"Code1": "int minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n",
"Code2": "def minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "cpp-python",
"Code1": "int singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"Code2": "def singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "cpp-python",
"Code1": "int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "cpp-python",
"Code1": "void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n",
"Code2": "def findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "cpp-python",
"Code1": "bool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n ",
"Code2": "def isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n \n"
},
{
"id": "cpp-python-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "cpp-python",
"Code1": "void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n",
"Code2": "def sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n\n"
},
{
"id": "cpp-python-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "cpp-python",
"Code1": "void printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"Code2": "def printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "cpp-python",
"Code1": "int findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n",
"Code2": "def findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "cpp-python",
"Code1": "void printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n",
"Code2": "def printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "cpp-python",
"Code1": "char * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n",
"Code2": "def simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "cpp-python",
"Code1": "double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n",
"Code2": "def vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n\n"
},
{
"id": "cpp-python-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "cpp-python",
"Code1": "int countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "cpp-python",
"Code1": "int sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n",
"Code2": "def sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "cpp-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "cpp-python",
"Code1": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"Code2": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "cpp-python",
"Code1": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n",
"Code2": "def isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n\n"
},
{
"id": "cpp-python-MAJORITY_ELEMENT_1",
"pair": "cpp-python",
"Code1": "void findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n",
"Code2": "def findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "cpp-python",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "cpp-python",
"Code1": "void replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n",
"Code2": "def replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-python-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "cpp-python",
"Code1": "void findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"Code2": "def findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_SUBSTRINGS_STRING",
"pair": "cpp-python",
"Code1": "int countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "def countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "cpp-python",
"Code1": "int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"Code2": "def countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "cpp-python",
"Code1": "int maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n",
"Code2": "def maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "cpp-python",
"Code1": "int countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"Code2": "def countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_PATH_SUM_MATRIX",
"pair": "cpp-python",
"Code1": "int findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n",
"Code2": "def findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "bool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"Code2": "def checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "cpp-python",
"Code1": "int check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "cpp-python",
"Code1": "void swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n",
"Code2": "def swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n\n"
},
{
"id": "cpp-python-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "cpp-python",
"Code1": "int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"Code2": "def find_Area ( r ) :\n return ( 2 * r * r )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "cpp-python",
"Code1": "bool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"Code2": "def isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "cpp-python",
"Code1": "void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n",
"Code2": "def countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "cpp-python",
"Code1": "void zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n",
"Code2": "def zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "cpp-python",
"Code1": "int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"Code2": "def countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "cpp-python",
"Code1": "bool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "cpp-python",
"Code1": "bool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"Code2": "def isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "cpp-python",
"Code1": "bool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"Code2": "def isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-KNAPSACK_PROBLEM",
"pair": "cpp-python",
"Code1": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "cpp-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"Code2": "def findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "cpp-python",
"Code1": "int breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"Code2": "def breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "cpp-python",
"Code1": "void decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n",
"Code2": "def decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n\n"
},
{
"id": "cpp-python-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "cpp-python",
"Code1": "int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n\n"
},
{
"id": "cpp-python-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "cpp-python",
"Code1": "bool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"Code2": "def oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "cpp-python",
"Code1": "bool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "cpp-python",
"Code1": "void strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n",
"Code2": "def strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "cpp-python",
"Code1": "void evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n",
"Code2": "def evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "cpp-python",
"Code1": "bool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"Code2": "def isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "cpp-python-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "cpp-python",
"Code1": "bool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n",
"Code2": "def findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "cpp-python",
"Code1": "int countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "cpp-python-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "cpp-python",
"Code1": "void findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n",
"Code2": "def findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n\n"
},
{
"id": "cpp-python-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "cpp-python",
"Code1": "void findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n",
"Code2": "def findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n\n"
},
{
"id": "cpp-python-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "cpp-python",
"Code1": "void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n",
"Code2": "def findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "cpp-python",
"Code1": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "cpp-python-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "cpp-python",
"Code1": "int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"Code2": "def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "cpp-python",
"Code1": "int solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"Code2": "def solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n\n"
},
{
"id": "cpp-python-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "cpp-python",
"Code1": "int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"Code2": "def firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "cpp-python",
"Code1": "int countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"Code2": "def countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "cpp-python-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "cpp-python",
"Code1": "void sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"Code2": "def sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "cpp-python",
"Code1": "bool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"Code2": "def canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "cpp-python",
"Code1": "void minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n",
"Code2": "def minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "cpp-python",
"Code1": "void KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n",
"Code2": "def KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n\n"
},
{
"id": "cpp-python-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "cpp-python",
"Code1": "void swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n",
"Code2": "def swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n\n"
},
{
"id": "cpp-python-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "cpp-python",
"Code1": "void psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n",
"Code2": "def psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "cpp-python",
"Code1": "int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n ",
"Code2": "def findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n \n"
},
{
"id": "cpp-python-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "cpp-python",
"Code1": "int minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"Code2": "def minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n\n"
},
{
"id": "cpp-python-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "cpp-python",
"Code1": "string maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n",
"Code2": "def maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "cpp-python",
"Code1": "int findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n ",
"Code2": "def findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n \n"
},
{
"id": "cpp-python-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "cpp-python",
"Code1": "void printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n",
"Code2": "def printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "cpp-python",
"Code1": "int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"Code2": "def maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "cpp-python",
"Code1": "int minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"Code2": "def minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "cpp-python",
"Code1": "int largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n",
"Code2": "def largest ( arr , n ) :\n return max ( arr )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "cpp-python",
"Code1": "float exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"Code2": "def exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nfloat exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n\n"
},
{
"id": "cpp-python-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "cpp-python",
"Code1": "int firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "def firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "cpp-python",
"Code1": "int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"Code2": "def maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "cpp-python",
"Code1": "int maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n",
"Code2": "def maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "cpp-python",
"Code1": "int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "cpp-python-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "cpp-python",
"Code1": "int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "cpp-python",
"Code1": "bool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n ",
"Code2": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n \n"
},
{
"id": "cpp-python-SUM_FACTORS_NUMBER",
"pair": "cpp-python",
"Code1": "int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"Code2": "def divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n\n"
},
{
"id": "cpp-python-ROTATE_MATRIX_180_DEGREE",
"pair": "cpp-python",
"Code1": "void rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"Code2": "def rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "cpp-python",
"Code1": "void printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n",
"Code2": "def printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "cpp-python",
"Code1": "int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"Code2": "def countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "cpp-python",
"Code1": "double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n",
"Code2": "def areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\ndouble areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n\n"
},
{
"id": "cpp-python-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "cpp-python",
"Code1": "int findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "cpp-python-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "cpp-python",
"Code1": "void printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n",
"Code2": "def printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "cpp-python",
"Code1": "int numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n ",
"Code2": "def numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n \n"
},
{
"id": "cpp-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "cpp-python",
"Code1": "bool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "cpp-python-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "cpp-python",
"Code1": "int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "def sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "cpp-python",
"Code1": "int findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "cpp-python",
"Code1": "int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"Code2": "def search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n\n"
},
{
"id": "cpp-python-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "cpp-python",
"Code1": "long int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"Code2": "def exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nlong int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n\n"
},
{
"id": "cpp-python-DIVISIBILITY_CHECK",
"pair": "cpp-python",
"Code1": "void divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n",
"Code2": "def divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "cpp-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n\n"
},
{
"id": "cpp-python-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "cpp-python",
"Code1": "int minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "cpp-python",
"Code1": "int height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n",
"Code2": "def height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n\n"
},
{
"id": "cpp-python-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "cpp-python",
"Code1": "bool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n",
"Code2": "def checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "cpp-python-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "cpp-python",
"Code1": "void removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n",
"Code2": "def removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n\n"
},
{
"id": "cpp-python-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "cpp-python",
"Code1": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "cpp-python-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "cpp-python",
"Code1": "int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"Code2": "def longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n\n"
},
{
"id": "cpp-python-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "cpp-python",
"Code1": "int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"Code2": "def addOne ( x ) :\n return ( - ( ~ x ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n\n"
},
{
"id": "cpp-python-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "cpp-python",
"Code1": "int getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"Code2": "def getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n\n"
},
{
"id": "cpp-python-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "cpp-python",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "cpp-python-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "cpp-python",
"Code1": "void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"Code2": "def bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n\n"
},
{
"id": "cpp-python-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "cpp-python",
"Code1": "int maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"Code2": "def maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n\n"
},
{
"id": "cpp-python-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "cpp-python",
"Code1": "pair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n",
"Code2": "def lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\npair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n\n"
},
{
"id": "cpp-python-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "cpp-python",
"Code1": "int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n",
"Code2": "def findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n\n"
},
{
"id": "cpp-python-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "cpp-python",
"Code1": "bool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "def find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "cpp-python-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "cpp-python",
"Code1": "void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n",
"Code2": "def KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n\n"
},
{
"id": "cpp-python-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "cpp-python",
"Code1": "int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"Code2": "def numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "cpp-python",
"Code1": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n ",
"Code2": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n \n"
},
{
"id": "cpp-python-DIVISIBILITY_BY_7",
"pair": "cpp-python",
"Code1": "int isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"Code2": "def isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n\n"
},
{
"id": "cpp-python-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "cpp-python",
"Code1": "int findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n ",
"Code2": "def findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n \n"
},
{
"id": "cpp-python-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "cpp-python",
"Code1": "int findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"Code2": "def findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n\n"
},
{
"id": "cpp-python-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "cpp-python",
"Code1": "int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"Code2": "def recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "cpp-python",
"Code1": "bool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n\n"
},
{
"id": "cpp-python-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "cpp-python",
"Code1": "string to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n",
"Code2": "def to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n\n"
},
{
"id": "cpp-python-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "cpp-python",
"Code1": "int remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n ",
"Code2": "def remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n \n"
},
{
"id": "cpp-python-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "cpp-python",
"Code1": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n",
"Code2": "def sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n\n"
},
{
"id": "cpp-python-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "cpp-python",
"Code1": "string getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n",
"Code2": "def getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "cpp-python-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "cpp-python",
"Code1": "bool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"Code2": "def isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nbool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "cpp-python-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "cpp-python",
"Code1": "void center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n",
"Code2": "def center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n\n"
},
{
"id": "cpp-python-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "cpp-python",
"Code1": "void findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"Code2": "def findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n\n"
},
{
"id": "cpp-python-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "cpp-python",
"Code1": "ll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"Code2": "def mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n\n"
},
{
"id": "cpp-python-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "cpp-python",
"Code1": "string Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"Code2": "def Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n\n"
},
{
"id": "cpp-python-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "cpp-python",
"Code1": "int minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"Code2": "def minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "cpp-python-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "cpp-python",
"Code1": "int findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nint findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n\n"
},
{
"id": "cpp-python-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "cpp-python",
"Code1": "char getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n ",
"Code2": "def getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nchar getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n \n"
},
{
"id": "cpp-python-SUM_TWO_LARGE_NUMBERS",
"pair": "cpp-python",
"Code1": "string findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n",
"Code2": "def findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nstring findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n\n"
},
{
"id": "cpp-python-NEXT_GREATER_ELEMENT",
"pair": "cpp-python",
"Code1": "void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n",
"Code2": "def printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n",
"instruction": "Translate the given code from cpp to python. The input Code is marked with and .",
"input": "\nvoid printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n\n"
},
{
"id": "java-cpp-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "java-cpp",
"Code1": "public static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n",
"Code2": "void printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "java-cpp",
"Code1": "static float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"Code2": "float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "java-cpp",
"Code1": "static boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n",
"Code2": "bool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "java-cpp",
"Code1": "static int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"Code2": "int nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-cpp",
"Code1": "static void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-NON_REPEATING_ELEMENT_1",
"pair": "java-cpp",
"Code1": "static int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "int firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "java-cpp",
"Code1": "static boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n",
"Code2": "bool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-BREAK_NUMBER_THREE_PARTS_1",
"pair": "java-cpp",
"Code1": "static long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"Code2": "ll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n",
"Code2": "int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "java-cpp",
"Code1": "static int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"Code2": "int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "java-cpp",
"Code1": "static int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n",
"Code2": "int smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "java-cpp",
"Code1": "static char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"Code2": "char findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n\n"
},
{
"id": "java-cpp-RECAMANS_SEQUENCE_1",
"pair": "java-cpp",
"Code1": "static void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"Code2": "void recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "java-cpp",
"Code1": "public static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"Code2": "int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "java-cpp",
"Code1": "static void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"Code2": "void countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "java-cpp",
"Code1": "static int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "java-cpp",
"Code1": "public static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "bool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FRIENDS_PAIRING_PROBLEM_2",
"pair": "java-cpp",
"Code1": "static int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"Code2": "int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n\n"
},
{
"id": "java-cpp-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "java-cpp",
"Code1": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n",
"Code2": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "java-cpp",
"Code1": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-cpp-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "java-cpp",
"Code1": "static void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "void subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "java-cpp",
"Code1": "static boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"Code2": "bool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "java-cpp",
"Code1": "static void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"Code2": "void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n\n"
},
{
"id": "java-cpp-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "java-cpp",
"Code1": "static float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"Code2": "public : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "java-cpp",
"Code1": "static int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"Code2": "int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "java-cpp",
"Code1": "static int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"Code2": "int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "java-cpp",
"Code1": "static boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n",
"Code2": "bool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "java-cpp",
"Code1": "public static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n",
"Code2": "double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n\n"
},
{
"id": "java-cpp-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "java-cpp",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "java-cpp",
"Code1": "static int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n",
"Code2": "int chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "java-cpp",
"Code1": "static double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"Code2": "double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n\n"
},
{
"id": "java-cpp-MAJORITY_ELEMENT",
"pair": "java-cpp",
"Code1": "static void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n",
"Code2": "void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "java-cpp",
"Code1": "static boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"Code2": "bool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "java-cpp",
"Code1": "static String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"Code2": "string findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "java-cpp",
"Code1": "static int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"Code2": "int countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "java-cpp",
"Code1": "static void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n",
"Code2": "void pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n\n"
},
{
"id": "java-cpp-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "java-cpp",
"Code1": "public static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"Code2": "int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n\n"
},
{
"id": "java-cpp-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "java-cpp",
"Code1": "public static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n",
"Code2": "void shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "java-cpp",
"Code1": "static int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n\n"
},
{
"id": "java-cpp-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "int maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "java-cpp",
"Code1": "static int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n",
"Code2": "int summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "java-cpp",
"Code1": "static boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"Code2": "bool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"Code2": "int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "java-cpp",
"Code1": "static int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"Code2": "int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"Code2": "int removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "java-cpp",
"Code1": "static void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n",
"Code2": "void find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-NON_REPEATING_ELEMENT",
"pair": "java-cpp",
"Code1": "static int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "java-cpp",
"Code1": "static void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n",
"Code2": "void middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n\n"
},
{
"id": "java-cpp-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "java-cpp",
"Code1": "static long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"Code2": "long long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "java-cpp",
"Code1": "static void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n",
"Code2": "void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-SUM_PAIRWISE_PRODUCTS_2",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"Code2": "long long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "java-cpp",
"Code1": "public static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"Code2": "int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "java-cpp",
"Code1": "static int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n",
"Code2": "int largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "java-cpp",
"Code1": "static boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "java-cpp",
"Code1": "static int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "int minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "java-cpp",
"Code1": "static void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n",
"Code2": "void arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "java-cpp",
"Code1": "static int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n",
"Code2": "int getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "java-cpp",
"Code1": "static int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"Code2": "int carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "java-cpp",
"Code1": "public static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"Code2": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "java-cpp",
"Code1": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n",
"Code2": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "java-cpp",
"Code1": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n",
"Code2": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "java-cpp",
"Code1": "static int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"Code2": "int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "java-cpp",
"Code1": "static void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n",
"Code2": "void printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "java-cpp",
"Code1": "static void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n",
"Code2": "void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "java-cpp",
"Code1": "static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"Code2": "int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "java-cpp",
"Code1": "static void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n",
"Code2": "void countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "java-cpp",
"Code1": "static float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "float findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "java-cpp",
"Code1": "static int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "int countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "java-cpp",
"Code1": "static int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n",
"Code2": "int lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "java-cpp",
"Code1": "static int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "int editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "java-cpp",
"Code1": "static int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"Code2": "int countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "java-cpp",
"Code1": "public static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n",
"Code2": "void longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "java-cpp",
"Code1": "static void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n",
"Code2": "void printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "java-cpp",
"Code1": "public static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n",
"Code2": "bool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "java-cpp",
"Code1": "static int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"Code2": "int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "java-cpp",
"Code1": "static void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n",
"Code2": "void printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_SORTED_ROWS_MATRIX",
"pair": "java-cpp",
"Code1": "static int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"Code2": "int sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "java-cpp",
"Code1": "static int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "int countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "java-cpp",
"Code1": "static void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n",
"Code2": "int findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n",
"Code2": "void printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "java-cpp",
"Code1": "static int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n",
"Code2": "int maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "java-cpp",
"Code1": "static int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n",
"Code2": "int largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "java-cpp",
"Code1": "static char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n",
"Code2": "char encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n",
"Code2": "int countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "java-cpp",
"Code1": "public static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"Code2": "int maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "java-cpp",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "java-cpp",
"Code1": "public static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n",
"Code2": "int countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "java-cpp",
"Code1": "static int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"Code2": "int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_1",
"pair": "java-cpp",
"Code1": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"Code2": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "java-cpp",
"Code1": "static int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "int countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "java-cpp",
"Code1": "static int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"Code2": "int countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "java-cpp",
"Code1": "static String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n",
"Code2": "string decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "java-cpp",
"Code1": "static int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"Code2": "int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '\n"
},
{
"id": "java-cpp-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "java-cpp",
"Code1": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"Code2": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "java-cpp",
"Code1": "static int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"Code2": "int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"Code2": "int maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "java-cpp",
"Code1": "static int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n",
"Code2": "int evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n\n"
},
{
"id": "java-cpp-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "java-cpp",
"Code1": "public static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"Code2": "int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "java-cpp",
"Code1": "static int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"Code2": "int numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "java-cpp",
"Code1": "static int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"Code2": "int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "java-cpp",
"Code1": "public static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "java-cpp",
"Code1": "static void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "void spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "java-cpp",
"Code1": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n",
"Code2": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "java-cpp",
"Code1": "static int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"Code2": "int minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n\n"
},
{
"id": "java-cpp-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "java-cpp",
"Code1": "static int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "int findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "java-cpp",
"Code1": "static void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n",
"Code2": "void convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "java-cpp",
"Code1": "static int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"Code2": "unsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n\n"
},
{
"id": "java-cpp-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "java-cpp",
"Code1": "static int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "java-cpp",
"Code1": "static void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n",
"Code2": "void transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "java-cpp",
"Code1": "static void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"Code2": "void findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "java-cpp",
"Code1": "static void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_AREA_QUADRILATERAL",
"pair": "java-cpp",
"Code1": "static double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"Code2": "double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n\n"
},
{
"id": "java-cpp-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "java-cpp",
"Code1": "static int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"Code2": "int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n\n"
},
{
"id": "java-cpp-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "java-cpp",
"Code1": "static void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n",
"Code2": "int printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "java-cpp",
"Code1": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"Code2": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "java-cpp",
"Code1": "public static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n",
"Code2": "int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n\n"
},
{
"id": "java-cpp-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "java-cpp",
"Code1": "static int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"Code2": "int countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "java-cpp",
"Code1": "static void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n",
"Code2": "void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "java-cpp",
"Code1": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "java-cpp",
"Code1": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"Code2": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "java-cpp",
"Code1": "static boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "java-cpp",
"Code1": "static int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "int getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-PRIME_FACTORS_BIG_NUMBER",
"pair": "java-cpp",
"Code1": "static void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n",
"Code2": "void factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "java-cpp",
"Code1": "static int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"Code2": "int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "java-cpp",
"Code1": "public static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "java-cpp",
"Code1": "static boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n",
"Code2": "bool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "java-cpp",
"Code1": "static void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n",
"Code2": "void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n\n"
},
{
"id": "java-cpp-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "java-cpp",
"Code1": "static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"Code2": "int solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n\n"
},
{
"id": "java-cpp-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "java-cpp",
"Code1": "static void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n",
"Code2": "void direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-cpp-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "java-cpp",
"Code1": "static void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n",
"Code2": "void splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "java-cpp",
"Code1": "static int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"Code2": "int binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-cpp-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "java-cpp",
"Code1": "private static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n",
"Code2": "void printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nprivate static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "java-cpp",
"Code1": "static void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n",
"Code2": "void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n\n"
},
{
"id": "java-cpp-SWAP_TWO_NIBBLES_BYTE",
"pair": "java-cpp",
"Code1": "static int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"Code2": "int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "java-cpp-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "java-cpp",
"Code1": "static int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"Code2": "int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_DIVISORS_1_N_1",
"pair": "java-cpp",
"Code1": "static int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"Code2": "int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "java-cpp",
"Code1": "static int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"Code2": "int addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "java-cpp",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"Code2": "int check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "java-cpp",
"Code1": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n",
"Code2": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "java-cpp",
"Code1": "static int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"Code2": "int minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n\n"
},
{
"id": "java-cpp-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "java-cpp",
"Code1": "void computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n",
"Code2": "void computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "java-cpp",
"Code1": "static int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "int numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-STOOGE_SORT",
"pair": "java-cpp",
"Code1": "static void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"Code2": "void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "java-cpp",
"Code1": "static void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n",
"Code2": "void solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "java-cpp",
"Code1": "static int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"Code2": "int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "java-cpp",
"Code1": "static void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n",
"Code2": "void printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "java-cpp",
"Code1": "static int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "java-cpp",
"Code1": "static int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n",
"Code2": "int stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "java-cpp",
"Code1": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"Code2": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n\n"
},
{
"id": "java-cpp-SUM_PAIRWISE_PRODUCTS_1",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"Code2": "long long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "java-cpp",
"Code1": "public static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "void recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "java-cpp",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "java-cpp",
"Code1": "static int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n",
"Code2": "int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "java-cpp",
"Code1": "static int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"Code2": "unsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "java-cpp",
"Code1": "static boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "bool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "java-cpp",
"Code1": "static int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n",
"Code2": "long long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "java-cpp",
"Code1": "public static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n",
"Code2": "long long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n\n"
},
{
"id": "java-cpp-COUNTING_INVERSIONS",
"pair": "java-cpp",
"Code1": "static int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n\n"
},
{
"id": "java-cpp-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "java-cpp",
"Code1": "static void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n",
"Code2": "void printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n\n"
},
{
"id": "java-cpp-DELANNOY_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "int dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "java-cpp",
"Code1": "static int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"Code2": "int power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CHECK_ISBN",
"pair": "java-cpp",
"Code1": "static boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"Code2": "bool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "java-cpp",
"Code1": "static void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "void NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "java-cpp",
"Code1": "static int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )",
"Code2": "int swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )\n"
},
{
"id": "java-cpp-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "java-cpp",
"Code1": "static void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"Code2": "void printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]\n"
},
{
"id": "java-cpp-HYPERCUBE_GRAPH",
"pair": "java-cpp",
"Code1": "static int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"Code2": "int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "java-cpp",
"Code1": "static void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "void findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "java-cpp",
"Code1": "static int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"Code2": "int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "java-cpp",
"Code1": "static void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n",
"Code2": "void reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "java-cpp",
"Code1": "static int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n",
"Code2": "int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "java-cpp",
"Code1": "static int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"Code2": "int longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n\n"
},
{
"id": "java-cpp-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "java-cpp",
"Code1": "static int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"Code2": "int MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "java-cpp",
"Code1": "static void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"Code2": "void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "java-cpp",
"Code1": "static void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n",
"Code2": "void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "java-cpp",
"Code1": "static boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n",
"Code2": "bool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "java-cpp",
"Code1": "static int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "int findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "java-cpp",
"Code1": "static int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "int countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-KNAPSACK_PROBLEM_1",
"pair": "java-cpp",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "java-cpp",
"Code1": "static void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"Code2": "void multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "java-cpp",
"Code1": "static int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"Code2": "int maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "java-cpp",
"Code1": "static int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "int findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_SINK_NODES_GRAPH",
"pair": "java-cpp",
"Code1": "static int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "java-cpp",
"Code1": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"Code2": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "java-cpp",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "java-cpp",
"Code1": "static int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n",
"Code2": "int countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "java-cpp",
"Code1": "boolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nboolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-LINEAR_SEARCH",
"pair": "java-cpp",
"Code1": "public static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "java-cpp",
"Code1": "static boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"Code2": "bool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "java-cpp",
"Code1": "static int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"Code2": "int binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "java-cpp",
"Code1": "static long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"Code2": "long countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-MIRROR_CHARACTERS_STRING",
"pair": "java-cpp",
"Code1": "static String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n",
"Code2": "string compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "java-cpp",
"Code1": "public static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"Code2": "int maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "java-cpp",
"Code1": "static long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"Code2": "long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n\n"
},
{
"id": "java-cpp-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"Code2": "int sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"Code2": "int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "java-cpp",
"Code1": "static int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"Code2": "int maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "java-cpp",
"Code1": "static int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"Code2": "int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "java-cpp",
"Code1": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "java-cpp",
"Code1": "static boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n",
"Code2": "bool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "java-cpp",
"Code1": "static boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"Code2": "bool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "java-cpp",
"Code1": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n",
"Code2": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "java-cpp",
"Code1": "static int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n",
"Code2": "int maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "java-cpp",
"Code1": "static int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"Code2": "int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "java-cpp",
"Code1": "static int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"Code2": "int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "java-cpp",
"Code1": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"Code2": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "java-cpp",
"Code1": "public static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n",
"Code2": "int minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "java-cpp",
"Code1": "static void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"Code2": "void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "java-cpp",
"Code1": "static void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "void spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "java-cpp",
"Code1": "static int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n",
"Code2": "int findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n\n"
},
{
"id": "java-cpp-NTH_PENTAGONAL_NUMBER",
"pair": "java-cpp",
"Code1": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"Code2": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "java-cpp",
"Code1": "static long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"Code2": "long long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FREQUENT_ELEMENT_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n",
"Code2": "int mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "java-cpp",
"Code1": "static int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"Code2": "int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "java-cpp",
"Code1": "static int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"Code2": "int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n\n"
},
{
"id": "java-cpp-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "java-cpp",
"Code1": "static String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"Code2": "string firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "java-cpp",
"Code1": "static void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n",
"Code2": "void assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "java-cpp",
"Code1": "static void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "java-cpp",
"Code1": "static int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"Code2": "int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "java-cpp",
"Code1": "static void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n",
"Code2": "void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "java-cpp",
"Code1": "static int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n",
"Code2": "int findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "java-cpp",
"Code1": "static int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"Code2": "int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "java-cpp",
"Code1": "static boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"Code2": "bool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "java-cpp",
"Code1": "static int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "java-cpp",
"Code1": "static boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n",
"Code2": "bool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "java-cpp",
"Code1": "static int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"Code2": "int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n\n"
},
{
"id": "java-cpp-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "java-cpp",
"Code1": "static String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"Code2": "string decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "java-cpp",
"Code1": "static int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"Code2": "int minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "java-cpp",
"Code1": "static boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"Code2": "bool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "java-cpp",
"Code1": "static int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n",
"Code2": "int countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "java-cpp",
"Code1": "static int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n",
"Code2": "int findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "java-cpp",
"Code1": "static void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n",
"Code2": "e9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "java-cpp",
"Code1": "static void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n",
"Code2": "void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-NUMBER_RECTANGLES_NM_GRID",
"pair": "java-cpp",
"Code1": "public static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"Code2": "int rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n\n"
},
{
"id": "java-cpp-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "java-cpp",
"Code1": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "java-cpp",
"Code1": "static void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "void subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "java-cpp",
"Code1": "static boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n",
"Code2": "bool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "java-cpp",
"Code1": "static int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"Code2": "int divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n\n"
},
{
"id": "java-cpp-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "java-cpp",
"Code1": "static int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"Code2": "int superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "java-cpp",
"Code1": "static void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "java-cpp",
"Code1": "public static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"Code2": "int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "java-cpp",
"Code1": "static boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"Code2": "bool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "java-cpp",
"Code1": "static boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"Code2": "bool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "java-cpp",
"Code1": "static int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n",
"Code2": "int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n\n"
},
{
"id": "java-cpp-REVERSE_A_STRING_USING_RECURSION",
"pair": "java-cpp",
"Code1": "void reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n",
"Code2": "void reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "java-cpp",
"Code1": "static long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"Code2": "long long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "java-cpp",
"Code1": "static boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"Code2": "bool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"Code2": "int maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "java-cpp",
"Code1": "static String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"Code2": "string lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "java-cpp",
"Code1": "public static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"Code2": "int maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "java-cpp",
"Code1": "static int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"Code2": "int xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n\n"
},
{
"id": "java-cpp-N_TH_ROOT_NUMBER",
"pair": "java-cpp",
"Code1": "static double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"Code2": "double nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n\n"
},
{
"id": "java-cpp-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "java-cpp",
"Code1": "static StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n",
"Code2": "string findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "java-cpp",
"Code1": "public static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n",
"Code2": "int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "java-cpp",
"Code1": "static void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n",
"Code2": "void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n\n"
},
{
"id": "java-cpp-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "java-cpp",
"Code1": "static int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n",
"Code2": "int findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "java-cpp",
"Code1": "static void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n",
"Code2": "void printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "java-cpp",
"Code1": "static int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "int evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "java-cpp",
"Code1": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n",
"Code2": "int getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "java-cpp",
"Code1": "static void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n",
"Code2": "void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "java-cpp",
"Code1": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n",
"Code2": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "java-cpp",
"Code1": "static boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"Code2": "bool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "java-cpp",
"Code1": "static void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n",
"Code2": "void printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "java-cpp",
"Code1": "int countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"Code2": "int countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "java-cpp",
"Code1": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "java-cpp",
"Code1": "static int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n",
"Code2": "int calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-cpp",
"Code1": "static void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "java-cpp",
"Code1": "static void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"Code2": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n\n"
},
{
"id": "java-cpp-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "java-cpp",
"Code1": "static boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "java-cpp",
"Code1": "static int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"Code2": "unsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "java-cpp",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "java-cpp",
"Code1": "static int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "int minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "java-cpp",
"Code1": "public static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "bool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "java-cpp",
"Code1": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"Code2": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "java-cpp",
"Code1": "public static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n",
"Code2": "bool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "java-cpp",
"Code1": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"Code2": "int getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n",
"Code2": "int maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "java-cpp",
"Code1": "static int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"Code2": "int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "java-cpp",
"Code1": "public static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n",
"Code2": "void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-cpp-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "java-cpp",
"Code1": "public static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "int nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "java-cpp",
"Code1": "static int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"Code2": "int countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "java-cpp",
"Code1": "static int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"Code2": "int selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "java-cpp",
"Code1": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n",
"Code2": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n\n"
},
{
"id": "java-cpp-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "java-cpp",
"Code1": "static boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "java-cpp",
"Code1": "static int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n",
"Code2": "int cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n\n"
},
{
"id": "java-cpp-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "java-cpp",
"Code1": "static int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"Code2": "int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "java-cpp",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "java-cpp",
"Code1": "static double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"Code2": "double surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n\n"
},
{
"id": "java-cpp-GNOME_SORT_A_STUPID_ONE",
"pair": "java-cpp",
"Code1": "static void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n",
"Code2": "void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "java-cpp",
"Code1": "public static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"Code2": "int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n\n"
},
{
"id": "java-cpp-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "java-cpp",
"Code1": "static int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"Code2": "int countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n\n"
},
{
"id": "java-cpp-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "java-cpp",
"Code1": "static void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n",
"Code2": "void generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "java-cpp",
"Code1": "static void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n",
"Code2": "void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "java-cpp",
"Code1": "static void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"Code2": "void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-FRIENDS_PAIRING_PROBLEM",
"pair": "java-cpp",
"Code1": "static int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "int countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "java-cpp",
"Code1": "static int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"Code2": "int remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n\n"
},
{
"id": "java-cpp-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "java-cpp",
"Code1": "public static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n",
"Code2": "int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n\n"
},
{
"id": "java-cpp-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "java-cpp",
"Code1": "static int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n",
"Code2": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "java-cpp",
"Code1": "static int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"Code2": "int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "java-cpp",
"Code1": "static void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"Code2": "void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "java-cpp",
"Code1": "static boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n",
"Code2": "bool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "java-cpp",
"Code1": "static double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n",
"Code2": "double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "java-cpp",
"Code1": "static int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-BINARY_SEARCH",
"pair": "java-cpp",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "java-cpp",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "java-cpp",
"Code1": "static long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"Code2": "long long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "java-cpp",
"Code1": "static int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"Code2": "int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "java-cpp",
"Code1": "static int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"Code2": "int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n\n"
},
{
"id": "java-cpp-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "java-cpp",
"Code1": "static void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n",
"Code2": "void moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n\n"
},
{
"id": "java-cpp-RECAMANS_SEQUENCE",
"pair": "java-cpp",
"Code1": "static void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n",
"Code2": "int recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "java-cpp",
"Code1": "static int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "java-cpp",
"Code1": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"Code2": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n\n"
},
{
"id": "java-cpp-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "java-cpp",
"Code1": "static int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n",
"Code2": "int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"Code2": "int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "java-cpp",
"Code1": "static int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"Code2": "int countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n\n"
},
{
"id": "java-cpp-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "java-cpp",
"Code1": "static int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"Code2": "int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "java-cpp",
"Code1": "static void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"Code2": "int substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "java-cpp",
"Code1": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"Code2": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "java-cpp",
"Code1": "static String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n",
"Code2": "string longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "java-cpp",
"Code1": "static boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "java-cpp",
"Code1": "public static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"Code2": "int calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n\n"
},
{
"id": "java-cpp-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "java-cpp",
"Code1": "static void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n",
"Code2": "void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "java-cpp",
"Code1": "public static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n",
"Code2": "void antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "java-cpp",
"Code1": "static void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n",
"Code2": "void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "java-cpp",
"Code1": "static int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "int findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "java-cpp",
"Code1": "static int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"Code2": "int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n\n"
},
{
"id": "java-cpp-BUBBLE_SORT",
"pair": "java-cpp",
"Code1": "void bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n",
"Code2": "void bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n\n"
},
{
"id": "java-cpp-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "int superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "java-cpp",
"Code1": "static int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"Code2": "int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "java-cpp",
"Code1": "static int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "java-cpp",
"Code1": "static int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"Code2": "int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "java-cpp",
"Code1": "public static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n",
"Code2": "int kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "java-cpp",
"Code1": "static int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"Code2": "INT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "java-cpp",
"Code1": "static String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "string reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "java-cpp",
"Code1": "static int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "int minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "java-cpp",
"Code1": "public static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"Code2": "int MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-cpp-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "java-cpp",
"Code1": "static void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n",
"Code2": "void bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "java-cpp",
"Code1": "static int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"Code2": "int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n\n"
},
{
"id": "java-cpp-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "java-cpp",
"Code1": "static void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n",
"Code2": "void printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "java-cpp",
"Code1": "static int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "java-cpp",
"Code1": "static void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"Code2": "void pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"Code2": "int minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "int lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "java-cpp",
"Code1": "static String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n",
"Code2": "string censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "java-cpp",
"Code1": "static int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"Code2": "public : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "java-cpp",
"Code1": "static float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "float getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "java-cpp",
"Code1": "static int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"Code2": "int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "java-cpp",
"Code1": "static void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n",
"Code2": "void findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n\n"
},
{
"id": "java-cpp-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "java-cpp",
"Code1": "static int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"Code2": "int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n\n"
},
{
"id": "java-cpp-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "java-cpp",
"Code1": "static int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n",
"Code2": "int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n\n"
},
{
"id": "java-cpp-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "java-cpp",
"Code1": "static boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n",
"Code2": "bool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n\n"
},
{
"id": "java-cpp-HOSOYAS_TRIANGLE",
"pair": "java-cpp",
"Code1": "static void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "void printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "java-cpp",
"Code1": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n",
"Code2": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVE_INSERTION_SORT",
"pair": "java-cpp",
"Code1": "static void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"Code2": "void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n\n"
},
{
"id": "java-cpp-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "int findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "java-cpp-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "java-cpp",
"Code1": "public static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n",
"Code2": "int playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "java-cpp",
"Code1": "static int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n",
"Code2": "int subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "java-cpp",
"Code1": "static boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"Code2": "bool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "java-cpp",
"Code1": "static double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n",
"Code2": "double largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "java-cpp",
"Code1": "static int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"Code2": "int getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n \n"
},
{
"id": "java-cpp-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "java-cpp",
"Code1": "public static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"Code2": "int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "java-cpp",
"Code1": "static int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "java-cpp",
"Code1": "static int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"Code2": "int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "java-cpp",
"Code1": "public static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n",
"Code2": "int count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "java-cpp",
"Code1": "static int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"Code2": "int findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n\n"
},
{
"id": "java-cpp-SHUFFLE_A_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n",
"Code2": "void randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "java-cpp",
"Code1": "static int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "java-cpp",
"Code1": "static void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n",
"Code2": "void translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "java-cpp",
"Code1": "static int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"Code2": "int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "java-cpp",
"Code1": "int catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n",
"Code2": "unsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SUM_SERIES_12_32_52_2N_12",
"pair": "java-cpp",
"Code1": "static int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"Code2": "int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "java-cpp",
"Code1": "static double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n",
"Code2": "int minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "java-cpp",
"Code1": "static void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n",
"Code2": "void printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "java-cpp",
"Code1": "static int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n",
"Code2": "int largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-PASCAL_TRIANGLE",
"pair": "java-cpp",
"Code1": "public static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "void printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "java-cpp",
"Code1": "static int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"Code2": "int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-CASSINIS_IDENTITY",
"pair": "java-cpp",
"Code1": "static int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n",
"Code2": "int cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n\n"
},
{
"id": "java-cpp-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "java-cpp",
"Code1": "static int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"Code2": "int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "java-cpp",
"Code1": "static int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"Code2": "int waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "java-cpp",
"Code1": "static void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n",
"Code2": "void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"Code2": "int maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "java-cpp",
"Code1": "static int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "long long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "java-cpp",
"Code1": "static int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"Code2": "int findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "java-cpp",
"Code1": "static int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "int findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "java-cpp",
"Code1": "static int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n",
"Code2": "int maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "java-cpp",
"Code1": "static void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-NTH_EVEN_LENGTH_PALINDROME",
"pair": "java-cpp",
"Code1": "static String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n",
"Code2": "string evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "java-cpp",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "java-cpp",
"Code1": "static int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "java-cpp",
"Code1": "static int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "int numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "java-cpp",
"Code1": "static double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"Code2": "double circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "java-cpp",
"Code1": "static void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n",
"Code2": "int substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "java-cpp",
"Code1": "static int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"Code2": "int maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "java-cpp",
"Code1": "public static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n",
"Code2": "int SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "java-cpp",
"Code1": "static int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n",
"Code2": "int fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "java-cpp",
"Code1": "static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n",
"Code2": "pair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "java-cpp",
"Code1": "static void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "java-cpp",
"Code1": "static void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n",
"Code2": "int printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "java-cpp",
"Code1": "static String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n",
"Code2": "string arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "java-cpp",
"Code1": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"Code2": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "java-cpp",
"Code1": "static int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"Code2": "int minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "java-cpp",
"Code1": "static String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"Code2": "string printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n\n"
},
{
"id": "java-cpp-ROTATE_MATRIX_ELEMENTS",
"pair": "java-cpp",
"Code1": "static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "void rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "java-cpp",
"Code1": "static int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"Code2": "int maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "java-cpp",
"Code1": "static double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n",
"Code2": "double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n\n"
},
{
"id": "java-cpp-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "java-cpp",
"Code1": "static void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n",
"Code2": "void sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "java-cpp",
"Code1": "public static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"Code2": "void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "java-cpp",
"Code1": "private static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nprivate static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "java-cpp",
"Code1": "static float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n",
"Code2": "float find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "java-cpp",
"Code1": "static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"Code2": "int waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-STERN_BROCOT_SEQUENCE",
"pair": "java-cpp",
"Code1": "static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n",
"Code2": "void SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-PRUFER_CODE_TREE_CREATION",
"pair": "java-cpp",
"Code1": "static void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n",
"Code2": "void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"Code2": "int countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "java-cpp",
"Code1": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"Code2": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "java-cpp",
"Code1": "static int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"Code2": "int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_BRACKET_NUMBER",
"pair": "java-cpp",
"Code1": "static void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"Code2": "void printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "java-cpp",
"Code1": "static int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"Code2": "int countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "java-cpp",
"Code1": "static int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"Code2": "int largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "java-cpp",
"Code1": "static int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n",
"Code2": "int findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"Code2": "int maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "java-cpp",
"Code1": "public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"Code2": "float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n\n"
},
{
"id": "java-cpp-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "java-cpp",
"Code1": "static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"Code2": "int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_ENDLESS_POINTS",
"pair": "java-cpp",
"Code1": "static int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "int countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-cpp",
"Code1": "static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "java-cpp",
"Code1": "static int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n",
"Code2": "int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "java-cpp",
"Code1": "public static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n",
"Code2": "bool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n\n"
},
{
"id": "java-cpp-DIAGONALLY_DOMINANT_MATRIX",
"pair": "java-cpp",
"Code1": "static boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"Code2": "bool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "java-cpp",
"Code1": "static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"Code2": "void transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "java-cpp",
"Code1": "static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"Code2": "int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "java-cpp",
"Code1": "static int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"Code2": "int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n\n"
},
{
"id": "java-cpp-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "java-cpp",
"Code1": "public static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"Code2": "INT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "java-cpp",
"Code1": "static long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"Code2": "long long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "java-cpp",
"Code1": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"Code2": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "java-cpp",
"Code1": "static void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"Code2": "void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n\n"
},
{
"id": "java-cpp-K_TH_DIGIT_RAISED_POWER_B",
"pair": "java-cpp",
"Code1": "public static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"Code2": "int kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "java-cpp",
"Code1": "public static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n",
"Code2": "bool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "java-cpp",
"Code1": "static void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n",
"Code2": "void printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "java-cpp",
"Code1": "public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"Code2": "bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "java-cpp",
"Code1": "static boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "java-cpp",
"Code1": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n",
"Code2": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "java-cpp",
"Code1": "static int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"Code2": "int maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "java-cpp",
"Code1": "static int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"Code2": "int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "java-cpp",
"Code1": "static double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"Code2": "double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "java-cpp",
"Code1": "static int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"Code2": "int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "java-cpp",
"Code1": "static int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"Code2": "int getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "java-cpp",
"Code1": "static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "bool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "java-cpp",
"Code1": "static void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n",
"Code2": "void printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "java-cpp",
"Code1": "static boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"Code2": "bool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "java-cpp",
"Code1": "static int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"Code2": "int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos\n"
},
{
"id": "java-cpp-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "java-cpp",
"Code1": "static int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"Code2": "int minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "java-cpp",
"Code1": "static void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"Code2": "void GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n\n"
},
{
"id": "java-cpp-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "java-cpp",
"Code1": "static int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"Code2": "int countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "java-cpp",
"Code1": "static int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n",
"Code2": "int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "java-cpp",
"Code1": "static boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n",
"Code2": "bool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "java-cpp",
"Code1": "static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n",
"Code2": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "java-cpp",
"Code1": "static int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"Code2": "int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n\n"
},
{
"id": "java-cpp-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "java-cpp",
"Code1": "static int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"Code2": "int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-NTH_NON_FIBONACCI_NUMBER",
"pair": "java-cpp",
"Code1": "static int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"Code2": "int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "java-cpp",
"Code1": "static void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n",
"Code2": "void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "java-cpp",
"Code1": "static String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"Code2": "string repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "java-cpp",
"Code1": "static String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"Code2": "string findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "java-cpp",
"Code1": "public static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"Code2": "public : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "java-cpp",
"Code1": "static void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "java-cpp",
"Code1": "static int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"Code2": "int minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n\n"
},
{
"id": "java-cpp-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "java-cpp",
"Code1": "static void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "void luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "java-cpp",
"Code1": "static void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n",
"Code2": "void bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "java-cpp",
"Code1": "static int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "int CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "java-cpp",
"Code1": "static void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n",
"Code2": "void modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n\n"
},
{
"id": "java-cpp-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "java-cpp",
"Code1": "static int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"Code2": "int minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "java-cpp",
"Code1": "static int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"Code2": "int maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "java-cpp",
"Code1": "static long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"Code2": "long long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "java-cpp",
"Code1": "static void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n",
"Code2": "void deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "java-cpp",
"Code1": "static char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n",
"Code2": "char first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "java-cpp",
"Code1": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n",
"Code2": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n\n"
},
{
"id": "java-cpp-ARC_LENGTH_ANGLE",
"pair": "java-cpp",
"Code1": "static double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"Code2": "double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n\n"
},
{
"id": "java-cpp-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "java-cpp",
"Code1": "static void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n",
"Code2": "void findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "java-cpp",
"Code1": "static boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-PRIME_NUMBERS",
"pair": "java-cpp",
"Code1": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"Code2": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "java-cpp",
"Code1": "static int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "java-cpp-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "java-cpp",
"Code1": "static void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n",
"Code2": "void maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n\n"
},
{
"id": "java-cpp-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "java-cpp",
"Code1": "static int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"Code2": "int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "java-cpp",
"Code1": "static void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"Code2": "void rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n\n"
},
{
"id": "java-cpp-N_BONACCI_NUMBERS_1",
"pair": "java-cpp",
"Code1": "static void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "void bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "java-cpp",
"Code1": "static int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"Code2": "int numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "java-cpp",
"Code1": "static int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"Code2": "int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "java-cpp",
"Code1": "static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"Code2": "int maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "java-cpp",
"Code1": "static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"Code2": "int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "java-cpp",
"Code1": "static int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"Code2": "int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "java-cpp",
"Code1": "private static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"Code2": "int minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nprivate static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "java-cpp",
"Code1": "public static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n",
"Code2": "void amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "java-cpp",
"Code1": "static int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"Code2": "int countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n\n"
},
{
"id": "java-cpp-BREAK_NUMBER_THREE_PARTS",
"pair": "java-cpp",
"Code1": "static long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"Code2": "ll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "java-cpp",
"Code1": "static double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n",
"Code2": "float sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n\n"
},
{
"id": "java-cpp-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "java-cpp",
"Code1": "static void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n",
"Code2": "void findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n\n"
},
{
"id": "java-cpp-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "java-cpp",
"Code1": "static int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"Code2": "int countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-HEXAGONAL_NUMBER",
"pair": "java-cpp",
"Code1": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"Code2": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "java-cpp",
"Code1": "static int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"Code2": "int findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "java-cpp",
"Code1": "static void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n",
"Code2": "void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "java-cpp",
"Code1": "static int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n",
"Code2": "int count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "java-cpp",
"Code1": "static int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n",
"Code2": "int find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n\n"
},
{
"id": "java-cpp-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "java-cpp",
"Code1": "static int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "java-cpp",
"Code1": "static double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n",
"Code2": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-LEONARDO_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"Code2": "int leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "java-cpp",
"Code1": "static int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "java-cpp",
"Code1": "static boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"Code2": "bool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "java-cpp",
"Code1": "static int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"Code2": "int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "java-cpp",
"Code1": "static int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-cpp-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "java-cpp",
"Code1": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "java-cpp",
"Code1": "static char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n",
"Code2": "char getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "java-cpp",
"Code1": "static int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"Code2": "int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "java-cpp",
"Code1": "static void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "java-cpp",
"Code1": "private static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n",
"Code2": "void findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nprivate static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "java-cpp",
"Code1": "static int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"Code2": "int countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "java-cpp",
"Code1": "static int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"Code2": "int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"Code2": "int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "java-cpp",
"Code1": "static int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "java-cpp",
"Code1": "static int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"Code2": "int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n\n"
},
{
"id": "java-cpp-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "java-cpp",
"Code1": "public static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"Code2": "double maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "java-cpp",
"Code1": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "java-cpp",
"Code1": "static int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n",
"Code2": "int longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "java-cpp",
"Code1": "static boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"Code2": "bool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "java-cpp",
"Code1": "static int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"Code2": "int computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "java-cpp",
"Code1": "static int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "int minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_POWER_OF_2_1",
"pair": "java-cpp",
"Code1": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "java-cpp-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "java-cpp",
"Code1": "static int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n",
"Code2": "int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n\n"
},
{
"id": "java-cpp-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "java-cpp",
"Code1": "static int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "int numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "java-cpp",
"Code1": "static boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"Code2": "bool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n\n"
},
{
"id": "java-cpp-NEWMAN_CONWAY_SEQUENCE",
"pair": "java-cpp",
"Code1": "static int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"Code2": "int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "java-cpp",
"Code1": "static void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"Code2": "void generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "java-cpp",
"Code1": "int countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n",
"Code2": "int countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n\n"
},
{
"id": "java-cpp-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "java-cpp",
"Code1": "static int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n",
"Code2": "int findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-LEONARDO_NUMBER",
"pair": "java-cpp",
"Code1": "static int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n",
"Code2": "int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "java-cpp",
"Code1": "static int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"Code2": "int findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "java-cpp",
"Code1": "static boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"Code2": "bool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "java-cpp",
"Code1": "static int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "int sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "java-cpp",
"Code1": "static void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "java-cpp",
"Code1": "static int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n",
"Code2": "int countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "java-cpp",
"Code1": "static int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"Code2": "int countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "java-cpp",
"Code1": "static void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "void printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-FLOOR_IN_A_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"Code2": "int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "java-cpp",
"Code1": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "java-cpp-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "java-cpp",
"Code1": "static void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n",
"Code2": "void printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "java-cpp",
"Code1": "static void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "void longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "java-cpp",
"Code1": "static int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"Code2": "int minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "java-cpp",
"Code1": "static int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"Code2": "int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "java-cpp",
"Code1": "static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"Code2": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "java-cpp",
"Code1": "static void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n",
"Code2": "void alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "java-cpp",
"Code1": "static void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n",
"Code2": "void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "java-cpp",
"Code1": "static int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "java-cpp-DICE_THROW_PROBLEM",
"pair": "java-cpp",
"Code1": "public static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n",
"Code2": "int findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "java-cpp",
"Code1": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n",
"Code2": "bool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "java-cpp",
"Code1": "static int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"Code2": "int findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-TILING_WITH_DOMINOES",
"pair": "java-cpp",
"Code1": "static int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"Code2": "int countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "java-cpp",
"Code1": "static int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"Code2": "int minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "java-cpp",
"Code1": "static boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"Code2": "bool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "java-cpp",
"Code1": "static int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"Code2": "int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-cpp-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "java-cpp",
"Code1": "static int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n",
"Code2": "public : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "java-cpp",
"Code1": "static int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "int countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-cpp",
"Code1": "static void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "java-cpp",
"Code1": "static int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"Code2": "int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "java-cpp",
"Code1": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "java-cpp",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-COMMON_CHARACTERS_N_STRINGS",
"pair": "java-cpp",
"Code1": "public static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n",
"Code2": "void commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "java-cpp",
"Code1": "static boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n",
"Code2": "bool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-MAGIC_SQUARE",
"pair": "java-cpp",
"Code1": "static void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "java-cpp",
"Code1": "static int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"Code2": "int count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "java-cpp",
"Code1": "static int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"Code2": "int numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "java-cpp",
"Code1": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"Code2": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"Code2": "int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "java-cpp",
"Code1": "static String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"Code2": "string decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n\n"
},
{
"id": "java-cpp-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "java-cpp",
"Code1": "static void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n",
"Code2": "public : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n\n"
},
{
"id": "java-cpp-PREFIX_SUM_2D_ARRAY",
"pair": "java-cpp",
"Code1": "public static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-EULERIAN_NUMBER",
"pair": "java-cpp",
"Code1": "public static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"Code2": "int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n",
"Code2": "long long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "java-cpp",
"Code1": "static int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n",
"Code2": "int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n\n"
},
{
"id": "java-cpp-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "java-cpp",
"Code1": "static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"Code2": "int longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_AREA_SQUARE",
"pair": "java-cpp",
"Code1": "static int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"Code2": "int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n\n"
},
{
"id": "java-cpp-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "java-cpp",
"Code1": "static void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n",
"Code2": "void findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n\n"
},
{
"id": "java-cpp-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "java-cpp",
"Code1": "static int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n",
"Code2": "int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "java-cpp",
"Code1": "static void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "void findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "java-cpp",
"Code1": "static int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"Code2": "int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"Code2": "int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "java-cpp",
"Code1": "static int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n",
"Code2": "int sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "java-cpp",
"Code1": "static int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n",
"Code2": "int calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n\n"
},
{
"id": "java-cpp-DOUBLE_FACTORIAL_1",
"pair": "java-cpp",
"Code1": "static int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n",
"Code2": "unsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_COMMON_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "java-cpp-TEMPLE_OFFERINGS",
"pair": "java-cpp",
"Code1": "static int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"Code2": "int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "java-cpp",
"Code1": "static int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n",
"Code2": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "java-cpp",
"Code1": "static String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "string constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "java-cpp",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "java-cpp",
"Code1": "static int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"Code2": "unsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-CAESAR_CIPHER",
"pair": "java-cpp",
"Code1": "public static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n",
"Code2": "string encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "java-cpp",
"Code1": "public static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n",
"Code2": "long double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n\n"
},
{
"id": "java-cpp-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "java-cpp",
"Code1": "static long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"Code2": "long int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "java-cpp",
"Code1": "static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"Code2": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a\n"
},
{
"id": "java-cpp-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "java-cpp",
"Code1": "static boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n",
"Code2": "bool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-SUM_PAIRWISE_PRODUCTS",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"Code2": "long long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "java-cpp",
"Code1": "static int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"Code2": "int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n\n"
},
{
"id": "java-cpp-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "java-cpp",
"Code1": "public static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"Code2": "int calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "java-cpp",
"Code1": "static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n",
"Code2": "void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINTING_ITEMS_01_KNAPSACK",
"pair": "java-cpp",
"Code1": "static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"Code2": "void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "java-cpp",
"Code1": "static int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"Code2": "int getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"Code2": "int findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "java-cpp",
"Code1": "static String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n",
"Code2": "string replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n\n"
},
{
"id": "java-cpp-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "java-cpp",
"Code1": "static int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"Code2": "int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "java-cpp",
"Code1": "static long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"Code2": "long long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n\n"
},
{
"id": "java-cpp-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "java-cpp",
"Code1": "static boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n",
"Code2": "bool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "java-cpp",
"Code1": "static int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "java-cpp",
"Code1": "static int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0",
"Code2": "int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0\n"
},
{
"id": "java-cpp-REMAINDER_7_LARGE_NUMBERS",
"pair": "java-cpp",
"Code1": "static int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"Code2": "int remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n \n"
},
{
"id": "java-cpp-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "java-cpp",
"Code1": "static boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"Code2": "bool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "java-cpp",
"Code1": "static int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"Code2": "int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "java-cpp",
"Code1": "static int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n",
"Code2": "int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n\n"
},
{
"id": "java-cpp-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "java-cpp",
"Code1": "static int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"Code2": "public : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "java-cpp",
"Code1": "static int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n",
"Code2": "int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n\n"
},
{
"id": "java-cpp-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "java-cpp",
"Code1": "static void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n",
"Code2": "void mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n\n"
},
{
"id": "java-cpp-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "java-cpp",
"Code1": "static void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "java-cpp",
"Code1": "public static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"Code2": "int minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "java-cpp",
"Code1": "static void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n",
"Code2": "void possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_SLOPE_LINE",
"pair": "java-cpp",
"Code1": "static float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"Code2": "float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "java-cpp",
"Code1": "double countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n",
"Code2": "int countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\ndouble countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "java-cpp",
"Code1": "static int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"Code2": "int countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "java-cpp",
"Code1": "static void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"Code2": "void findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "java-cpp",
"Code1": "static String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"Code2": "string lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "java-cpp",
"Code1": "public static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n",
"Code2": "void maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "java-cpp",
"Code1": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"Code2": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "java-cpp",
"Code1": "static int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n",
"Code2": "int findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n\n"
},
{
"id": "java-cpp-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "java-cpp",
"Code1": "static long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n",
"Code2": "long long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"Code2": "int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "java-cpp",
"Code1": "static int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"Code2": "int maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n",
"Code2": "ll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n\n"
},
{
"id": "java-cpp-PETERSON_GRAPH",
"pair": "java-cpp",
"Code1": "static boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n",
"Code2": "bool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "java-cpp",
"Code1": "static boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n",
"Code2": "bool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "java-cpp",
"Code1": "static void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"Code2": "void generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVE_FUNCTIONS",
"pair": "java-cpp",
"Code1": "static void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"Code2": "void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n\n"
},
{
"id": "java-cpp-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "java-cpp",
"Code1": "static int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "java-cpp",
"Code1": "static String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n",
"Code2": "string minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "java-cpp",
"Code1": "static int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"Code2": "int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "java-cpp",
"Code1": "static int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"Code2": "int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MISSING_NUMBER",
"pair": "java-cpp",
"Code1": "static int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"Code2": "int getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "java-cpp",
"Code1": "static void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n",
"Code2": "void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n\n"
},
{
"id": "java-cpp-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "java-cpp",
"Code1": "static boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"Code2": "bool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "java-cpp",
"Code1": "static void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n",
"Code2": "void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n\n"
},
{
"id": "java-cpp-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "java-cpp",
"Code1": "public static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n",
"Code2": "int findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "java-cpp",
"Code1": "public static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "void sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "java-cpp",
"Code1": "static int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "int countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "java-cpp",
"Code1": "static int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"Code2": "int count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "java-cpp",
"Code1": "static int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"Code2": "int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"Code2": "int findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "java-cpp",
"Code1": "static boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n",
"Code2": "bool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "java-cpp",
"Code1": "static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"Code2": "int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "java-cpp",
"Code1": "static int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"Code2": "int countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-JUMP_SEARCH",
"pair": "java-cpp",
"Code1": "public static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"Code2": "int jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_X_Y_SATISFYING_AX_N",
"pair": "java-cpp",
"Code1": "static void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n",
"Code2": "void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n\n"
},
{
"id": "java-cpp-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "java-cpp",
"Code1": "static String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"Code2": "string longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "java-cpp",
"Code1": "static void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n",
"Code2": "void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "java-cpp",
"Code1": "boolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"Code2": "bool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nboolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "java-cpp",
"Code1": "static int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "int find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "java-cpp",
"Code1": "static void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"Code2": "void printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-cpp-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "java-cpp",
"Code1": "public static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n",
"Code2": "void sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "java-cpp",
"Code1": "static int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n",
"Code2": "int find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "java-cpp",
"Code1": "static char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "char maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "java-cpp",
"Code1": "static int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "int solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "java-cpp",
"Code1": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"Code2": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint Circumference ( int a ) {\n return 4 * a ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "java-cpp",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n\n"
},
{
"id": "java-cpp-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "java-cpp",
"Code1": "static void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n",
"Code2": "void pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "java-cpp",
"Code1": "static int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n",
"Code2": "ll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n\n"
},
{
"id": "java-cpp-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "java-cpp",
"Code1": "public static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"Code2": "void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "java-cpp",
"Code1": "static int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"Code2": "int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n\n"
},
{
"id": "java-cpp-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "java-cpp",
"Code1": "static int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"Code2": "int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "java-cpp",
"Code1": "static Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"Code2": "bool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "java-cpp",
"Code1": "static int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"Code2": "int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "java-cpp",
"Code1": "static void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n",
"Code2": "void CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "java-cpp",
"Code1": "static int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"Code2": "uint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit\n"
},
{
"id": "java-cpp-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "java-cpp",
"Code1": "static boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "bool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "java-cpp",
"Code1": "static int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"Code2": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n\n"
},
{
"id": "java-cpp-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n",
"Code2": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "java-cpp",
"Code1": "static int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"Code2": "int nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n\n"
},
{
"id": "java-cpp-COCKTAIL_SORT",
"pair": "java-cpp",
"Code1": "void cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n",
"Code2": "void CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n\n"
},
{
"id": "java-cpp-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "java-cpp",
"Code1": "static void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"Code2": "void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n\n"
},
{
"id": "java-cpp-BINARY_SEARCH_1",
"pair": "java-cpp",
"Code1": "int binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_XOR_VALUE_PAIR",
"pair": "java-cpp",
"Code1": "static int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"Code2": "int minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "java-cpp",
"Code1": "public static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "java-cpp",
"Code1": "static char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n",
"Code2": "char first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "java-cpp",
"Code1": "static int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"Code2": "int maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "java-cpp",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "java-cpp",
"Code1": "static double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"Code2": "double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "java-cpp",
"Code1": "static void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n",
"Code2": "void rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "java-cpp",
"Code1": "static void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n",
"Code2": "void greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "java-cpp",
"Code1": "static int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"Code2": "int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_COMMON_SUBSTRING",
"pair": "java-cpp",
"Code1": "static int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"Code2": "int LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "java-cpp",
"Code1": "static int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"Code2": "int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIBONACCI_MODULO_P",
"pair": "java-cpp",
"Code1": "static int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"Code2": "int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n\n"
},
{
"id": "java-cpp-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "java-cpp",
"Code1": "static void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"Code2": "void reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "java-cpp",
"Code1": "static int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n",
"Code2": "int longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-cpp-SUM_FIBONACCI_NUMBERS",
"pair": "java-cpp",
"Code1": "static int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "java-cpp",
"Code1": "int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "INT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "java-cpp",
"Code1": "static int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"Code2": "int sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "java-cpp",
"Code1": "static void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"Code2": "void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "java-cpp",
"Code1": "static int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n",
"Code2": "int patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n\n"
},
{
"id": "java-cpp-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "java-cpp",
"Code1": "public static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"Code2": "int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "java-cpp",
"Code1": "static void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n",
"Code2": "void parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "java-cpp",
"Code1": "static int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"Code2": "int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "java-cpp",
"Code1": "static void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n",
"Code2": "void longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "java-cpp",
"Code1": "static int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"Code2": "int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n\n"
},
{
"id": "java-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "java-cpp",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_POWER_OF_2",
"pair": "java-cpp",
"Code1": "static int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "java-cpp",
"Code1": "static int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"Code2": "int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n\n"
},
{
"id": "java-cpp-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "java-cpp",
"Code1": "static void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n",
"Code2": "void reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "java-cpp",
"Code1": "public static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n",
"Code2": "string nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n\n"
},
{
"id": "java-cpp-SUM_BINOMIAL_COEFFICIENTS",
"pair": "java-cpp",
"Code1": "static int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "int binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "java-cpp",
"Code1": "public static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"Code2": "bool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "java-cpp",
"Code1": "static void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n",
"Code2": "void maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n\n"
},
{
"id": "java-cpp-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "java-cpp",
"Code1": "static boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n",
"Code2": "int bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "java-cpp",
"Code1": "static int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"Code2": "int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "java-cpp",
"Code1": "static boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "java-cpp",
"Code1": "static void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n",
"Code2": "void decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n\n"
},
{
"id": "java-cpp-FRIENDS_PAIRING_PROBLEM_1",
"pair": "java-cpp",
"Code1": "static int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"Code2": "int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "java-cpp",
"Code1": "static int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"Code2": "int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "java-cpp",
"Code1": "static int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"Code2": "int countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "java-cpp",
"Code1": "static boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"Code2": "bool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "java-cpp",
"Code1": "static int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"Code2": "int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "java-cpp",
"Code1": "static int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"Code2": "public : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "java-cpp",
"Code1": "static int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n",
"Code2": "int lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "java-cpp",
"Code1": "static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"Code2": "int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n\n"
},
{
"id": "java-cpp-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "java-cpp",
"Code1": "static void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n",
"Code2": "void carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "java-cpp",
"Code1": "public static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"Code2": "int sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "java-cpp",
"Code1": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n",
"Code2": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "java-cpp",
"Code1": "static int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "int maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "java-cpp",
"Code1": "static void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "void segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "java-cpp-MERGING_INTERVALS",
"pair": "java-cpp",
"Code1": "public static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n",
"Code2": "void mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "java-cpp",
"Code1": "static float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n",
"Code2": "float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "java-cpp",
"Code1": "static int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"Code2": "int findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n \n"
},
{
"id": "java-cpp-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "java-cpp",
"Code1": "static int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"Code2": "int minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "java-cpp",
"Code1": "static int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"Code2": "int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "java-cpp",
"Code1": "static boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"Code2": "int isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "java-cpp",
"Code1": "static void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "void printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "java-cpp",
"Code1": "static int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"Code2": "int minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "java-cpp",
"Code1": "static int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "long long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "java-cpp",
"Code1": "static boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n",
"Code2": "bool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "java-cpp",
"Code1": "static int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"Code2": "int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "java-cpp",
"Code1": "static int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"Code2": "int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "java-cpp",
"Code1": "static int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"Code2": "int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "java-cpp",
"Code1": "static int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"Code2": "int assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n \n"
},
{
"id": "java-cpp-TRIANGULAR_NUMBERS",
"pair": "java-cpp",
"Code1": "static boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"Code2": "bool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-PANGRAM_CHECKING",
"pair": "java-cpp",
"Code1": "public static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"Code2": "bool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n\n"
},
{
"id": "java-cpp-INTERPOLATION_SEARCH",
"pair": "java-cpp",
"Code1": "static int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "int interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FITTING_SHELVES_PROBLEM",
"pair": "java-cpp",
"Code1": "static void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n",
"Code2": "void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "java-cpp",
"Code1": "static int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n\n"
},
{
"id": "java-cpp-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "java-cpp",
"Code1": "public static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "void kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "java-cpp",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "java-cpp",
"Code1": "static boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n",
"Code2": "bool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "java-cpp",
"Code1": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "java-cpp",
"Code1": "int findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"Code2": "int findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n \n"
},
{
"id": "java-cpp-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "java-cpp",
"Code1": "static int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n",
"Code2": "int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "java-cpp",
"Code1": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"Code2": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n\n"
},
{
"id": "java-cpp-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "java-cpp",
"Code1": "static int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"Code2": "int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "java-cpp",
"Code1": "static void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "java-cpp",
"Code1": "public void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n",
"Code2": "int decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SUPER_PRIME",
"pair": "java-cpp",
"Code1": "static void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"Code2": "bool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "java-cpp",
"Code1": "static int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "int abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "java-cpp",
"Code1": "static int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n",
"Code2": "int countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "java-cpp",
"Code1": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"Code2": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "java-cpp",
"Code1": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "java-cpp",
"Code1": "static int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"Code2": "int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n\n"
},
{
"id": "java-cpp-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "java-cpp",
"Code1": "public static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"Code2": "void findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n\n"
},
{
"id": "java-cpp-MARKOV_MATRIX",
"pair": "java-cpp",
"Code1": "static boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "bool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"Code2": "int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "java-cpp",
"Code1": "static void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"Code2": "void recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "java-cpp",
"Code1": "boolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"Code2": "bool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nboolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "java-cpp",
"Code1": "static double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"Code2": "double findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n\n"
},
{
"id": "java-cpp-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "java-cpp",
"Code1": "public static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"Code2": "int sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n",
"Code2": "int findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_MISSING_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"Code2": "int getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_POWER_OF_2_2",
"pair": "java-cpp",
"Code1": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "java-cpp",
"Code1": "static void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"Code2": "void add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "java-cpp-ENTRINGER_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "int zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "java-cpp",
"Code1": "static int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"Code2": "int eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "java-cpp",
"Code1": "public static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n",
"Code2": "string noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n\n"
},
{
"id": "java-cpp-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "java-cpp",
"Code1": "static int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"Code2": "int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "java-cpp",
"Code1": "static int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"Code2": "int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n\n"
},
{
"id": "java-cpp-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "java-cpp",
"Code1": "static boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n",
"Code2": "bool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-HARDY_RAMANUJAN_THEOREM",
"pair": "java-cpp",
"Code1": "static int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"Code2": "int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "java-cpp",
"Code1": "static void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n",
"Code2": "void query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"Code2": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "java-cpp",
"Code1": "static void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n",
"Code2": "void findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "java-cpp",
"Code1": "int countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"Code2": "int countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "java-cpp",
"Code1": "static void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n",
"Code2": "void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "java-cpp",
"Code1": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "java-cpp",
"Code1": "static int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"Code2": "- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "java-cpp",
"Code1": "static void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n",
"Code2": "void printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "java-cpp",
"Code1": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-RECURSION",
"pair": "java-cpp",
"Code1": "static void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n",
"Code2": "void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-cpp-SHIFT_MATRIX_ELEMENTS_K",
"pair": "java-cpp",
"Code1": "static void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n",
"Code2": "void shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "java-cpp",
"Code1": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "java-cpp",
"Code1": "static void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n",
"Code2": "void findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "java-cpp",
"Code1": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n",
"Code2": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-cpp-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "java-cpp",
"Code1": "static boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"Code2": "bool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "java-cpp",
"Code1": "static int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "int count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "java-cpp",
"Code1": "static int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"Code2": "int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "java-cpp",
"Code1": "static void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "void smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "java-cpp",
"Code1": "static void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n",
"Code2": "void findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "java-cpp",
"Code1": "static int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n",
"Code2": "int minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "java-cpp",
"Code1": "static int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"Code2": "int singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "java-cpp",
"Code1": "static int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "java-cpp",
"Code1": "static void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n",
"Code2": "void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n\n"
},
{
"id": "java-cpp-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "java-cpp",
"Code1": "static boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n",
"Code2": "bool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "java-cpp",
"Code1": "static void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n",
"Code2": "void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n\n"
},
{
"id": "java-cpp-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "java-cpp",
"Code1": "static void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "java-cpp",
"Code1": "static int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n",
"Code2": "int findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "java-cpp",
"Code1": "static void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n",
"Code2": "void printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "java-cpp",
"Code1": "static String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n",
"Code2": "char * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n\n"
},
{
"id": "java-cpp-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "java-cpp",
"Code1": "static double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n",
"Code2": "double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n\n"
},
{
"id": "java-cpp-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "java-cpp",
"Code1": "static int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "int countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "java-cpp",
"Code1": "static int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n",
"Code2": "int sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "java-cpp",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "java-cpp",
"Code1": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"Code2": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "java-cpp",
"Code1": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n",
"Code2": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-MAJORITY_ELEMENT_1",
"pair": "java-cpp",
"Code1": "private static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n",
"Code2": "void findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nprivate static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "java-cpp",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "java-cpp",
"Code1": "static void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n",
"Code2": "void replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "java-cpp",
"Code1": "public static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n",
"Code2": "void findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_SUBSTRINGS_STRING",
"pair": "java-cpp",
"Code1": "static int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "int countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "java-cpp",
"Code1": "static int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"Code2": "int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "java-cpp",
"Code1": "static int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n",
"Code2": "int maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "java-cpp",
"Code1": "static int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"Code2": "int countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PATH_SUM_MATRIX",
"pair": "java-cpp",
"Code1": "static int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "int findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"Code2": "bool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "java-cpp",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"Code2": "int check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "java-cpp",
"Code1": "static void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n",
"Code2": "void swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "java-cpp",
"Code1": "static int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"Code2": "int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "java-cpp",
"Code1": "static boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"Code2": "bool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "java-cpp",
"Code1": "static void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n",
"Code2": "void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "java-cpp",
"Code1": "static void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n",
"Code2": "void zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "java-cpp",
"Code1": "static int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"Code2": "int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "java-cpp",
"Code1": "static boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "bool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "java-cpp",
"Code1": "static boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"Code2": "bool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "java-cpp",
"Code1": "static boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"Code2": "bool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-KNAPSACK_PROBLEM",
"pair": "java-cpp",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "java-cpp",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "static int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"Code2": "int findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "java-cpp",
"Code1": "static int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"Code2": "int breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "java-cpp",
"Code1": "static void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n",
"Code2": "void decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n\n"
},
{
"id": "java-cpp-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "java-cpp",
"Code1": "static int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"Code2": "int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n\n"
},
{
"id": "java-cpp-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "java-cpp",
"Code1": "static boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"Code2": "bool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "java-cpp",
"Code1": "static boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "bool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "java-cpp",
"Code1": "static void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n",
"Code2": "void strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "java-cpp",
"Code1": "static void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n",
"Code2": "void evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "java-cpp",
"Code1": "static Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"Code2": "bool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "java-cpp-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "java-cpp",
"Code1": "static boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n",
"Code2": "bool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "java-cpp",
"Code1": "static int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "int countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-cpp-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "java-cpp",
"Code1": "static void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n",
"Code2": "void findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n\n"
},
{
"id": "java-cpp-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "java-cpp",
"Code1": "static void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n",
"Code2": "void findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n\n"
},
{
"id": "java-cpp-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "java-cpp",
"Code1": "static void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "java-cpp",
"Code1": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "java-cpp",
"Code1": "public static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"Code2": "int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "java-cpp",
"Code1": "static int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"Code2": "int solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n\n"
},
{
"id": "java-cpp-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "java-cpp",
"Code1": "static int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"Code2": "int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "java-cpp",
"Code1": "static int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"Code2": "int countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-cpp-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "java-cpp",
"Code1": "static void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"Code2": "void sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "java-cpp",
"Code1": "static boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"Code2": "bool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "java-cpp",
"Code1": "static void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n",
"Code2": "void minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "java-cpp",
"Code1": "static void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n",
"Code2": "void KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n\n"
},
{
"id": "java-cpp-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "java-cpp",
"Code1": "static void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n",
"Code2": "void swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n\n"
},
{
"id": "java-cpp-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "java-cpp",
"Code1": "public static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n",
"Code2": "void psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "java-cpp",
"Code1": "static int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n",
"Code2": "int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "java-cpp",
"Code1": "static int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"Code2": "int minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n\n"
},
{
"id": "java-cpp-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "java-cpp",
"Code1": "static String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n",
"Code2": "string maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "java-cpp",
"Code1": "static int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n",
"Code2": "int findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "java-cpp",
"Code1": "static void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n",
"Code2": "void printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "java-cpp",
"Code1": "static int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"Code2": "int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "java-cpp",
"Code1": "public static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"Code2": "int minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n",
"Code2": "int largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "java-cpp",
"Code1": "static float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"Code2": "float exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n\n"
},
{
"id": "java-cpp-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "java-cpp",
"Code1": "static int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "int firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "java-cpp",
"Code1": "static int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"Code2": "int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "java-cpp",
"Code1": "public static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n",
"Code2": "int maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "java-cpp",
"Code1": "static int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-cpp-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "java-cpp",
"Code1": "static int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "java-cpp",
"Code1": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "bool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-SUM_FACTORS_NUMBER",
"pair": "java-cpp",
"Code1": "static int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"Code2": "int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n\n"
},
{
"id": "java-cpp-ROTATE_MATRIX_180_DEGREE",
"pair": "java-cpp",
"Code1": "static void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "void rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "java-cpp",
"Code1": "static void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n",
"Code2": "void printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "java-cpp",
"Code1": "static int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"Code2": "int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "java-cpp",
"Code1": "static double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n",
"Code2": "double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n\n"
},
{
"id": "java-cpp-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "java-cpp",
"Code1": "static int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "int findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-cpp-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "java-cpp",
"Code1": "static void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n",
"Code2": "void printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "java-cpp",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "java-cpp",
"Code1": "static int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"Code2": "bool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "java-cpp",
"Code1": "static int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "java-cpp",
"Code1": "static int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "java-cpp",
"Code1": "static int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"Code2": "int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n\n"
},
{
"id": "java-cpp-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "java-cpp",
"Code1": "static long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"Code2": "long int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n\n"
},
{
"id": "java-cpp-DIVISIBILITY_CHECK",
"pair": "java-cpp",
"Code1": "static void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n",
"Code2": "void divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "java-cpp",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "java-cpp",
"Code1": "static int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "int minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "java-cpp",
"Code1": "static int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n",
"Code2": "int height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n\n"
},
{
"id": "java-cpp-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "java-cpp",
"Code1": "static boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n",
"Code2": "bool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-cpp-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "java-cpp",
"Code1": "static void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n",
"Code2": "void removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "java-cpp",
"Code1": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "java-cpp-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "java-cpp",
"Code1": "public static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"Code2": "int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n\n"
},
{
"id": "java-cpp-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "java-cpp",
"Code1": "static int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"Code2": "int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n\n"
},
{
"id": "java-cpp-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "java-cpp",
"Code1": "static int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"Code2": "int getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n\n"
},
{
"id": "java-cpp-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "java-cpp",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "java-cpp",
"Code1": "static void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"Code2": "void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n\n"
},
{
"id": "java-cpp-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "java-cpp",
"Code1": "static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"Code2": "int maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n\n"
},
{
"id": "java-cpp-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "java-cpp",
"Code1": "static void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n",
"Code2": "pair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "java-cpp",
"Code1": "static int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n",
"Code2": "int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "java-cpp",
"Code1": "boolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "bool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nboolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-cpp-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "java-cpp",
"Code1": "static void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n",
"Code2": "void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n\n"
},
{
"id": "java-cpp-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "java-cpp",
"Code1": "public static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"Code2": "int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\npublic static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n\n"
},
{
"id": "java-cpp-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "java-cpp",
"Code1": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n",
"Code2": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-DIVISIBILITY_BY_7",
"pair": "java-cpp",
"Code1": "static boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"Code2": "int isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n\n"
},
{
"id": "java-cpp-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "java-cpp",
"Code1": "static int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "int findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-cpp-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "java-cpp",
"Code1": "static int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"Code2": "int findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n\n"
},
{
"id": "java-cpp-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "java-cpp",
"Code1": "static int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"Code2": "int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "java-cpp",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"Code2": "bool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n\n"
},
{
"id": "java-cpp-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "java-cpp",
"Code1": "static String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n",
"Code2": "string to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n\n"
},
{
"id": "java-cpp-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "java-cpp",
"Code1": "static int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n",
"Code2": "int remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-cpp-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "java-cpp",
"Code1": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n",
"Code2": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nvoid sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "java-cpp",
"Code1": "static String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n",
"Code2": "string getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n\n"
},
{
"id": "java-cpp-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "java-cpp",
"Code1": "static boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"Code2": "bool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-cpp-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "java-cpp",
"Code1": "static void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n",
"Code2": "void center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "java-cpp",
"Code1": "static void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n",
"Code2": "void findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n\n"
},
{
"id": "java-cpp-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "java-cpp",
"Code1": "static long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"Code2": "ll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n\n"
},
{
"id": "java-cpp-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "java-cpp",
"Code1": "static String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"Code2": "string Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n\n"
},
{
"id": "java-cpp-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "java-cpp",
"Code1": "static int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"Code2": "int minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-cpp-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "java-cpp",
"Code1": "static int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n\n"
},
{
"id": "java-cpp-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "java-cpp",
"Code1": "static char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n",
"Code2": "char getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n ",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n\n"
},
{
"id": "java-cpp-SUM_TWO_LARGE_NUMBERS",
"pair": "java-cpp",
"Code1": "static String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n",
"Code2": "string findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n\n"
},
{
"id": "java-cpp-NEXT_GREATER_ELEMENT",
"pair": "java-cpp",
"Code1": "static void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n",
"Code2": "void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n",
"instruction": "Translate the given code from java to cpp. The input Code is marked with and .",
"input": "\nstatic void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n\n"
},
{
"id": "java-python-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "java-python",
"Code1": "public static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n",
"Code2": "def printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "java-python",
"Code1": "static float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"Code2": "def findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "java-python",
"Code1": "static boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n",
"Code2": "def isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "java-python",
"Code1": "static int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"Code2": "def nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-python",
"Code1": "static void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-NON_REPEATING_ELEMENT_1",
"pair": "java-python",
"Code1": "static int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "def firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "java-python",
"Code1": "static boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n",
"Code2": "def distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-BREAK_NUMBER_THREE_PARTS_1",
"pair": "java-python",
"Code1": "static long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"Code2": "def count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "java-python",
"Code1": "static int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n",
"Code2": "def maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "java-python",
"Code1": "static int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"Code2": "def calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "java-python",
"Code1": "static int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n",
"Code2": "def smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n\n"
},
{
"id": "java-python-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "java-python",
"Code1": "static char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"Code2": "def findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n\n"
},
{
"id": "java-python-RECAMANS_SEQUENCE_1",
"pair": "java-python",
"Code1": "static void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"Code2": "def recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "java-python",
"Code1": "public static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"Code2": "def findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "java-python",
"Code1": "static void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"Code2": "def countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "java-python",
"Code1": "static int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "java-python",
"Code1": "public static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-FRIENDS_PAIRING_PROBLEM_2",
"pair": "java-python",
"Code1": "static int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n\n"
},
{
"id": "java-python-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "java-python",
"Code1": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n",
"Code2": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "java-python",
"Code1": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "def findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-python-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "java-python",
"Code1": "static void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "def subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "java-python",
"Code1": "static boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "java-python",
"Code1": "static void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"Code2": "def solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n\n"
},
{
"id": "java-python-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "java-python",
"Code1": "static float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"Code2": "def squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "java-python",
"Code1": "static int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"Code2": "def CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "java-python",
"Code1": "static int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"Code2": "def multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "java-python",
"Code1": "static boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n",
"Code2": "def prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n\n"
},
{
"id": "java-python-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "java-python",
"Code1": "public static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n",
"Code2": "def polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n\n"
},
{
"id": "java-python-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "java-python",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "java-python",
"Code1": "static int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n",
"Code2": "def chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n\n"
},
{
"id": "java-python-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "java-python",
"Code1": "static double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"Code2": "def compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n\n"
},
{
"id": "java-python-MAJORITY_ELEMENT",
"pair": "java-python",
"Code1": "static void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n",
"Code2": "def findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "java-python",
"Code1": "static boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "java-python",
"Code1": "static String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"Code2": "def findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "java-python",
"Code1": "static int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"Code2": "def countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "java-python",
"Code1": "static void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n",
"Code2": "def pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n\n"
},
{
"id": "java-python-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "java-python",
"Code1": "public static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"Code2": "def nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n\n"
},
{
"id": "java-python-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "java-python",
"Code1": "public static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n",
"Code2": "def shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "java-python",
"Code1": "static int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n\n"
},
{
"id": "java-python-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "java-python",
"Code1": "static int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n",
"Code2": "def summingSeries ( n ) :\n return math.pow ( n , 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n\n"
},
{
"id": "java-python-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "java-python",
"Code1": "static boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"Code2": "def isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n\n"
},
{
"id": "java-python-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "java-python",
"Code1": "static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"Code2": "def findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n\n"
},
{
"id": "java-python-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "java-python",
"Code1": "static int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"Code2": "def numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "java-python",
"Code1": "static int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"Code2": "def removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "java-python",
"Code1": "static void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n",
"Code2": "def find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-NON_REPEATING_ELEMENT",
"pair": "java-python",
"Code1": "static int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "java-python",
"Code1": "static void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n",
"Code2": "def middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n\n"
},
{
"id": "java-python-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "java-python",
"Code1": "static long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"Code2": "def moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "java-python",
"Code1": "static void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n",
"Code2": "def pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n\n"
},
{
"id": "java-python-SUM_PAIRWISE_PRODUCTS_2",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"Code2": "def findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "java-python",
"Code1": "public static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"Code2": "def fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "java-python-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "java-python",
"Code1": "static int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n",
"Code2": "def largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "java-python",
"Code1": "static boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "java-python",
"Code1": "static int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "def minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "java-python",
"Code1": "static void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n",
"Code2": "def arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "java-python",
"Code1": "static int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n",
"Code2": "def getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "java-python",
"Code1": "static int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"Code2": "def carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n\n"
},
{
"id": "java-python-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "java-python",
"Code1": "public static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n\n"
},
{
"id": "java-python-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "java-python",
"Code1": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n",
"Code2": "def findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "java-python",
"Code1": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n",
"Code2": "def getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "java-python",
"Code1": "static int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"Code2": "def maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "java-python",
"Code1": "static void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n",
"Code2": "def printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "java-python",
"Code1": "static void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n",
"Code2": "def printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n\n"
},
{
"id": "java-python-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "java-python",
"Code1": "static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"Code2": "def circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n\n"
},
{
"id": "java-python-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "java-python",
"Code1": "static void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n",
"Code2": "def countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "java-python",
"Code1": "static float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "def findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "java-python-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "java-python",
"Code1": "static int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "java-python",
"Code1": "static int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n",
"Code2": "def lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "java-python",
"Code1": "static int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "java-python",
"Code1": "static int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"Code2": "def countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n\n"
},
{
"id": "java-python-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "java-python",
"Code1": "public static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n",
"Code2": "def longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "java-python",
"Code1": "static void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n",
"Code2": "def printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "java-python",
"Code1": "public static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n",
"Code2": "def isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "java-python",
"Code1": "static int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"Code2": "def maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "java-python",
"Code1": "static void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n",
"Code2": "def printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_SORTED_ROWS_MATRIX",
"pair": "java-python",
"Code1": "static int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"Code2": "def sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "java-python",
"Code1": "static int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "def countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-python-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "java-python",
"Code1": "static void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n",
"Code2": "def findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n",
"Code2": "def printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "java-python",
"Code1": "static int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n",
"Code2": "def maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "java-python",
"Code1": "static int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n",
"Code2": "def largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n\n"
},
{
"id": "java-python-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "java-python",
"Code1": "static char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n",
"Code2": "def encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n\n"
},
{
"id": "java-python-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "java-python",
"Code1": "static int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n",
"Code2": "def countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "java-python",
"Code1": "public static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "java-python",
"Code1": "static int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"Code2": "def maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "java-python",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n\n"
},
{
"id": "java-python-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "java-python",
"Code1": "public static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n",
"Code2": "def countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "java-python-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "java-python",
"Code1": "static int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"Code2": "def nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_1",
"pair": "java-python",
"Code1": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"Code2": "def fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "java-python",
"Code1": "static int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"Code2": "def countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "java-python",
"Code1": "static int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"Code2": "def countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-python-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "java-python",
"Code1": "static String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n",
"Code2": "def decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "java-python",
"Code1": "static int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"Code2": "def countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '\n"
},
{
"id": "java-python-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "java-python",
"Code1": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"Code2": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "java-python",
"Code1": "static int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"Code2": "def longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "java-python",
"Code1": "static int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"Code2": "def maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "java-python",
"Code1": "static int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n",
"Code2": "def evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n\n"
},
{
"id": "java-python-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "java-python",
"Code1": "public static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"Code2": "def findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n\n"
},
{
"id": "java-python-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "java-python",
"Code1": "static int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"Code2": "def numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "java-python",
"Code1": "static int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"Code2": "def countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "java-python",
"Code1": "public static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "java-python",
"Code1": "static void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "def spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-python-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "java-python",
"Code1": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n",
"Code2": "def printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "java-python",
"Code1": "static int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"Code2": "def minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n\n"
},
{
"id": "java-python-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "java-python",
"Code1": "static int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"Code2": "def findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "java-python",
"Code1": "static void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n",
"Code2": "def convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "java-python",
"Code1": "static int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"Code2": "def decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n\n"
},
{
"id": "java-python-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "java-python",
"Code1": "static int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "java-python",
"Code1": "static void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n",
"Code2": "def transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "java-python",
"Code1": "static void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"Code2": "def findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "java-python",
"Code1": "static void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_AREA_QUADRILATERAL",
"pair": "java-python",
"Code1": "static double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"Code2": "def maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n\n"
},
{
"id": "java-python-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "java-python",
"Code1": "static int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"Code2": "def Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n\n"
},
{
"id": "java-python-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "java-python",
"Code1": "static void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n",
"Code2": "def printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "java-python",
"Code1": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"Code2": "def isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "java-python",
"Code1": "public static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n",
"Code2": "def countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n\n"
},
{
"id": "java-python-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "java-python",
"Code1": "static int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"Code2": "def CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "java-python-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "java-python",
"Code1": "static void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n",
"Code2": "def twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n\n"
},
{
"id": "java-python-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "java-python",
"Code1": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"Code2": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "java-python",
"Code1": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"Code2": "def findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n\n"
},
{
"id": "java-python-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "java-python",
"Code1": "static boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "java-python",
"Code1": "static int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-PRIME_FACTORS_BIG_NUMBER",
"pair": "java-python",
"Code1": "static void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n",
"Code2": "def factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "java-python",
"Code1": "static int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"Code2": "def findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "java-python",
"Code1": "public static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "java-python",
"Code1": "static boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n",
"Code2": "def isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n\n"
},
{
"id": "java-python-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "java-python",
"Code1": "static void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n",
"Code2": "def bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n\n"
},
{
"id": "java-python-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "java-python",
"Code1": "static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"Code2": "def solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n\n"
},
{
"id": "java-python-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "java-python",
"Code1": "static void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n",
"Code2": "def direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-python-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "java-python",
"Code1": "static void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n",
"Code2": "def splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "java-python",
"Code1": "static int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"Code2": "def binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-python-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "java-python",
"Code1": "private static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n",
"Code2": "def printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nprivate static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "java-python",
"Code1": "static void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n",
"Code2": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n\n"
},
{
"id": "java-python-SWAP_TWO_NIBBLES_BYTE",
"pair": "java-python",
"Code1": "static int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"Code2": "def swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "java-python-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "java-python",
"Code1": "static int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"Code2": "def countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n\n"
},
{
"id": "java-python-SUM_DIVISORS_1_N_1",
"pair": "java-python",
"Code1": "static int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"Code2": "def divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "java-python",
"Code1": "static int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"Code2": "def addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n\n"
},
{
"id": "java-python-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "java-python",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "java-python",
"Code1": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n",
"Code2": "def findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n\n"
},
{
"id": "java-python-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "java-python",
"Code1": "static int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"Code2": "def minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n\n"
},
{
"id": "java-python-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "java-python",
"Code1": "void computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n",
"Code2": "def computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "java-python",
"Code1": "static int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-STOOGE_SORT",
"pair": "java-python",
"Code1": "static void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"Code2": "def stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "java-python",
"Code1": "static void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n",
"Code2": "def solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n\n"
},
{
"id": "java-python-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "java-python",
"Code1": "static int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"Code2": "def turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n\n"
},
{
"id": "java-python-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "java-python",
"Code1": "static void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n",
"Code2": "def printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "java-python",
"Code1": "static int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "java-python",
"Code1": "static int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n",
"Code2": "def stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-python-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "java-python",
"Code1": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"Code2": "def KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n\n"
},
{
"id": "java-python-SUM_PAIRWISE_PRODUCTS_1",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "java-python",
"Code1": "public static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "def recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "java-python",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"Code2": "def subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "java-python",
"Code1": "static int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n",
"Code2": "def getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "java-python",
"Code1": "static int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"Code2": "def getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "java-python",
"Code1": "static boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "def allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "java-python",
"Code1": "static int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n",
"Code2": "def maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "java-python",
"Code1": "public static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n",
"Code2": "def countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n\n"
},
{
"id": "java-python-COUNTING_INVERSIONS",
"pair": "java-python",
"Code1": "static int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"Code2": "def getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n\n"
},
{
"id": "java-python-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "java-python",
"Code1": "static void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n",
"Code2": "def printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n\n"
},
{
"id": "java-python-DELANNOY_NUMBER_1",
"pair": "java-python",
"Code1": "static int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "java-python",
"Code1": "static int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"Code2": "def power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CHECK_ISBN",
"pair": "java-python",
"Code1": "static boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"Code2": "def isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "java-python",
"Code1": "static void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "def NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "java-python",
"Code1": "static int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )",
"Code2": "def swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )\n"
},
{
"id": "java-python-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "java-python",
"Code1": "static void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"Code2": "def printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]\n"
},
{
"id": "java-python-HYPERCUBE_GRAPH",
"pair": "java-python",
"Code1": "static int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"Code2": "def power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "java-python",
"Code1": "static void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "def findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "java-python",
"Code1": "static int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"Code2": "def lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "java-python",
"Code1": "static void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n",
"Code2": "def reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "java-python",
"Code1": "static int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n",
"Code2": "def findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n\n"
},
{
"id": "java-python-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "java-python",
"Code1": "static int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"Code2": "def longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n\n"
},
{
"id": "java-python-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "java-python",
"Code1": "static int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"Code2": "def MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "java-python",
"Code1": "static void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"Code2": "def printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "java-python",
"Code1": "static void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n",
"Code2": "def minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n\n"
},
{
"id": "java-python-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "java-python",
"Code1": "static boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n",
"Code2": "def isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "java-python",
"Code1": "static int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "java-python",
"Code1": "static int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-KNAPSACK_PROBLEM_1",
"pair": "java-python",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "java-python",
"Code1": "static void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"Code2": "def multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "java-python",
"Code1": "static int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"Code2": "def maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n\n"
},
{
"id": "java-python-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "java-python",
"Code1": "static int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "def findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_SINK_NODES_GRAPH",
"pair": "java-python",
"Code1": "static int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "java-python",
"Code1": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"Code2": "def countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "java-python",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "java-python",
"Code1": "static int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n",
"Code2": "def countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "java-python",
"Code1": "boolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nboolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-LINEAR_SEARCH",
"pair": "java-python",
"Code1": "public static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "java-python",
"Code1": "static boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"Code2": "def check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "java-python",
"Code1": "static int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"Code2": "def binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "java-python-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "java-python",
"Code1": "static long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"Code2": "def countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-MIRROR_CHARACTERS_STRING",
"pair": "java-python",
"Code1": "static String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n",
"Code2": "def compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "java-python",
"Code1": "public static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"Code2": "def maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "java-python",
"Code1": "static long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"Code2": "def exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n\n"
},
{
"id": "java-python-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "java-python",
"Code1": "static int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"Code2": "def sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"Code2": "def lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "java-python",
"Code1": "static int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"Code2": "def maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "java-python",
"Code1": "static int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"Code2": "def fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "java-python",
"Code1": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "java-python",
"Code1": "static boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n",
"Code2": "def flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "java-python-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "java-python",
"Code1": "static boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"Code2": "def checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "java-python",
"Code1": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n",
"Code2": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "java-python",
"Code1": "static int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n",
"Code2": "def maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "java-python",
"Code1": "static int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"Code2": "def longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "java-python",
"Code1": "static int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"Code2": "def maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "java-python",
"Code1": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"Code2": "def maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "java-python",
"Code1": "public static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n",
"Code2": "def minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n\n"
},
{
"id": "java-python-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "java-python",
"Code1": "static void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"Code2": "def kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "java-python",
"Code1": "static void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n",
"Code2": "def spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-python-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "java-python",
"Code1": "static int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n",
"Code2": "def findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n\n"
},
{
"id": "java-python-NTH_PENTAGONAL_NUMBER",
"pair": "java-python",
"Code1": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"Code2": "def pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n\n"
},
{
"id": "java-python-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "java-python",
"Code1": "static long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"Code2": "def countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-FREQUENT_ELEMENT_ARRAY_1",
"pair": "java-python",
"Code1": "static int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n",
"Code2": "def mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "java-python",
"Code1": "static int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"Code2": "def kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "java-python",
"Code1": "static int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"Code2": "def binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n\n"
},
{
"id": "java-python-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "java-python",
"Code1": "static String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"Code2": "def firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "java-python",
"Code1": "static void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n",
"Code2": "def assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "java-python",
"Code1": "static void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "java-python",
"Code1": "static int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"Code2": "def countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "java-python",
"Code1": "static void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n",
"Code2": "def relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "java-python",
"Code1": "static int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n",
"Code2": "def findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n\n"
},
{
"id": "java-python-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "java-python",
"Code1": "static int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"Code2": "def findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n\n"
},
{
"id": "java-python-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "java-python",
"Code1": "static boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"Code2": "def isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "java-python",
"Code1": "static int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "java-python",
"Code1": "static boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n",
"Code2": "def isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "java-python",
"Code1": "static int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"Code2": "def maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n\n"
},
{
"id": "java-python-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "java-python",
"Code1": "static String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"Code2": "def decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "java-python",
"Code1": "static int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"Code2": "def minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "java-python",
"Code1": "static boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"Code2": "def isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "java-python",
"Code1": "static int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n",
"Code2": "def countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "java-python",
"Code1": "static int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n",
"Code2": "def findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "java-python",
"Code1": "static void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n",
"Code2": "def minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "java-python",
"Code1": "static void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n",
"Code2": "def constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-python-NUMBER_RECTANGLES_NM_GRID",
"pair": "java-python",
"Code1": "public static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"Code2": "def rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n\n"
},
{
"id": "java-python-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "java-python",
"Code1": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "java-python",
"Code1": "static void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "def subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "java-python",
"Code1": "static boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n",
"Code2": "def isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "java-python",
"Code1": "static int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"Code2": "def divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n\n"
},
{
"id": "java-python-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "java-python",
"Code1": "static int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"Code2": "def superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "java-python",
"Code1": "static void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "java-python",
"Code1": "public static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"Code2": "def kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "java-python",
"Code1": "static boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "java-python",
"Code1": "static boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"Code2": "def isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "java-python",
"Code1": "static int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n",
"Code2": "def longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n\n"
},
{
"id": "java-python-REVERSE_A_STRING_USING_RECURSION",
"pair": "java-python",
"Code1": "void reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n",
"Code2": "def reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-python-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "java-python",
"Code1": "static long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"Code2": "def arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "java-python",
"Code1": "static boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"Code2": "def isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "java-python",
"Code1": "static int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"Code2": "def maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "java-python",
"Code1": "static String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"Code2": "def lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "java-python",
"Code1": "public static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"Code2": "def maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-python-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "java-python",
"Code1": "static int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"Code2": "def xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n\n"
},
{
"id": "java-python-N_TH_ROOT_NUMBER",
"pair": "java-python",
"Code1": "static double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"Code2": "def nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n\n"
},
{
"id": "java-python-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "java-python",
"Code1": "static StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n",
"Code2": "def findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "java-python",
"Code1": "public static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n",
"Code2": "def subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "java-python",
"Code1": "static void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n",
"Code2": "def minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n\n"
},
{
"id": "java-python-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "java-python",
"Code1": "static int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n",
"Code2": "def findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "java-python",
"Code1": "static void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n",
"Code2": "def printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "java-python",
"Code1": "static int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "def evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "java-python",
"Code1": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n",
"Code2": "def getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n\n"
},
{
"id": "java-python-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "java-python",
"Code1": "static void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n",
"Code2": "def arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "java-python",
"Code1": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n",
"Code2": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "java-python",
"Code1": "static boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"Code2": "def areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "java-python",
"Code1": "static void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n",
"Code2": "def printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n\n"
},
{
"id": "java-python-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "java-python",
"Code1": "int countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"Code2": "def countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-python-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "java-python",
"Code1": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-python-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "java-python",
"Code1": "static int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n",
"Code2": "def calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-python",
"Code1": "static void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "java-python",
"Code1": "static void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"Code2": "def countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n\n"
},
{
"id": "java-python-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "java-python",
"Code1": "static boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"Code2": "def isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "java-python",
"Code1": "static int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"Code2": "def getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "java-python",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "java-python",
"Code1": "static int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "def minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-python-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "java-python",
"Code1": "public static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"Code2": "def containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "java-python",
"Code1": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"Code2": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "java-python",
"Code1": "public static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n",
"Code2": "def isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "java-python",
"Code1": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"Code2": "def getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "java-python",
"Code1": "static int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n",
"Code2": "def maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "java-python",
"Code1": "static int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"Code2": "def maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "java-python",
"Code1": "public static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n",
"Code2": "def checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-python-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "java-python",
"Code1": "public static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"Code2": "def nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "java-python",
"Code1": "static int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"Code2": "def countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "java-python",
"Code1": "static int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"Code2": "def selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "java-python",
"Code1": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n",
"Code2": "def productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n\n"
},
{
"id": "java-python-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "java-python",
"Code1": "static boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "java-python",
"Code1": "static int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n",
"Code2": "def cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n\n"
},
{
"id": "java-python-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "java-python",
"Code1": "static int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"Code2": "def minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "java-python",
"Code1": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"Code2": "def getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "java-python",
"Code1": "static double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"Code2": "def surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n\n"
},
{
"id": "java-python-GNOME_SORT_A_STUPID_ONE",
"pair": "java-python",
"Code1": "static void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n",
"Code2": "def gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "java-python-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "java-python",
"Code1": "public static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"Code2": "def find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n\n"
},
{
"id": "java-python-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "java-python",
"Code1": "static int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"Code2": "def countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n\n"
},
{
"id": "java-python-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "java-python",
"Code1": "static void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n",
"Code2": "def generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n\n"
},
{
"id": "java-python-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "java-python",
"Code1": "static void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n",
"Code2": "def midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "java-python",
"Code1": "static void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"Code2": "def printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "java-python-FRIENDS_PAIRING_PROBLEM",
"pair": "java-python",
"Code1": "static int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "java-python",
"Code1": "static int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"Code2": "def remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n\n"
},
{
"id": "java-python-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "java-python",
"Code1": "public static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n",
"Code2": "def findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n\n"
},
{
"id": "java-python-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "java-python",
"Code1": "static int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n",
"Code2": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-python-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "java-python",
"Code1": "static int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"Code2": "def maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "java-python",
"Code1": "static void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"Code2": "def printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "java-python",
"Code1": "static boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n",
"Code2": "def checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "java-python",
"Code1": "static double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n",
"Code2": "def vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "java-python",
"Code1": "static int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-BINARY_SEARCH",
"pair": "java-python",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "java-python",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "java-python",
"Code1": "static long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"Code2": "def answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "java-python",
"Code1": "static int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"Code2": "def maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "java-python",
"Code1": "static int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"Code2": "def maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n\n"
},
{
"id": "java-python-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "java-python",
"Code1": "static void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n",
"Code2": "def moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n\n"
},
{
"id": "java-python-RECAMANS_SEQUENCE",
"pair": "java-python",
"Code1": "static void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n",
"Code2": "def recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "java-python",
"Code1": "static int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "java-python",
"Code1": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"Code2": "def KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n\n"
},
{
"id": "java-python-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "java-python",
"Code1": "static int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n",
"Code2": "def modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n\n"
},
{
"id": "java-python-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "java-python",
"Code1": "static int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"Code2": "def lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n\n"
},
{
"id": "java-python-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "java-python",
"Code1": "static int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"Code2": "def countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n\n"
},
{
"id": "java-python-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "java-python",
"Code1": "static int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"Code2": "def findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "java-python",
"Code1": "static void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"Code2": "def substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "java-python",
"Code1": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"Code2": "def maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n\n"
},
{
"id": "java-python-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "java-python",
"Code1": "static String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n",
"Code2": "def longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n\n"
},
{
"id": "java-python-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "java-python",
"Code1": "static boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "java-python",
"Code1": "public static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"Code2": "def calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n\n"
},
{
"id": "java-python-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "java-python",
"Code1": "static void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n",
"Code2": "def rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "java-python",
"Code1": "public static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n",
"Code2": "def antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "java-python",
"Code1": "static void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "java-python",
"Code1": "static int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "def findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "java-python",
"Code1": "static int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"Code2": "def Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n\n"
},
{
"id": "java-python-BUBBLE_SORT",
"pair": "java-python",
"Code1": "void bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n",
"Code2": "def bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n\n"
},
{
"id": "java-python-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "java-python",
"Code1": "static int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"Code2": "def superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "java-python",
"Code1": "static int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"Code2": "def countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "java-python",
"Code1": "static int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"Code2": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "java-python",
"Code1": "static int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"Code2": "def minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "java-python",
"Code1": "public static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n",
"Code2": "def kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "java-python",
"Code1": "static int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"Code2": "def minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-python-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "java-python",
"Code1": "static String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "def reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-python-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "java-python",
"Code1": "static int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "def minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "java-python",
"Code1": "public static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"Code2": "def MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-python-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "java-python",
"Code1": "static void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n",
"Code2": "def bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "java-python",
"Code1": "static int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"Code2": "def countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"Code2": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n\n"
},
{
"id": "java-python-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "java-python",
"Code1": "static void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n",
"Code2": "def printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "java-python",
"Code1": "static int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "java-python",
"Code1": "static void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"Code2": "def pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "java-python",
"Code1": "static int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"Code2": "def minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "java-python",
"Code1": "static String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n",
"Code2": "def censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n\n"
},
{
"id": "java-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "java-python",
"Code1": "static int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-python-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "java-python",
"Code1": "static float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n",
"Code2": "def getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n\n"
},
{
"id": "java-python-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "java-python",
"Code1": "static int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"Code2": "def distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "java-python",
"Code1": "static void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n",
"Code2": "def findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n\n"
},
{
"id": "java-python-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "java-python",
"Code1": "static int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"Code2": "def lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n\n"
},
{
"id": "java-python-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "java-python",
"Code1": "static int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n",
"Code2": "def evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n\n"
},
{
"id": "java-python-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "java-python",
"Code1": "static boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n",
"Code2": "def isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n\n"
},
{
"id": "java-python-HOSOYAS_TRIANGLE",
"pair": "java-python",
"Code1": "static void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "def printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "java-python",
"Code1": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n",
"Code2": "def findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n\n"
},
{
"id": "java-python-RECURSIVE_INSERTION_SORT",
"pair": "java-python",
"Code1": "static void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"Code2": "def insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n\n"
},
{
"id": "java-python-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "java-python",
"Code1": "static int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"Code2": "def findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n\n"
},
{
"id": "java-python-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "java-python",
"Code1": "public static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n",
"Code2": "def playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "java-python",
"Code1": "static int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n",
"Code2": "def subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "java-python",
"Code1": "static boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"Code2": "def isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "java-python",
"Code1": "static double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n",
"Code2": "def largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "java-python",
"Code1": "static int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"Code2": "def getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n ",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n \n"
},
{
"id": "java-python-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "java-python",
"Code1": "public static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"Code2": "def nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "java-python",
"Code1": "static int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "def findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "java-python",
"Code1": "static int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"Code2": "def eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "java-python",
"Code1": "public static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n",
"Code2": "def count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "java-python",
"Code1": "static int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"Code2": "def findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n\n"
},
{
"id": "java-python-SHUFFLE_A_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n",
"Code2": "def randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n\n"
},
{
"id": "java-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "java-python",
"Code1": "static int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "java-python",
"Code1": "static void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n",
"Code2": "def translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n\n"
},
{
"id": "java-python-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "java-python",
"Code1": "static int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"Code2": "def maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "java-python",
"Code1": "int catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n",
"Code2": "def catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-SUM_SERIES_12_32_52_2N_12",
"pair": "java-python",
"Code1": "static int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"Code2": "def sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "java-python",
"Code1": "static double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n",
"Code2": "def minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "java-python",
"Code1": "static void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n",
"Code2": "def printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n\n"
},
{
"id": "java-python-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "java-python",
"Code1": "static int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n",
"Code2": "def largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-PASCAL_TRIANGLE",
"pair": "java-python",
"Code1": "public static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "def printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "java-python",
"Code1": "static int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"Code2": "def answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n\n"
},
{
"id": "java-python-CASSINIS_IDENTITY",
"pair": "java-python",
"Code1": "static int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n",
"Code2": "def cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n\n"
},
{
"id": "java-python-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "java-python",
"Code1": "static int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"Code2": "def compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n\n"
},
{
"id": "java-python-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "java-python",
"Code1": "static int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"Code2": "def waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n\n"
},
{
"id": "java-python-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "java-python",
"Code1": "static void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n",
"Code2": "def findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "java-python",
"Code1": "static int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"Code2": "def maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "java-python",
"Code1": "static int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "def MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "java-python",
"Code1": "static int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"Code2": "def findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n\n"
},
{
"id": "java-python-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "java-python",
"Code1": "static int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n",
"Code2": "def findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "java-python",
"Code1": "static int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n",
"Code2": "def maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n\n"
},
{
"id": "java-python-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "java-python",
"Code1": "static void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "def findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-NTH_EVEN_LENGTH_PALINDROME",
"pair": "java-python",
"Code1": "static String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n",
"Code2": "def evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "java-python",
"Code1": "int maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "java-python",
"Code1": "static int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "def possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "java-python",
"Code1": "static int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "def numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "java-python",
"Code1": "static double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"Code2": "def circumference ( r ) :\n return ( 2 * PI * r )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n\n"
},
{
"id": "java-python-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "java-python",
"Code1": "static void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n",
"Code2": "def substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "java-python",
"Code1": "static int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"Code2": "def maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "java-python",
"Code1": "public static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n",
"Code2": "def SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "java-python",
"Code1": "static int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n",
"Code2": "def fun ( n ) :\n return n & ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "java-python",
"Code1": "static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n",
"Code2": "def mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "java-python",
"Code1": "static void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "java-python",
"Code1": "static void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n",
"Code2": "def printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n\n"
},
{
"id": "java-python-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "java-python",
"Code1": "static String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n",
"Code2": "def arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "java-python",
"Code1": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"Code2": "def countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "java-python",
"Code1": "static int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"Code2": "def minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n\n"
},
{
"id": "java-python-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "java-python",
"Code1": "static String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"Code2": "def printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n\n"
},
{
"id": "java-python-ROTATE_MATRIX_ELEMENTS",
"pair": "java-python",
"Code1": "static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "def rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "java-python",
"Code1": "static int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"Code2": "def maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "java-python",
"Code1": "static double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n\n"
},
{
"id": "java-python-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "java-python",
"Code1": "static void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n",
"Code2": "def sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n\n"
},
{
"id": "java-python-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "java-python",
"Code1": "public static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"Code2": "def rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "java-python",
"Code1": "private static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"Code2": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nprivate static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "java-python",
"Code1": "static float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n",
"Code2": "def find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "java-python",
"Code1": "static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"Code2": "def waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n\n"
},
{
"id": "java-python-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "java-python",
"Code1": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"Code2": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-STERN_BROCOT_SEQUENCE",
"pair": "java-python",
"Code1": "static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n",
"Code2": "def SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-PRUFER_CODE_TREE_CREATION",
"pair": "java-python",
"Code1": "static void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n",
"Code2": "def printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "java-python",
"Code1": "static int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"Code2": "def countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "java-python-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "java-python",
"Code1": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"Code2": "def countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "java-python",
"Code1": "static int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"Code2": "def maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-python-PRINT_BRACKET_NUMBER",
"pair": "java-python",
"Code1": "static void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"Code2": "def printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "java-python",
"Code1": "static int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"Code2": "def countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "java-python",
"Code1": "static int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"Code2": "def largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "java-python",
"Code1": "static int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n",
"Code2": "def findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"Code2": "def maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "java-python",
"Code1": "public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"Code2": "def volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n\n"
},
{
"id": "java-python-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "java-python",
"Code1": "static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"Code2": "def lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_ENDLESS_POINTS",
"pair": "java-python",
"Code1": "static int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-python",
"Code1": "static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"Code2": "def NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "java-python",
"Code1": "static int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n",
"Code2": "def lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "java-python",
"Code1": "public static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n",
"Code2": "def checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n\n"
},
{
"id": "java-python-DIAGONALLY_DOMINANT_MATRIX",
"pair": "java-python",
"Code1": "static boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "java-python",
"Code1": "static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"Code2": "def transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "java-python",
"Code1": "static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"Code2": "def returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "java-python",
"Code1": "static int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"Code2": "def sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n\n"
},
{
"id": "java-python-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "java-python",
"Code1": "public static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"Code2": "def shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "java-python",
"Code1": "static long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"Code2": "def calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n\n"
},
{
"id": "java-python-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "java-python",
"Code1": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"Code2": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "java-python",
"Code1": "static void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"Code2": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n\n"
},
{
"id": "java-python-K_TH_DIGIT_RAISED_POWER_B",
"pair": "java-python",
"Code1": "public static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"Code2": "def kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "java-python",
"Code1": "public static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n",
"Code2": "def isEven ( n ) :\n return ( not ( n & 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n\n"
},
{
"id": "java-python-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "java-python",
"Code1": "static void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n",
"Code2": "def printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "java-python",
"Code1": "public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"Code2": "def checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n\n"
},
{
"id": "java-python-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "java-python",
"Code1": "static boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "java-python",
"Code1": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n",
"Code2": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "java-python-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "java-python",
"Code1": "static int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"Code2": "def maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "java-python",
"Code1": "static int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"Code2": "def findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "java-python",
"Code1": "static double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"Code2": "def seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "java-python",
"Code1": "static int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"Code2": "def countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "java-python",
"Code1": "static int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"Code2": "def getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "java-python",
"Code1": "static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"Code2": "def isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "java-python",
"Code1": "static void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n",
"Code2": "def printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "java-python",
"Code1": "static boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"Code2": "def isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "java-python",
"Code1": "static int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"Code2": "def getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos\n"
},
{
"id": "java-python-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "java-python",
"Code1": "static int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"Code2": "def minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "java-python",
"Code1": "static void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"Code2": "def rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n\n"
},
{
"id": "java-python-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "java-python",
"Code1": "static int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"Code2": "def countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n\n"
},
{
"id": "java-python-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "java-python",
"Code1": "static int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n",
"Code2": "def largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "java-python",
"Code1": "static boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n",
"Code2": "def isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "java-python",
"Code1": "static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n",
"Code2": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "java-python",
"Code1": "static int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"Code2": "def CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n\n"
},
{
"id": "java-python-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "java-python",
"Code1": "static int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"Code2": "def minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-NTH_NON_FIBONACCI_NUMBER",
"pair": "java-python",
"Code1": "static int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"Code2": "def nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "java-python",
"Code1": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"Code2": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "java-python",
"Code1": "static void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n",
"Code2": "def leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "java-python",
"Code1": "static String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"Code2": "def repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "java-python",
"Code1": "static String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"Code2": "def findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "java-python",
"Code1": "public static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"Code2": "def findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "java-python",
"Code1": "static void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "java-python",
"Code1": "static int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"Code2": "def minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n\n"
},
{
"id": "java-python-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "java-python",
"Code1": "static void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "def luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "java-python",
"Code1": "static void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n",
"Code2": "def bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "java-python",
"Code1": "static int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "java-python",
"Code1": "static void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n",
"Code2": "def modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n\n"
},
{
"id": "java-python-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "java-python",
"Code1": "static int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"Code2": "def minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "java-python",
"Code1": "static int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"Code2": "def maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "java-python",
"Code1": "static long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"Code2": "def findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "java-python",
"Code1": "static void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n",
"Code2": "def deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n\n"
},
{
"id": "java-python-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "java-python",
"Code1": "static char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n",
"Code2": "def first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "java-python",
"Code1": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n",
"Code2": "def minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n\n"
},
{
"id": "java-python-ARC_LENGTH_ANGLE",
"pair": "java-python",
"Code1": "static double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"Code2": "def arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n\n"
},
{
"id": "java-python-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "java-python",
"Code1": "static void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n",
"Code2": "def findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "java-python",
"Code1": "static boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-PRIME_NUMBERS",
"pair": "java-python",
"Code1": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"Code2": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "java-python",
"Code1": "static int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"Code2": "def findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n\n"
},
{
"id": "java-python-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "java-python",
"Code1": "static void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n",
"Code2": "def maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n\n"
},
{
"id": "java-python-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "java-python",
"Code1": "static int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"Code2": "def horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "java-python",
"Code1": "static void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"Code2": "def rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n\n"
},
{
"id": "java-python-N_BONACCI_NUMBERS_1",
"pair": "java-python",
"Code1": "static void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "def bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "java-python",
"Code1": "static int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"Code2": "def numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n\n"
},
{
"id": "java-python-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "java-python",
"Code1": "static int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"Code2": "def findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "java-python",
"Code1": "static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"Code2": "def maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n\n"
},
{
"id": "java-python-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "java-python",
"Code1": "static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"Code2": "def isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "java-python",
"Code1": "static int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"Code2": "def fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "java-python",
"Code1": "private static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"Code2": "def minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nprivate static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "java-python",
"Code1": "public static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n",
"Code2": "def amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n\n"
},
{
"id": "java-python-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "java-python",
"Code1": "static int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"Code2": "def countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n\n"
},
{
"id": "java-python-BREAK_NUMBER_THREE_PARTS",
"pair": "java-python",
"Code1": "static long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"Code2": "def count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "java-python",
"Code1": "static double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n",
"Code2": "def sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n\n"
},
{
"id": "java-python-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "java-python",
"Code1": "static void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n",
"Code2": "def findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n\n"
},
{
"id": "java-python-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "java-python",
"Code1": "static int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"Code2": "def countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-python-HEXAGONAL_NUMBER",
"pair": "java-python",
"Code1": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"Code2": "def hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "java-python",
"Code1": "static int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"Code2": "def findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "java-python",
"Code1": "static void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n",
"Code2": "def squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "java-python",
"Code1": "static int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n",
"Code2": "def count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "java-python",
"Code1": "static int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n",
"Code2": "def find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n\n"
},
{
"id": "java-python-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "java-python",
"Code1": "static int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "java-python",
"Code1": "static double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n",
"Code2": "def sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-LEONARDO_NUMBER_1",
"pair": "java-python",
"Code1": "static int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"Code2": "def leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-python-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "java-python",
"Code1": "static int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"Code2": "def countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "java-python",
"Code1": "static boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"Code2": "def check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "java-python",
"Code1": "static int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"Code2": "def evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "java-python",
"Code1": "static int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-python-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "java-python",
"Code1": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "java-python",
"Code1": "static char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n",
"Code2": "def getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "java-python",
"Code1": "static int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"Code2": "def countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n\n"
},
{
"id": "java-python-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "java-python",
"Code1": "static void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "java-python",
"Code1": "private static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n",
"Code2": "def findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nprivate static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "java-python",
"Code1": "static int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"Code2": "def countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "java-python",
"Code1": "static int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"Code2": "def intersection ( n ) :\n return n * ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "java-python",
"Code1": "static int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "java-python",
"Code1": "static int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"Code2": "def smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n\n"
},
{
"id": "java-python-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "java-python",
"Code1": "public static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"Code2": "def maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "java-python",
"Code1": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "java-python",
"Code1": "static int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n",
"Code2": "def longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n\n"
},
{
"id": "java-python-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "java-python",
"Code1": "static boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"Code2": "def isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "java-python",
"Code1": "static int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"Code2": "def computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "java-python",
"Code1": "static int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"Code2": "def minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-NEXT_POWER_OF_2_1",
"pair": "java-python",
"Code1": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "java-python-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "java-python",
"Code1": "static int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n",
"Code2": "def getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n\n"
},
{
"id": "java-python-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "java-python",
"Code1": "static int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"Code2": "def numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-python-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "java-python",
"Code1": "static boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"Code2": "def check ( n ) :\n return 1162261467 % n == 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n\n"
},
{
"id": "java-python-NEWMAN_CONWAY_SEQUENCE",
"pair": "java-python",
"Code1": "static int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"Code2": "def sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "java-python",
"Code1": "static void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"Code2": "def generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "java-python",
"Code1": "int countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n",
"Code2": "def countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n\n"
},
{
"id": "java-python-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "java-python",
"Code1": "static int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n",
"Code2": "def findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-LEONARDO_NUMBER",
"pair": "java-python",
"Code1": "static int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n",
"Code2": "def leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "java-python",
"Code1": "static int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"Code2": "def findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n\n"
},
{
"id": "java-python-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "java-python",
"Code1": "static boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"Code2": "def HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n\n"
},
{
"id": "java-python-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "java-python",
"Code1": "static int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n",
"Code2": "def sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "java-python",
"Code1": "static void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "java-python",
"Code1": "static int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n",
"Code2": "def countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "java-python",
"Code1": "static int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"Code2": "def countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n\n"
},
{
"id": "java-python-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "java-python",
"Code1": "static void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "def printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-FLOOR_IN_A_SORTED_ARRAY",
"pair": "java-python",
"Code1": "static int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"Code2": "def floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "java-python",
"Code1": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n\n"
},
{
"id": "java-python-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "java-python",
"Code1": "static void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n",
"Code2": "def printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "java-python",
"Code1": "static void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "def longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "java-python",
"Code1": "static int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"Code2": "def minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n\n"
},
{
"id": "java-python-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "java-python",
"Code1": "static int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"Code2": "def breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "java-python",
"Code1": "static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"Code2": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "java-python",
"Code1": "static void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n",
"Code2": "def alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "java-python",
"Code1": "static void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n",
"Code2": "def subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "java-python",
"Code1": "static int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"Code2": "def maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n\n"
},
{
"id": "java-python-DICE_THROW_PROBLEM",
"pair": "java-python",
"Code1": "public static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n",
"Code2": "def findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n\n"
},
{
"id": "java-python-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "java-python",
"Code1": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n",
"Code2": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "java-python",
"Code1": "static int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"Code2": "def findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-TILING_WITH_DOMINOES",
"pair": "java-python",
"Code1": "static int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"Code2": "def countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "java-python",
"Code1": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "java-python-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "java-python",
"Code1": "static int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"Code2": "def minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "java-python",
"Code1": "static boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"Code2": "def isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "java-python",
"Code1": "static int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"Code2": "def MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-python-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "java-python",
"Code1": "static int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n",
"Code2": "def multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "java-python",
"Code1": "static int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "def countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "java-python",
"Code1": "static void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "java-python",
"Code1": "static int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"Code2": "def maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n\n"
},
{
"id": "java-python-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "java-python",
"Code1": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"Code2": "def findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-python-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "java-python",
"Code1": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"Code2": "def subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n\n"
},
{
"id": "java-python-COMMON_CHARACTERS_N_STRINGS",
"pair": "java-python",
"Code1": "public static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n",
"Code2": "def commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "java-python",
"Code1": "static boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n",
"Code2": "def canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-MAGIC_SQUARE",
"pair": "java-python",
"Code1": "static void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "java-python",
"Code1": "static int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"Code2": "def count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "java-python",
"Code1": "static int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"Code2": "def numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "java-python",
"Code1": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"Code2": "def countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-python-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "java-python",
"Code1": "static int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"Code2": "def ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n\n"
},
{
"id": "java-python-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "java-python",
"Code1": "static String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"Code2": "def decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n\n"
},
{
"id": "java-python-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "java-python",
"Code1": "static void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n",
"Code2": "def printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n\n"
},
{
"id": "java-python-PREFIX_SUM_2D_ARRAY",
"pair": "java-python",
"Code1": "public static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-EULERIAN_NUMBER",
"pair": "java-python",
"Code1": "public static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"Code2": "def eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n",
"Code2": "def findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "java-python",
"Code1": "static int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n",
"Code2": "def isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n\n"
},
{
"id": "java-python-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "java-python",
"Code1": "static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"Code2": "def longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_AREA_SQUARE",
"pair": "java-python",
"Code1": "static int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"Code2": "def areaSquare ( side ) :\n area = side * side\n return area\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n\n"
},
{
"id": "java-python-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "java-python",
"Code1": "static void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n",
"Code2": "def findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n\n"
},
{
"id": "java-python-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "java-python",
"Code1": "static int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n",
"Code2": "def lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "java-python",
"Code1": "static void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "def findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "java-python",
"Code1": "static int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"Code2": "def spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "java-python",
"Code1": "static int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"Code2": "def countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-python-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "java-python",
"Code1": "static int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n",
"Code2": "def sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "java-python",
"Code1": "static int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n",
"Code2": "def calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n\n"
},
{
"id": "java-python-DOUBLE_FACTORIAL_1",
"pair": "java-python",
"Code1": "static int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n",
"Code2": "def doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-LONGEST_COMMON_SUBSEQUENCE",
"pair": "java-python",
"Code1": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"Code2": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "java-python",
"Code1": "static int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"Code2": "def maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n\n"
},
{
"id": "java-python-TEMPLE_OFFERINGS",
"pair": "java-python",
"Code1": "static int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"Code2": "def offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "java-python",
"Code1": "static int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n",
"Code2": "def SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "java-python",
"Code1": "static String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n",
"Code2": "def constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "java-python",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "java-python",
"Code1": "static int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"Code2": "def russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-CAESAR_CIPHER",
"pair": "java-python",
"Code1": "public static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n",
"Code2": "def encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "java-python",
"Code1": "public static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n",
"Code2": "def distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n\n"
},
{
"id": "java-python-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "java-python",
"Code1": "static long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"Code2": "def evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n\n"
},
{
"id": "java-python-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "java-python",
"Code1": "static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"Code2": "def gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a\n"
},
{
"id": "java-python-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "java-python",
"Code1": "static boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n",
"Code2": "def isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-SUM_PAIRWISE_PRODUCTS",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "java-python",
"Code1": "static int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"Code2": "def binomialCoeffSum ( n ) :\n return ( 1 << n )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n\n"
},
{
"id": "java-python-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "java-python",
"Code1": "public static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"Code2": "def calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "java-python",
"Code1": "static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n",
"Code2": "def checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n\n"
},
{
"id": "java-python-PRINTING_ITEMS_01_KNAPSACK",
"pair": "java-python",
"Code1": "static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"Code2": "def printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n\n"
},
{
"id": "java-python-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "java-python",
"Code1": "static int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"Code2": "def getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"Code2": "def findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "java-python",
"Code1": "static String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n",
"Code2": "def replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n\n"
},
{
"id": "java-python-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "java-python",
"Code1": "static int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"Code2": "def discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "java-python",
"Code1": "static long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"Code2": "def maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n\n"
},
{
"id": "java-python-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "java-python",
"Code1": "static boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n",
"Code2": "def isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "java-python",
"Code1": "static int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "def numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "java-python",
"Code1": "static int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0",
"Code2": "def solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0\n"
},
{
"id": "java-python-REMAINDER_7_LARGE_NUMBERS",
"pair": "java-python",
"Code1": "static int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"Code2": "def remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n \n"
},
{
"id": "java-python-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "java-python",
"Code1": "static boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"Code2": "def isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "java-python",
"Code1": "static int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"Code2": "def getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "java-python",
"Code1": "static int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n",
"Code2": "def minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n\n"
},
{
"id": "java-python-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "java-python",
"Code1": "static int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"Code2": "def getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "java-python",
"Code1": "static int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n",
"Code2": "def findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n\n"
},
{
"id": "java-python-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "java-python",
"Code1": "static void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n",
"Code2": "def mergeTwoHalf ( A , n ) :\n A.sort ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n\n"
},
{
"id": "java-python-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "java-python",
"Code1": "static void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "java-python",
"Code1": "public static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"Code2": "def minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "java-python",
"Code1": "static void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n",
"Code2": "def possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_SLOPE_LINE",
"pair": "java-python",
"Code1": "static float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"Code2": "def slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "java-python",
"Code1": "double countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n",
"Code2": "def CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\ndouble countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "java-python",
"Code1": "static int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"Code2": "def countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "java-python",
"Code1": "static void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"Code2": "def findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "java-python",
"Code1": "static String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"Code2": "def lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "java-python",
"Code1": "public static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n",
"Code2": "def maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "java-python",
"Code1": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"Code2": "def countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "java-python",
"Code1": "static int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n",
"Code2": "def findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n\n"
},
{
"id": "java-python-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "java-python",
"Code1": "static long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n",
"Code2": "def yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"Code2": "def maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "java-python",
"Code1": "static int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"Code2": "def maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n",
"Code2": "def lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n\n"
},
{
"id": "java-python-PETERSON_GRAPH",
"pair": "java-python",
"Code1": "static boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n",
"Code2": "def findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "java-python",
"Code1": "static boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n",
"Code2": "def checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "java-python",
"Code1": "static void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"Code2": "def generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n\n"
},
{
"id": "java-python-RECURSIVE_FUNCTIONS",
"pair": "java-python",
"Code1": "static void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"Code2": "def tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n\n"
},
{
"id": "java-python-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "java-python",
"Code1": "static int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "def findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "java-python",
"Code1": "static String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n",
"Code2": "def minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "java-python",
"Code1": "static int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"Code2": "def findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "java-python",
"Code1": "static int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"Code2": "def octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MISSING_NUMBER",
"pair": "java-python",
"Code1": "static int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"Code2": "def getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n\n"
},
{
"id": "java-python-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "java-python",
"Code1": "static void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n",
"Code2": "def printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n\n"
},
{
"id": "java-python-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "java-python",
"Code1": "static boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"Code2": "def isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "java-python",
"Code1": "static void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n",
"Code2": "def fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n\n"
},
{
"id": "java-python-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "java-python",
"Code1": "public static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n",
"Code2": "def findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-python-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "java-python",
"Code1": "public static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n",
"Code2": "def sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "java-python",
"Code1": "static int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "java-python",
"Code1": "static int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"Code2": "def count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n\n"
},
{
"id": "java-python-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "java-python",
"Code1": "static int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"Code2": "def maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"Code2": "def findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "java-python",
"Code1": "static boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n",
"Code2": "def isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n\n"
},
{
"id": "java-python-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "java-python",
"Code1": "static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"Code2": "def getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n\n"
},
{
"id": "java-python-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "java-python",
"Code1": "static int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"Code2": "def countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-JUMP_SEARCH",
"pair": "java-python",
"Code1": "public static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"Code2": "def jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_X_Y_SATISFYING_AX_N",
"pair": "java-python",
"Code1": "static void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n",
"Code2": "def solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n\n"
},
{
"id": "java-python-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "java-python",
"Code1": "static String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"Code2": "def longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "java-python",
"Code1": "static void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n",
"Code2": "def sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "java-python",
"Code1": "boolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"Code2": "def canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nboolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "java-python",
"Code1": "static int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "java-python",
"Code1": "static void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"Code2": "def printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-python-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "java-python",
"Code1": "public static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n",
"Code2": "def sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n\n"
},
{
"id": "java-python-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "java-python",
"Code1": "static int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n",
"Code2": "def find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "java-python",
"Code1": "static char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "java-python",
"Code1": "static int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n",
"Code2": "def solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "java-python",
"Code1": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"Code2": "def Circumference ( a ) :\n return ( 4 * a )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint Circumference ( int a ) {\n return 4 * a ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "java-python",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"Code2": "def numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n\n"
},
{
"id": "java-python-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "java-python",
"Code1": "static void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n",
"Code2": "def pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "java-python",
"Code1": "static int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n",
"Code2": "def pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n\n"
},
{
"id": "java-python-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "java-python",
"Code1": "public static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"Code2": "def splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "java-python",
"Code1": "static int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"Code2": "def smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n\n"
},
{
"id": "java-python-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "java-python",
"Code1": "static int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"Code2": "def winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n\n"
},
{
"id": "java-python-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "java-python",
"Code1": "static Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"Code2": "def divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "java-python",
"Code1": "static int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"Code2": "def countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "java-python",
"Code1": "static void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n",
"Code2": "def CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n\n"
},
{
"id": "java-python-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "java-python",
"Code1": "static int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"Code2": "def snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit\n"
},
{
"id": "java-python-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "java-python",
"Code1": "static boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"Code2": "def isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"Code2": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "java-python",
"Code1": "static int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n\n"
},
{
"id": "java-python-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "java-python",
"Code1": "static void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n",
"Code2": "def countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n\n"
},
{
"id": "java-python-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "java-python",
"Code1": "static int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"Code2": "def nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n\n"
},
{
"id": "java-python-COCKTAIL_SORT",
"pair": "java-python",
"Code1": "void cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n",
"Code2": "def cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n\n"
},
{
"id": "java-python-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "java-python",
"Code1": "static void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"Code2": "def solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n\n"
},
{
"id": "java-python-BINARY_SEARCH_1",
"pair": "java-python",
"Code1": "int binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_XOR_VALUE_PAIR",
"pair": "java-python",
"Code1": "static int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"Code2": "def minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "java-python",
"Code1": "public static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "def sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "java-python",
"Code1": "static char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n",
"Code2": "def first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "java-python",
"Code1": "static int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"Code2": "def maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n\n"
},
{
"id": "java-python-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "java-python",
"Code1": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"Code2": "def equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "java-python",
"Code1": "static double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"Code2": "def procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n\n"
},
{
"id": "java-python-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "java-python",
"Code1": "static void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n",
"Code2": "def rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "java-python",
"Code1": "static void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n",
"Code2": "def greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "java-python",
"Code1": "static int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"Code2": "def isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-python-LONGEST_COMMON_SUBSTRING",
"pair": "java-python",
"Code1": "static int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"Code2": "def LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "java-python",
"Code1": "static int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"Code2": "def maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIBONACCI_MODULO_P",
"pair": "java-python",
"Code1": "static int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"Code2": "def findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n\n"
},
{
"id": "java-python-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "java-python",
"Code1": "static void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"Code2": "def reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n\n"
},
{
"id": "java-python-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "java-python",
"Code1": "static int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n",
"Code2": "def longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n\n"
},
{
"id": "java-python-SUM_FIBONACCI_NUMBERS",
"pair": "java-python",
"Code1": "static int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"Code2": "def calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n\n"
},
{
"id": "java-python-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "java-python",
"Code1": "int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "def shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "java-python",
"Code1": "static int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"Code2": "def sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "java-python",
"Code1": "static void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"Code2": "def constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "java-python",
"Code1": "static int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n",
"Code2": "def patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n\n"
},
{
"id": "java-python-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "java-python",
"Code1": "public static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"Code2": "def findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n\n"
},
{
"id": "java-python-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "java-python",
"Code1": "static void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n",
"Code2": "def parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "java-python",
"Code1": "static int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"Code2": "def minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "java-python",
"Code1": "static void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n",
"Code2": "def longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "java-python",
"Code1": "static int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"Code2": "def pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n\n"
},
{
"id": "java-python-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "java-python",
"Code1": "public static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"Code2": "def middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n\n"
},
{
"id": "java-python-NEXT_POWER_OF_2",
"pair": "java-python",
"Code1": "static int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "java-python",
"Code1": "static int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"Code2": "def maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n\n"
},
{
"id": "java-python-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "java-python",
"Code1": "static void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n",
"Code2": "def reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n\n"
},
{
"id": "java-python-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "java-python",
"Code1": "public static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n",
"Code2": "def nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n\n"
},
{
"id": "java-python-SUM_BINOMIAL_COEFFICIENTS",
"pair": "java-python",
"Code1": "static int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"Code2": "def binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "java-python",
"Code1": "public static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"Code2": "def isEven ( n ) :\n return ( n % 2 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "java-python",
"Code1": "static int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"Code2": "def binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "java-python",
"Code1": "static void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n",
"Code2": "def MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n\n"
},
{
"id": "java-python-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "java-python",
"Code1": "static boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n",
"Code2": "def isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n\n"
},
{
"id": "java-python-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "java-python",
"Code1": "static int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"Code2": "def countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "java-python",
"Code1": "static boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "def isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "java-python",
"Code1": "static void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n",
"Code2": "def decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n\n"
},
{
"id": "java-python-FRIENDS_PAIRING_PROBLEM_1",
"pair": "java-python",
"Code1": "static int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"Code2": "def countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "java-python",
"Code1": "static int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"Code2": "def maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "java-python",
"Code1": "static int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"Code2": "def countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n\n"
},
{
"id": "java-python-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "java-python",
"Code1": "static boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"Code2": "def checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "java-python",
"Code1": "static int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"Code2": "def countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "java-python",
"Code1": "static int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "java-python",
"Code1": "static int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n",
"Code2": "def lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "java-python",
"Code1": "static int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n",
"Code2": "def minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "java-python",
"Code1": "static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"Code2": "def minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n\n"
},
{
"id": "java-python-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "java-python",
"Code1": "static void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n",
"Code2": "def carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "java-python",
"Code1": "public static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"Code2": "def sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "java-python",
"Code1": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n",
"Code2": "def findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "java-python",
"Code1": "static int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "java-python",
"Code1": "static void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"Code2": "def segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n\n"
},
{
"id": "java-python-MERGING_INTERVALS",
"pair": "java-python",
"Code1": "public static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n",
"Code2": "def mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "java-python",
"Code1": "static float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n",
"Code2": "def correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "java-python",
"Code1": "static int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"Code2": "def findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n \n"
},
{
"id": "java-python-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "java-python",
"Code1": "static int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"Code2": "def minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "java-python",
"Code1": "static int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"Code2": "def floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "java-python",
"Code1": "static boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"Code2": "def isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "java-python",
"Code1": "static void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"Code2": "def printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "java-python",
"Code1": "static int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"Code2": "def minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n\n"
},
{
"id": "java-python-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "java-python",
"Code1": "static int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "java-python",
"Code1": "static boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n",
"Code2": "def isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "java-python",
"Code1": "static int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"Code2": "def maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "java-python",
"Code1": "static int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"Code2": "def findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "java-python",
"Code1": "static int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"Code2": "def rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n\n"
},
{
"id": "java-python-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "java-python",
"Code1": "static int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"Code2": "def assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n \n"
},
{
"id": "java-python-TRIANGULAR_NUMBERS",
"pair": "java-python",
"Code1": "static boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"Code2": "def isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-PANGRAM_CHECKING",
"pair": "java-python",
"Code1": "public static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"Code2": "def checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n\n"
},
{
"id": "java-python-INTERPOLATION_SEARCH",
"pair": "java-python",
"Code1": "static int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"Code2": "def interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FITTING_SHELVES_PROBLEM",
"pair": "java-python",
"Code1": "static void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n",
"Code2": "def minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n\n"
},
{
"id": "java-python-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "java-python",
"Code1": "static int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n\n"
},
{
"id": "java-python-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "java-python",
"Code1": "public static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"Code2": "def kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "java-python",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n\n"
},
{
"id": "java-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "java-python",
"Code1": "static boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "java-python",
"Code1": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "java-python",
"Code1": "int findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"Code2": "def findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n \n"
},
{
"id": "java-python-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "java-python",
"Code1": "static int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n",
"Code2": "def kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n\n"
},
{
"id": "java-python-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "java-python",
"Code1": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"Code2": "def findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n\n"
},
{
"id": "java-python-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "java-python",
"Code1": "static int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"Code2": "def kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "java-python",
"Code1": "static void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "def printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "java-python",
"Code1": "public void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n",
"Code2": "def decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n\n"
},
{
"id": "java-python-SUPER_PRIME",
"pair": "java-python",
"Code1": "static void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"Code2": "def SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n\n"
},
{
"id": "java-python-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "java-python",
"Code1": "static int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"Code2": "def abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "java-python",
"Code1": "static int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n",
"Code2": "def countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "java-python",
"Code1": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"Code2": "def findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "java-python",
"Code1": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"Code2": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "java-python",
"Code1": "static int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"Code2": "def minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n\n"
},
{
"id": "java-python-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "java-python",
"Code1": "public static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"Code2": "def findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n\n"
},
{
"id": "java-python-MARKOV_MATRIX",
"pair": "java-python",
"Code1": "static boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"Code2": "def checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "java-python",
"Code1": "static int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"Code2": "def insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "java-python",
"Code1": "static void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"Code2": "def recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "java-python",
"Code1": "boolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"Code2": "def areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nboolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "java-python",
"Code1": "static double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"Code2": "def findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n\n"
},
{
"id": "java-python-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "java-python",
"Code1": "public static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"Code2": "def sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "java-python",
"Code1": "static int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n",
"Code2": "def findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_MISSING_NUMBER_1",
"pair": "java-python",
"Code1": "static int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"Code2": "def getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n\n"
},
{
"id": "java-python-NEXT_POWER_OF_2_2",
"pair": "java-python",
"Code1": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "java-python",
"Code1": "static void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"Code2": "def add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n\n"
},
{
"id": "java-python-ENTRINGER_NUMBER_1",
"pair": "java-python",
"Code1": "static int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n",
"Code2": "def zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "java-python",
"Code1": "static int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"Code2": "def eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n\n"
},
{
"id": "java-python-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "java-python",
"Code1": "public static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n",
"Code2": "def noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n\n"
},
{
"id": "java-python-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "java-python",
"Code1": "static int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"Code2": "def maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "java-python",
"Code1": "static int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"Code2": "def minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n\n"
},
{
"id": "java-python-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "java-python",
"Code1": "static boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n",
"Code2": "def isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-HARDY_RAMANUJAN_THEOREM",
"pair": "java-python",
"Code1": "static int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"Code2": "def exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "java-python",
"Code1": "static void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n",
"Code2": "def query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "java-python",
"Code1": "static int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"Code2": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n\n"
},
{
"id": "java-python-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "java-python",
"Code1": "static void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n",
"Code2": "def findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "java-python",
"Code1": "int countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"Code2": "def countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "java-python",
"Code1": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n",
"Code2": "def countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "java-python",
"Code1": "static void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n",
"Code2": "def print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n\n"
},
{
"id": "java-python-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "java-python",
"Code1": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"Code2": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n\n"
},
{
"id": "java-python-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "java-python",
"Code1": "static int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"Code2": "def findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "java-python",
"Code1": "static void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n",
"Code2": "def printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "java-python",
"Code1": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"Code2": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-RECURSION",
"pair": "java-python",
"Code1": "static void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n",
"Code2": "def printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n\n"
},
{
"id": "java-python-SHIFT_MATRIX_ELEMENTS_K",
"pair": "java-python",
"Code1": "static void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n",
"Code2": "def shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n\n"
},
{
"id": "java-python-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "java-python",
"Code1": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"Code2": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "java-python",
"Code1": "static void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n",
"Code2": "def findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "java-python",
"Code1": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n",
"Code2": "def findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n\n"
},
{
"id": "java-python-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "java-python",
"Code1": "static boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"Code2": "def squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "java-python",
"Code1": "static int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "java-python",
"Code1": "static int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"Code2": "def maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n\n"
},
{
"id": "java-python-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "java-python",
"Code1": "static void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "def smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "java-python",
"Code1": "static void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n",
"Code2": "def findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "java-python",
"Code1": "static int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n",
"Code2": "def minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "java-python",
"Code1": "static int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"Code2": "def singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n\n"
},
{
"id": "java-python-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "java-python",
"Code1": "static int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"Code2": "def countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "java-python",
"Code1": "static void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n",
"Code2": "def findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n\n"
},
{
"id": "java-python-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "java-python",
"Code1": "static boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n",
"Code2": "def isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "java-python",
"Code1": "static void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n",
"Code2": "def sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n\n"
},
{
"id": "java-python-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "java-python",
"Code1": "static void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "java-python",
"Code1": "static int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n",
"Code2": "def findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n\n"
},
{
"id": "java-python-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "java-python",
"Code1": "static void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n",
"Code2": "def printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n\n"
},
{
"id": "java-python-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "java-python",
"Code1": "static String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n",
"Code2": "def simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n\n"
},
{
"id": "java-python-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "java-python",
"Code1": "static double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n",
"Code2": "def vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n\n"
},
{
"id": "java-python-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "java-python",
"Code1": "static int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"Code2": "def countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "java-python",
"Code1": "static int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n",
"Code2": "def sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "java-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n\n"
},
{
"id": "java-python-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "java-python",
"Code1": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"Code2": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "java-python",
"Code1": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n",
"Code2": "def isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-MAJORITY_ELEMENT_1",
"pair": "java-python",
"Code1": "private static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n",
"Code2": "def findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nprivate static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "java-python",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "java-python",
"Code1": "static void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n",
"Code2": "def replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "java-python",
"Code1": "public static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n",
"Code2": "def findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_SUBSTRINGS_STRING",
"pair": "java-python",
"Code1": "static int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"Code2": "def countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n\n"
},
{
"id": "java-python-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "java-python",
"Code1": "static int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"Code2": "def countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "java-python",
"Code1": "static int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n",
"Code2": "def maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n\n"
},
{
"id": "java-python-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "java-python",
"Code1": "static int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"Code2": "def countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PATH_SUM_MATRIX",
"pair": "java-python",
"Code1": "static int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n",
"Code2": "def findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"Code2": "def checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "java-python",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "java-python",
"Code1": "static void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n",
"Code2": "def swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "java-python",
"Code1": "static int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"Code2": "def find_Area ( r ) :\n return ( 2 * r * r )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "java-python",
"Code1": "static boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"Code2": "def isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n\n"
},
{
"id": "java-python-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "java-python",
"Code1": "static void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n",
"Code2": "def countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "java-python",
"Code1": "static void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n",
"Code2": "def zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n\n"
},
{
"id": "java-python-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "java-python",
"Code1": "static int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"Code2": "def countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "java-python",
"Code1": "static boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "java-python",
"Code1": "static boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"Code2": "def isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "java-python",
"Code1": "static boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"Code2": "def isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n\n"
},
{
"id": "java-python-KNAPSACK_PROBLEM",
"pair": "java-python",
"Code1": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"Code2": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "java-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "java-python",
"Code1": "static int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"Code2": "def findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n\n"
},
{
"id": "java-python-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "java-python",
"Code1": "static int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"Code2": "def breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "java-python",
"Code1": "static void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n",
"Code2": "def decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n\n"
},
{
"id": "java-python-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "java-python",
"Code1": "static int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"Code2": "def gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n\n"
},
{
"id": "java-python-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "java-python",
"Code1": "static boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"Code2": "def oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "java-python",
"Code1": "static boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "java-python",
"Code1": "static void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n",
"Code2": "def strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "java-python",
"Code1": "static void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n",
"Code2": "def evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "java-python",
"Code1": "static Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"Code2": "def isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n\n"
},
{
"id": "java-python-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "java-python",
"Code1": "static boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n",
"Code2": "def findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "java-python",
"Code1": "static int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"Code2": "def countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n\n"
},
{
"id": "java-python-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "java-python",
"Code1": "static void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n",
"Code2": "def findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n\n"
},
{
"id": "java-python-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "java-python",
"Code1": "static void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n",
"Code2": "def findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n\n"
},
{
"id": "java-python-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "java-python",
"Code1": "static void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"Code2": "def findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "java-python",
"Code1": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n",
"Code2": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n\n"
},
{
"id": "java-python-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "java-python",
"Code1": "public static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"Code2": "def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "java-python",
"Code1": "static int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"Code2": "def solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n\n"
},
{
"id": "java-python-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "java-python",
"Code1": "static int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"Code2": "def firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n\n"
},
{
"id": "java-python-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "java-python",
"Code1": "static int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"Code2": "def countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n\n"
},
{
"id": "java-python-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "java-python",
"Code1": "static void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"Code2": "def sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n\n"
},
{
"id": "java-python-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "java-python",
"Code1": "static boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"Code2": "def canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n\n"
},
{
"id": "java-python-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "java-python",
"Code1": "static void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n",
"Code2": "def minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "java-python",
"Code1": "static void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n",
"Code2": "def KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n\n"
},
{
"id": "java-python-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "java-python",
"Code1": "static void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n",
"Code2": "def swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n\n"
},
{
"id": "java-python-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "java-python",
"Code1": "public static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n",
"Code2": "def psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "java-python",
"Code1": "static int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n",
"Code2": "def findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "java-python",
"Code1": "static int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"Code2": "def minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n\n"
},
{
"id": "java-python-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "java-python",
"Code1": "static String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n",
"Code2": "def maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "java-python",
"Code1": "static int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n",
"Code2": "def findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "java-python",
"Code1": "static void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n",
"Code2": "def printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "java-python",
"Code1": "static int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"Code2": "def maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "java-python",
"Code1": "public static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"Code2": "def minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "java-python",
"Code1": "static int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n",
"Code2": "def largest ( arr , n ) :\n return max ( arr )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "java-python",
"Code1": "static float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"Code2": "def exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n\n"
},
{
"id": "java-python-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "java-python",
"Code1": "static int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "def firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "java-python",
"Code1": "static int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"Code2": "def maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "java-python",
"Code1": "public static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n",
"Code2": "def maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n\n"
},
{
"id": "java-python-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "java-python",
"Code1": "static int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"Code2": "def countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n\n"
},
{
"id": "java-python-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "java-python",
"Code1": "static int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "java-python",
"Code1": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n",
"Code2": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-SUM_FACTORS_NUMBER",
"pair": "java-python",
"Code1": "static int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"Code2": "def divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n\n"
},
{
"id": "java-python-ROTATE_MATRIX_180_DEGREE",
"pair": "java-python",
"Code1": "static void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"Code2": "def rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n\n"
},
{
"id": "java-python-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "java-python",
"Code1": "static void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n",
"Code2": "def printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "java-python",
"Code1": "static int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"Code2": "def countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "java-python",
"Code1": "static double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n",
"Code2": "def areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n\n"
},
{
"id": "java-python-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "java-python",
"Code1": "static int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"Code2": "def findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n\n"
},
{
"id": "java-python-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "java-python",
"Code1": "static void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n",
"Code2": "def printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n\n"
},
{
"id": "java-python-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "java-python",
"Code1": "static int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n",
"Code2": "def numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "java-python",
"Code1": "static int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"Code2": "def isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n\n"
},
{
"id": "java-python-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "java-python",
"Code1": "static int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"Code2": "def sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "java-python",
"Code1": "static int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "java-python",
"Code1": "static int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"Code2": "def search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n\n"
},
{
"id": "java-python-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "java-python",
"Code1": "static long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"Code2": "def exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n\n"
},
{
"id": "java-python-DIVISIBILITY_CHECK",
"pair": "java-python",
"Code1": "static void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n",
"Code2": "def divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n\n"
},
{
"id": "java-python-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "java-python",
"Code1": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n",
"Code2": "def printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n\n"
},
{
"id": "java-python-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "java-python",
"Code1": "static int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"Code2": "def minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n\n"
},
{
"id": "java-python-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "java-python",
"Code1": "static int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n",
"Code2": "def height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n\n"
},
{
"id": "java-python-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "java-python",
"Code1": "static boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n",
"Code2": "def checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n\n"
},
{
"id": "java-python-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "java-python",
"Code1": "static void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n",
"Code2": "def removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n\n"
},
{
"id": "java-python-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "java-python",
"Code1": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"Code2": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n\n"
},
{
"id": "java-python-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "java-python",
"Code1": "public static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"Code2": "def longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n\n"
},
{
"id": "java-python-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "java-python",
"Code1": "static int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"Code2": "def addOne ( x ) :\n return ( - ( ~ x ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n\n"
},
{
"id": "java-python-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "java-python",
"Code1": "static int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"Code2": "def getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n\n"
},
{
"id": "java-python-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "java-python",
"Code1": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"Code2": "def binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nint binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "java-python",
"Code1": "static void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"Code2": "def bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n\n"
},
{
"id": "java-python-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "java-python",
"Code1": "static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"Code2": "def maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n\n"
},
{
"id": "java-python-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "java-python",
"Code1": "static void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n",
"Code2": "def lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n\n"
},
{
"id": "java-python-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "java-python",
"Code1": "static int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n",
"Code2": "def findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n\n"
},
{
"id": "java-python-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "java-python",
"Code1": "boolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"Code2": "def find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nboolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n\n"
},
{
"id": "java-python-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "java-python",
"Code1": "static void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n",
"Code2": "def KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n\n"
},
{
"id": "java-python-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "java-python",
"Code1": "public static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"Code2": "def numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\npublic static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n\n"
},
{
"id": "java-python-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "java-python",
"Code1": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n",
"Code2": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-DIVISIBILITY_BY_7",
"pair": "java-python",
"Code1": "static boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"Code2": "def isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n\n"
},
{
"id": "java-python-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "java-python",
"Code1": "static int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"Code2": "def findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n\n"
},
{
"id": "java-python-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "java-python",
"Code1": "static int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"Code2": "def findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n\n"
},
{
"id": "java-python-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "java-python",
"Code1": "static int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"Code2": "def recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "java-python",
"Code1": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"Code2": "def check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n\n"
},
{
"id": "java-python-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "java-python",
"Code1": "static String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n",
"Code2": "def to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n\n"
},
{
"id": "java-python-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "java-python",
"Code1": "static int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n",
"Code2": "def remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n\n"
},
{
"id": "java-python-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "java-python",
"Code1": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n",
"Code2": "def sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nvoid sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n\n"
},
{
"id": "java-python-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "java-python",
"Code1": "static String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n",
"Code2": "def getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n\n"
},
{
"id": "java-python-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "java-python",
"Code1": "static boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"Code2": "def isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n\n"
},
{
"id": "java-python-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "java-python",
"Code1": "static void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n",
"Code2": "def center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n\n"
},
{
"id": "java-python-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "java-python",
"Code1": "static void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n",
"Code2": "def findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n\n"
},
{
"id": "java-python-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "java-python",
"Code1": "static long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"Code2": "def mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n\n"
},
{
"id": "java-python-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "java-python",
"Code1": "static String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"Code2": "def Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n\n"
},
{
"id": "java-python-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "java-python",
"Code1": "static int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"Code2": "def minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n\n"
},
{
"id": "java-python-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "java-python",
"Code1": "static int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n",
"Code2": "def findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n\n"
},
{
"id": "java-python-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "java-python",
"Code1": "static char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n",
"Code2": "def getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n\n"
},
{
"id": "java-python-SUM_TWO_LARGE_NUMBERS",
"pair": "java-python",
"Code1": "static String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n",
"Code2": "def findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n\n"
},
{
"id": "java-python-NEXT_GREATER_ELEMENT",
"pair": "java-python",
"Code1": "static void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n",
"Code2": "def printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n",
"instruction": "Translate the given code from java to python. The input Code is marked with and .",
"input": "\nstatic void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n\n"
},
{
"id": "python-cpp-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n",
"Code2": "void printPairs ( int arr [ ] , int n ) {\n vector < int > v ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) v . push_back ( abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n sort ( v . begin ( ) , v . end ( ) ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) cout << - v [ i ] << \" \" << v [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "python-cpp",
"Code1": "def findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n",
"Code2": "float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n cout << \"Not a valid trianglen\" ;\n exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n\n"
},
{
"id": "python-cpp-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "python-cpp",
"Code1": "def isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n",
"Code2": "bool isMajority ( int a [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ a [ i ] ] ++ ;\n for ( auto x : mp ) if ( x . second >= n / 2 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n\n"
},
{
"id": "python-cpp-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "python-cpp",
"Code1": "def nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n",
"Code2": "int nonDecNums ( int n ) {\n int a [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n\n"
},
{
"id": "python-cpp-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-cpp",
"Code1": "def firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-cpp-NON_REPEATING_ELEMENT_1",
"pair": "python-cpp",
"Code1": "def firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n",
"Code2": "int firstNonRepeating ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp [ arr [ i ] ] == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-cpp-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "python-cpp",
"Code1": "def distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n",
"Code2": "bool distributingBalls ( int k , int n , string str ) {\n int a [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str [ i ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-BREAK_NUMBER_THREE_PARTS_1",
"pair": "python-cpp",
"Code1": "def count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n",
"Code2": "ll count_of_ways ( ll n ) {\n ll count ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n",
"Code2": "int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = max ( res , next_val ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n\n"
},
{
"id": "python-cpp-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "python-cpp",
"Code1": "def calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n",
"Code2": "int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) printf ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = 0.5 * ( h * 60 + m ) ;\n int minute_angle = 6 * m ;\n int angle = abs ( hour_angle - minute_angle ) ;\n angle = min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n\n"
},
{
"id": "python-cpp-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "python-cpp",
"Code1": "def smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n",
"Code2": "int smallest ( int x , int y , int z ) {\n if ( ! ( y / x ) ) return ( ! ( y / z ) ) ? y : z ;\n return ( ! ( x / z ) ) ? x : z ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n\n"
},
{
"id": "python-cpp-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "python-cpp",
"Code1": "def findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n",
"Code2": "char findExtraCharcter ( string strA , string strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA [ i ] ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB [ i ] ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n\n"
},
{
"id": "python-cpp-RECAMANS_SEQUENCE_1",
"pair": "python-cpp",
"Code1": "def recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n",
"Code2": "void recaman ( int n ) {\n if ( n <= 0 ) return ;\n printf ( \"%d, \" , 0 ) ;\n unordered_set < int > s ;\n s . insert ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ;\n s . insert ( curr ) ;\n printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "python-cpp",
"Code1": "def findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n",
"Code2": "int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = min ( ans , 2 * abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "python-cpp",
"Code1": "def countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n",
"Code2": "void countSubsequence ( char s [ ] , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s [ i ] ) {\n case 'G' : cntG ++ ;\n result += C ;\n break ;\n case 'F' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n cout << result << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n\n"
},
{
"id": "python-cpp-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "python-cpp",
"Code1": "def maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n",
"Code2": "int maxdiff ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ;\n else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n\n"
},
{
"id": "python-cpp-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "python-cpp",
"Code1": "def areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n",
"Code2": "bool areEqual ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n if ( n != m ) return false ;\n sort ( arr1 , arr1 + n ) ;\n sort ( arr2 , arr2 + m ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n\n"
},
{
"id": "python-cpp-FRIENDS_PAIRING_PROBLEM_2",
"pair": "python-cpp",
"Code1": "def countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n",
"Code2": "int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n\n"
},
{
"id": "python-cpp-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "python-cpp",
"Code1": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n",
"Code2": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n\n"
},
{
"id": "python-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "python-cpp",
"Code1": "def findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n",
"Code2": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str [ i + k ] - '0' ) ;\n rightsum += ( str [ i + k + length / 2 ] - '0' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n\n"
},
{
"id": "python-cpp-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "python-cpp",
"Code1": "def search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-cpp-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "python-cpp",
"Code1": "def subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "void subArray ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) cout << arr [ k ] << \" \" ;\n cout << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "python-cpp",
"Code1": "def isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n",
"Code2": "bool isSubSeqDivisible ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ 10 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n int arr [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = str [ i - 1 ] - '0' ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "python-cpp",
"Code1": "def solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n",
"Code2": "void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n\n"
},
{
"id": "python-cpp-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "python-cpp",
"Code1": "def squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n",
"Code2": "public : float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n float e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "python-cpp",
"Code1": "def CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n",
"Code2": "int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n\n"
},
{
"id": "python-cpp-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "python-cpp",
"Code1": "def multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n",
"Code2": "int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "python-cpp",
"Code1": "def prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n",
"Code2": "bool prevPermutation ( string & str ) {\n int n = str . length ( ) - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) i -- ;\n if ( i <= 0 ) return false ;\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) j ++ ;\n swap ( str [ i - 1 ] , str [ j ] ) ;\n reverse ( str . begin ( ) + i , str . end ( ) ) ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n\n"
},
{
"id": "python-cpp-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "python-cpp",
"Code1": "def polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n",
"Code2": "double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return abs ( area / 2.0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n\n"
},
{
"id": "python-cpp-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n\n"
},
{
"id": "python-cpp-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "python-cpp",
"Code1": "def chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n",
"Code2": "int chordCnt ( int A ) {\n int n = 2 * A ;\n int dpArray [ n + 1 ] = {\n 0 }\n ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n\n"
},
{
"id": "python-cpp-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "python-cpp",
"Code1": "def compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n",
"Code2": "double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n\n"
},
{
"id": "python-cpp-MAJORITY_ELEMENT",
"pair": "python-cpp",
"Code1": "def findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n",
"Code2": "void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) cout << arr [ index ] << endl ;\n else cout << \"No Majority Element\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n\n"
},
{
"id": "python-cpp-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "python-cpp",
"Code1": "def isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n",
"Code2": "bool isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n\n"
},
{
"id": "python-cpp-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "python-cpp",
"Code1": "def findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n",
"Code2": "string findSubString ( string str , string pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n int hash_pat [ no_of_chars ] = {\n 0 }\n ;\n int hash_str [ no_of_chars ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat [ i ] ] ++ ;\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str [ j ] ] ++ ;\n if ( hash_pat [ str [ j ] ] != 0 && hash_str [ str [ j ] ] <= hash_pat [ str [ j ] ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] || hash_pat [ str [ start ] ] == 0 ) {\n if ( hash_str [ str [ start ] ] > hash_pat [ str [ start ] ] ) hash_str [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n cout << \"No such window exists\" ;\n return \"\" ;\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n\n"
},
{
"id": "python-cpp-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "python-cpp",
"Code1": "def countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n",
"Code2": "int countDivisibleSubseq ( string str , int n ) {\n int len = str . length ( ) ;\n int dp [ len ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ ( str [ 0 ] - '0' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str [ i ] - '0' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str [ i ] - '0' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n\n"
},
{
"id": "python-cpp-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "python-cpp",
"Code1": "def pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n",
"Code2": "void pairs ( int arr [ ] , int n , int k ) {\n int smallest = INT_MAX ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n cout << \"Minimal Value = \" << smallest << \"\\n\" ;\n cout << \"Total Pairs = \" << count << \"\\n\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n\n"
},
{
"id": "python-cpp-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "python-cpp",
"Code1": "def nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n",
"Code2": "int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n\n"
},
{
"id": "python-cpp-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "python-cpp",
"Code1": "def shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n",
"Code2": "void shuffle ( int card [ ] , int n ) {\n srand ( time ( 0 ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + ( rand ( ) % ( 52 - i ) ) ;\n swap ( card [ i ] , card [ r ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n\n"
},
{
"id": "python-cpp-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "python-cpp",
"Code1": "def maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > presum ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n if ( presum . find ( sum ) != presum . end ( ) ) {\n max_len = max ( max_len , i - presum [ sum ] ) ;\n }\n else {\n presum [ sum ] = i ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n\n"
},
{
"id": "python-cpp-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n",
"Code2": "int maxLength ( char s [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s [ i ] == '(' && s [ i + 1 ] == ')' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s [ i ] == '(' && s [ j ] == ')' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "python-cpp",
"Code1": "def summingSeries ( n ) :\n return math.pow ( n , 2 )\n",
"Code2": "int summingSeries ( long n ) {\n return pow ( n , 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef summingSeries ( n ) :\n return math.pow ( n , 2 )\n\n"
},
{
"id": "python-cpp-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "python-cpp",
"Code1": "def isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n",
"Code2": "bool isSubsetSum ( int arr [ ] , int n , int sum ) {\n bool subset [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n\n"
},
{
"id": "python-cpp-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n",
"Code2": "int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n\n"
},
{
"id": "python-cpp-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "python-cpp",
"Code1": "def numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n",
"Code2": "int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n\n"
},
{
"id": "python-cpp-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "python-cpp",
"Code1": "def removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n",
"Code2": "int removeConsecutiveSame ( vector < string > v ) {\n stack < string > st ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v [ i ] ) ;\n else {\n string str = st . top ( ) ;\n if ( str . compare ( v [ i ] ) == 0 ) st . pop ( ) ;\n else st . push ( v [ i ] ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n\n"
},
{
"id": "python-cpp-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "python-cpp",
"Code1": "def find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n",
"Code2": "void find ( vector < string > list1 , vector < string > list2 ) {\n vector < string > res ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 [ i ] == list2 [ sum - i ] ) res . push_back ( list1 [ i ] ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) cout << res [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-NON_REPEATING_ELEMENT",
"pair": "python-cpp",
"Code1": "def firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n",
"Code2": "int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-cpp-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "python-cpp",
"Code1": "def search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n\n"
},
{
"id": "python-cpp-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "python-cpp",
"Code1": "def middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n",
"Code2": "void middlesum ( int mat [ ] [ MAX ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n cout << \"Sum of middle row = \" << row_sum << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n cout << \"Sum of middle column = \" << col_sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n\n"
},
{
"id": "python-cpp-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "python-cpp",
"Code1": "def moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n",
"Code2": "long long moduloMultiplication ( long long a , long long b , long long mod ) {\n long long res = 0 ;\n a %= mod ;\n while ( b ) {\n if ( b & 1 ) res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n\n"
},
{
"id": "python-cpp-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "python-cpp",
"Code1": "def pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n",
"Code2": "void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n printf ( \"%d %d %d\\n\" , a , b , c ) ;\n }\n m ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n\n"
},
{
"id": "python-cpp-SUM_PAIRWISE_PRODUCTS_2",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n",
"Code2": "long long int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n\n"
},
{
"id": "python-cpp-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "python-cpp",
"Code1": "def fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n",
"Code2": "int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] ) return f [ n ] ;\n int k = ( n & 1 ) ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n\n"
},
{
"id": "python-cpp-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "python-cpp",
"Code1": "def largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n",
"Code2": "int largestPower ( int n , int p ) {\n int x = 0 ;\n while ( n ) {\n n /= p ;\n x += n ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n\n"
},
{
"id": "python-cpp-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "python-cpp",
"Code1": "def isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n",
"Code2": "bool isIdentity ( int mat [ ] [ MAX ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "python-cpp",
"Code1": "def minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n",
"Code2": "int minCells ( int mat [ SIZE ] [ SIZE ] , int m , int n ) {\n int dp [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = INT_MAX ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != INT_MAX && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != INT_MAX && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != INT_MAX ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n\n"
},
{
"id": "python-cpp-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "python-cpp",
"Code1": "def arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n",
"Code2": "void arrangeString ( string str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str [ i ] == '0' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n cout << \"0\" ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n cout << \"1\" ;\n count_1 -- ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "python-cpp",
"Code1": "def getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n",
"Code2": "int getLevenstein ( string const & input ) {\n string revInput ( input . rbegin ( ) , input . rend ( ) ) ;\n int n = input . size ( ) ;\n vector < vector < int >> dp ( n + 1 , vector < int > ( n + 1 , - 1 ) ) ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input [ i - 1 ] == revInput [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( {\n dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] }\n ) ;\n }\n }\n int res = numeric_limits < int > :: max ( ) ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n -- i , ++ j ) {\n res = min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "python-cpp",
"Code1": "def carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n",
"Code2": "int carAssembly ( int a [ ] [ NUM_STATION ] , int t [ ] [ NUM_STATION ] , int * e , int * x ) {\n int T1 [ NUM_STATION ] , T2 [ NUM_STATION ] , i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n\n"
},
{
"id": "python-cpp-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "python-cpp",
"Code1": "def gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n",
"Code2": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n\n"
},
{
"id": "python-cpp-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "python-cpp",
"Code1": "def findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n",
"Code2": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n printf ( \"%d %d %d\\n\" , x , arr [ l ] , arr [ r ] ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n\n"
},
{
"id": "python-cpp-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "python-cpp",
"Code1": "def getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n",
"Code2": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < ar_size ;\n i ++ ) res = res ^ ar [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "python-cpp",
"Code1": "def maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n",
"Code2": "int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n\n"
},
{
"id": "python-cpp-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "python-cpp",
"Code1": "def printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n",
"Code2": "void printOtherSides ( int n ) {\n if ( n & 1 ) {\n if ( n == 1 ) cout << - 1 << endl ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n else {\n if ( n == 2 ) cout << - 1 << endl ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n cout << \"b = \" << b << \", c = \" << c << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n\n"
},
{
"id": "python-cpp-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "python-cpp",
"Code1": "def printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n",
"Code2": "void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n cout << \"The complete array is sorted\" ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n cout << \"The unsorted subarray which\" << \" makes the given array\" << endl << \"sorted lies between the indees \" << s << \" and \" << e ;\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n\n"
},
{
"id": "python-cpp-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "python-cpp",
"Code1": "def circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n",
"Code2": "int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n\n"
},
{
"id": "python-cpp-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "python-cpp",
"Code1": "def countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n",
"Code2": "void countDistinct ( int arr [ ] , int k , int n ) {\n map < int , int > hm ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n }\n cout << dist_count << endl ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n if ( hm [ arr [ i - k ] ] == 1 ) {\n dist_count -- ;\n }\n hm [ arr [ i - k ] ] -= 1 ;\n if ( hm [ arr [ i ] ] == 0 ) {\n dist_count ++ ;\n }\n hm [ arr [ i ] ] += 1 ;\n cout << dist_count << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "python-cpp",
"Code1": "def findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n",
"Code2": "float findArea ( float a ) {\n float area ;\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n\n"
},
{
"id": "python-cpp-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "python-cpp",
"Code1": "def countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n",
"Code2": "int countRotationsDivBy8 ( string n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n [ 0 ] - '0' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n int second = ( n [ 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n [ i ] - '0' ) * 100 + ( n [ i + 1 ] - '0' ) * 10 + ( n [ i + 2 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n [ len - 1 ] - '0' ) * 100 + ( n [ 0 ] - '0' ) * 10 + ( n [ 1 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n [ len - 2 ] - '0' ) * 100 + ( n [ len - 1 ] - '0' ) * 10 + ( n [ 0 ] - '0' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "python-cpp",
"Code1": "def lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n",
"Code2": "int lcs ( int dp [ MAX ] [ MAX ] [ MAX ] , int arr1 [ ] , int n , int arr2 [ ] , int m , int k ) {\n if ( k < 0 ) return - 1e7 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int & ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "python-cpp",
"Code1": "def editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"Code2": "int editDistDP ( string str1 , string str2 , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "python-cpp",
"Code1": "def countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n",
"Code2": "int countOps ( int A [ ] [ MAX ] , int B [ ] [ MAX ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n\n"
},
{
"id": "python-cpp-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "python-cpp",
"Code1": "def longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n",
"Code2": "void longestAlternating ( int arr [ ] , int n ) {\n int count [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n\n"
},
{
"id": "python-cpp-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "python-cpp",
"Code1": "def printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n",
"Code2": "void printDivisors ( int n ) {\n vector < int > v ;\n for ( int i = 1 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) printf ( \"%d \" , i ) ;\n else {\n printf ( \"%d \" , i ) ;\n v . push_back ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) printf ( \"%d \" , v [ i ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-cpp-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "python-cpp",
"Code1": "def isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n",
"Code2": "bool isPower ( int x , long int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n long int pow = 1 ;\n while ( pow < y ) pow *= x ;\n return ( pow == y ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n",
"Code2": "int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n\n"
},
{
"id": "python-cpp-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "python-cpp",
"Code1": "def printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n",
"Code2": "void printGrouped ( string str ) {\n int n = str . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str [ i ] - 'a' ] -- ) cout << str [ i ] ;\n count [ str [ i ] - 'a' ] = 0 ;\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n\n"
},
{
"id": "python-cpp-COUNT_SORTED_ROWS_MATRIX",
"pair": "python-cpp",
"Code1": "def sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n",
"Code2": "int sortedCount ( int mat [ ] [ MAX ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n\n"
},
{
"id": "python-cpp-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "python-cpp",
"Code1": "def countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n",
"Code2": "int countSub ( string str ) {\n vector < int > last ( MAX_CHAR , - 1 ) ;\n int n = str . length ( ) ;\n int dp [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ str [ i - 1 ] ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ str [ i - 1 ] ] ] ;\n last [ str [ i - 1 ] ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "python-cpp",
"Code1": "def findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n",
"Code2": "int findLIS ( int A [ ] , int n ) {\n unordered_map < int , int > hash ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash [ A [ 0 ] ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1 ;\n if ( LIS_size < hash [ A [ i ] ] ) {\n LIS_size = hash [ A [ i ] ] ;\n LIS_index = A [ i ] ;\n }\n }\n cout << \"LIS_size = \" << LIS_size << \"\\n\" ;\n cout << \"LIS : \" ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n cout << start << \" \" ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n\n"
},
{
"id": "python-cpp-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n",
"Code2": "void printMaxOfMin ( int arr [ ] , int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = INT_MIN ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n cout << maxOfMin << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "python-cpp",
"Code1": "def maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n",
"Code2": "int maximumZeros ( int * arr , int n , int k ) {\n int subset [ k + 1 ] [ MAX5 + 5 ] ;\n memset ( subset , - 1 , sizeof ( subset ) ) ;\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) if ( subset [ i ] [ j ] != - 1 ) subset [ i + 1 ] [ j + pw5 ] = max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) ans = max ( ans , min ( i , subset [ k ] [ i ] ) ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n\n"
},
{
"id": "python-cpp-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "python-cpp",
"Code1": "def largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n",
"Code2": "int largestSubset ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int dp [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( a [ j ] % a [ i ] == 0 ) mxm = max ( mxm , dp [ j ] ) ;\n dp [ i ] = 1 + mxm ;\n }\n return * max_element ( dp , dp + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n\n"
},
{
"id": "python-cpp-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "python-cpp",
"Code1": "def encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n",
"Code2": "char encodedChar ( string str , int k ) {\n string expand = \"\" ;\n string temp ;\n int freq = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( str [ i ] >= 'a' && str [ i ] <= 'z' ) {\n temp . push_back ( str [ i ] ) ;\n i ++ ;\n }\n while ( str [ i ] >= '1' && str [ i ] <= '9' ) {\n freq = freq * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand . append ( temp ) ;\n }\n if ( freq == 0 ) expand . append ( temp ) ;\n return expand [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n\n"
},
{
"id": "python-cpp-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n",
"Code2": "int countNum ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int count = 0 , maxm = INT_MIN , minm = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( s . find ( arr [ i ] ) == s . end ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "python-cpp",
"Code1": "def countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int ans = 0 ;\n for ( auto it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n int count = it -> second ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n\n"
},
{
"id": "python-cpp-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "python-cpp",
"Code1": "def maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n",
"Code2": "int maxDiff ( int arr [ ] , int n ) {\n int result = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n\n"
},
{
"id": "python-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "python-cpp",
"Code1": "def middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n\n"
},
{
"id": "python-cpp-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "python-cpp",
"Code1": "def countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n",
"Code2": "int countarray ( int n , int k , int x ) {\n int dp [ MAXN ] = {\n 0 }\n ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n\n"
},
{
"id": "python-cpp-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "python-cpp",
"Code1": "def nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n",
"Code2": "int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_1",
"pair": "python-cpp",
"Code1": "def fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n",
"Code2": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n\n"
},
{
"id": "python-cpp-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "python-cpp",
"Code1": "def countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n",
"Code2": "int countNums ( int n , int x , int y ) {\n vector < bool > arr ( n + 1 , false ) ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n\n"
},
{
"id": "python-cpp-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "python-cpp",
"Code1": "def countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n",
"Code2": "int countPS ( string str ) {\n int N = str . length ( ) ;\n int cps [ N + 1 ] [ N + 1 ] ;\n memset ( cps , 0 , sizeof ( cps ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( str [ i ] == str [ k ] ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n\n"
},
{
"id": "python-cpp-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "python-cpp",
"Code1": "def decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n",
"Code2": "string decimalToBinary ( double num , int k_prec ) {\n string binary = \"\" ;\n int Integral = num ;\n double fractional = num - Integral ;\n while ( Integral ) {\n int rem = Integral % 2 ;\n binary . push_back ( rem + '0' ) ;\n Integral /= 2 ;\n }\n reverse ( binary . begin ( ) , binary . end ( ) ) ;\n binary . push_back ( '.' ) ;\n while ( k_prec -- ) {\n fractional *= 2 ;\n int fract_bit = fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary . push_back ( 1 + '0' ) ;\n }\n else binary . push_back ( 0 + '0' ) ;\n }\n return binary ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "python-cpp",
"Code1": "def countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '",
"Code2": "int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ n ] [ n ] , T [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == 'F' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == 'T' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == '&' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '\n"
},
{
"id": "python-cpp-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "python-cpp",
"Code1": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n",
"Code2": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n\n"
},
{
"id": "python-cpp-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "python-cpp",
"Code1": "def longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n",
"Code2": "int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n\n"
},
{
"id": "python-cpp-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "python-cpp",
"Code1": "def maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n",
"Code2": "int maxTripletSum ( int arr [ ] , int n ) {\n int sum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n\n"
},
{
"id": "python-cpp-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "python-cpp",
"Code1": "def evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n",
"Code2": "int evaluateBoolExpr ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( s [ i + 1 ] == 'A' ) {\n if ( s [ i + 2 ] == '0' || s [ i ] == '0' ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n else if ( s [ i + 1 ] == 'B' ) {\n if ( s [ i + 2 ] == '1' || s [ i ] == '1' ) s [ i + 2 ] = '1' ;\n else s [ i + 2 ] = '0' ;\n }\n else {\n if ( s [ i + 2 ] == s [ i ] ) s [ i + 2 ] = '0' ;\n else s [ i + 2 ] = '1' ;\n }\n }\n return s [ n - 1 ] - '0' ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n\n"
},
{
"id": "python-cpp-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "python-cpp",
"Code1": "def findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n",
"Code2": "int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n\n"
},
{
"id": "python-cpp-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "python-cpp",
"Code1": "def numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n",
"Code2": "int numofAP ( int a [ ] , int n ) {\n int minarr = INT_MAX , maxarr = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = min ( minarr , a [ i ] ) ;\n maxarr = max ( maxarr , a [ i ] ) ;\n }\n int dp [ n ] , sum [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n memset ( sum , 0 , sizeof sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "python-cpp",
"Code1": "def countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n",
"Code2": "int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "python-cpp",
"Code1": "def minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n",
"Code2": "int minSwaps ( int arr [ ] , int n ) {\n pair < int , int > arrPos [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arrPos [ i ] . first = arr [ i ] ;\n arrPos [ i ] . second = i ;\n }\n sort ( arrPos , arrPos + n ) ;\n vector < bool > vis ( n , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrPos [ i ] . second == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = 1 ;\n j = arrPos [ j ] . second ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n\n"
},
{
"id": "python-cpp-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "python-cpp",
"Code1": "def spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n",
"Code2": "void spiralFill ( int m , int n , int a [ ] [ MAX ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = val ++ ;\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = val ++ ;\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = val ++ ;\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = val ++ ;\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n\n"
},
{
"id": "python-cpp-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "python-cpp",
"Code1": "def printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n",
"Code2": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = INT_MAX ;\n int res_l , res_r ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \"The closest pair is [\" << ar1 [ res_l ] << \", \" << ar2 [ res_r ] << \"] \\n\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n\n"
},
{
"id": "python-cpp-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "python-cpp",
"Code1": "def minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n",
"Code2": "int minimumBox ( int arr [ ] , int n ) {\n queue < int > q ;\n sort ( arr , arr + n ) ;\n q . push ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . front ( ) ;\n if ( arr [ i ] >= 2 * now ) q . pop ( ) ;\n q . push ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n\n"
},
{
"id": "python-cpp-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "python-cpp",
"Code1": "def findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n",
"Code2": "int findInteger ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash [ abs ( arr [ i ] ) ] -= 1 ;\n else hash [ arr [ i ] ] += 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash [ arr [ i ] ] != 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n\n"
},
{
"id": "python-cpp-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "python-cpp",
"Code1": "def convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n",
"Code2": "void convertOpposite ( string & str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) str [ i ] = str [ i ] - 32 ;\n else if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) str [ i ] = str [ i ] + 32 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n\n"
},
{
"id": "python-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "python-cpp",
"Code1": "def decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n",
"Code2": "unsigned long long int int decimalToBinary ( int N ) {\n ull B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n ull c = pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n\n"
},
{
"id": "python-cpp-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "python-cpp",
"Code1": "def findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) != s . end ( ) ) return arr [ i ] ;\n s . insert ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "python-cpp",
"Code1": "def transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n",
"Code2": "void transpose ( int A [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) swap ( A [ i ] [ j ] , A [ j ] [ i ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n\n"
},
{
"id": "python-cpp-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "python-cpp",
"Code1": "def findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n",
"Code2": "void findConsecutive ( int N ) {\n int start = 1 , end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) printf ( \"%d \" , j ) ;\n printf ( \"\\n\" ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n\n"
},
{
"id": "python-cpp-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "python-cpp",
"Code1": "def printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "void printSubsequences ( string str ) {\n int n = str . length ( ) ;\n unsigned int opsize = pow ( 2 , n - 1 ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << str [ j ] ;\n if ( counter & ( 1 << j ) ) cout << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_AREA_QUADRILATERAL",
"pair": "python-cpp",
"Code1": "def maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n",
"Code2": "double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n\n"
},
{
"id": "python-cpp-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "python-cpp",
"Code1": "def Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n",
"Code2": "int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ! ( num & ( 1 << i ) ) ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n\n"
},
{
"id": "python-cpp-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "python-cpp",
"Code1": "def printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n",
"Code2": "int printRoman ( int number ) {\n int num [ ] = {\n 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 }\n ;\n string sym [ ] = {\n \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" }\n ;\n int i = 12 ;\n while ( number > 0 ) {\n int div = number / num [ i ] ;\n number = number % num [ i ] ;\n while ( div -- ) {\n cout << sym [ i ] ;\n }\n i -- ;\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "python-cpp",
"Code1": "def isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n",
"Code2": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n\n"
},
{
"id": "python-cpp-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "python-cpp",
"Code1": "def countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n",
"Code2": "int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return floor ( log10 ( abs ( a ) ) + log10 ( abs ( b ) ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n\n"
},
{
"id": "python-cpp-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "python-cpp",
"Code1": "def CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n",
"Code2": "int countWays ( int n ) {\n int table [ n + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n\n"
},
{
"id": "python-cpp-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "python-cpp",
"Code1": "def twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n",
"Code2": "void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] & 1 ) arr [ i ] *= - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n\n"
},
{
"id": "python-cpp-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "python-cpp",
"Code1": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n",
"Code2": "int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n\n"
},
{
"id": "python-cpp-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "python-cpp",
"Code1": "def findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n",
"Code2": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n\n"
},
{
"id": "python-cpp-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "python-cpp",
"Code1": "def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n",
"Code2": "bool findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) s . insert ( a1 [ i ] ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( s . find ( sum - a2 [ i ] - a3 [ j ] ) != s . end ( ) ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n\n"
},
{
"id": "python-cpp-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "python-cpp",
"Code1": "def getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n",
"Code2": "int getOddOccurrence ( int arr [ ] , int arr_size ) {\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-cpp-PRIME_FACTORS_BIG_NUMBER",
"pair": "python-cpp",
"Code1": "def factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n",
"Code2": "void factorize ( long long n ) {\n int count = 0 ;\n while ( ! ( n % 2 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count ) cout << 2 << \" \" << count << endl ;\n for ( long long i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count ) cout << i << \" \" << count << endl ;\n }\n if ( n > 2 ) cout << n << \" \" << 1 << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n\n"
},
{
"id": "python-cpp-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "python-cpp",
"Code1": "def findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n",
"Code2": "int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n sort ( A , A + m ) ;\n sort ( B , B + n ) ;\n int a = 0 , b = 0 ;\n int result = INT_MAX ;\n while ( a < m && b < n ) {\n if ( abs ( A [ a ] - B [ b ] ) < result ) result = abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n\n"
},
{
"id": "python-cpp-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "python-cpp",
"Code1": "def check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n",
"Code2": "bool check ( string s ) {\n if ( s . size ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . size ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . size ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . size ( ) ;\n k ++ ) {\n string s1 = s . substr ( 0 , i ) ;\n string s2 = s . substr ( i , j - i ) ;\n string s3 = s . substr ( j , k - j ) ;\n string s4 = s . substr ( k , s . size ( ) - k ) ;\n if ( s1 != s2 && s1 != s3 && s1 != s4 && s2 != s3 && s2 != s4 && s3 != s4 ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "python-cpp",
"Code1": "def isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n",
"Code2": "bool isPath ( int arr [ row ] [ col ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) if ( arr [ i ] [ 0 ] != - 1 ) arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ] ;\n for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ 0 ] [ j ] != - 1 ) arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i < row ;\n i ++ ) for ( int j = 1 ;\n j < col ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ row - 1 ] [ col - 1 ] == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n\n"
},
{
"id": "python-cpp-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "python-cpp",
"Code1": "def bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n",
"Code2": "void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n swap ( arr [ i ] , arr [ j ] ) ;\n i += 2 ;\n j -= 2 ;\n }\n sort ( arr , arr + ( n + 1 ) / 2 ) ;\n sort ( arr + ( n + 1 ) / 2 , arr + n , greater < int > ( ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n\n"
},
{
"id": "python-cpp-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "python-cpp",
"Code1": "def solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n",
"Code2": "int solve ( int dp [ ] [ MAX ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) return a [ low ] * turn ;\n if ( dp [ low ] [ high ] != 0 ) return dp [ low ] [ high ] ;\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n\n"
},
{
"id": "python-cpp-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "python-cpp",
"Code1": "def direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n",
"Code2": "void direction ( ll R , ll C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n cout << \"Left\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n cout << \"Up\" << endl ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n cout << \"Down\" << endl ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n cout << \"Right\" << endl ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n\n"
},
{
"id": "python-cpp-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "python-cpp",
"Code1": "def splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n",
"Code2": "void splitString ( string str ) {\n string alpha , num , special ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( isdigit ( str [ i ] ) ) num . push_back ( str [ i ] ) ;\n else if ( ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) || ( str [ i ] >= 'a' && str [ i ] <= 'z' ) ) alpha . push_back ( str [ i ] ) ;\n else special . push_back ( str [ i ] ) ;\n }\n cout << alpha << endl ;\n cout << num << endl ;\n cout << special << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n\n"
},
{
"id": "python-cpp-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "python-cpp",
"Code1": "def binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n",
"Code2": "int binaryMedian ( int m [ ] [ MAX ] , int r , int c ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) place += upper_bound ( m [ i ] , m [ i ] + c , mid ) - m [ i ] ;\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n\n"
},
{
"id": "python-cpp-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "python-cpp",
"Code1": "def printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n",
"Code2": "void printDuplicates ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] ++ ;\n bool dup = false ;\n unordered_map < int , int > :: iterator itr ;\n for ( itr = freq . begin ( ) ;\n itr != freq . end ( ) ;\n itr ++ ) {\n if ( itr -> second > 1 ) {\n cout << itr -> first << \" \" ;\n dup = true ;\n }\n }\n if ( dup == false ) cout << \"-1\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n\n"
},
{
"id": "python-cpp-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "python-cpp",
"Code1": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n",
"Code2": "void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n cout << c << \" \" ;\n a = b ;\n b = c ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n\n"
},
{
"id": "python-cpp-SWAP_TWO_NIBBLES_BYTE",
"pair": "python-cpp",
"Code1": "def swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4",
"Code2": "int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "python-cpp-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "python-cpp",
"Code1": "def countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n",
"Code2": "int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( abs ( i - j ) == 1 ) {\n if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str [ i ] == str [ j ] ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n\n"
},
{
"id": "python-cpp-SUM_DIVISORS_1_N_1",
"pair": "python-cpp",
"Code1": "def divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n",
"Code2": "int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n\n"
},
{
"id": "python-cpp-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "python-cpp",
"Code1": "def addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n",
"Code2": "int addOne ( int x ) {\n int m = 1 ;\n while ( x & m ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n\n"
},
{
"id": "python-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "python-cpp",
"Code1": "def check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n",
"Code2": "int check ( string str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str [ i ] - '0' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n\n"
},
{
"id": "python-cpp-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "python-cpp",
"Code1": "def findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n",
"Code2": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int divisors [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n\n"
},
{
"id": "python-cpp-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "python-cpp",
"Code1": "def minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n",
"Code2": "int minRemove ( int arr [ ] , int n ) {\n int LIS [ n ] , len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) {\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n }\n len = max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n\n"
},
{
"id": "python-cpp-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "python-cpp",
"Code1": "def computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n",
"Code2": "void computeLPSArray ( char * pat , int M , int * lps ) {\n int len = 0 ;\n lps [ 0 ] = 0 ;\n int i = 1 ;\n while ( i < M ) {\n if ( pat [ i ] == pat [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n\n"
},
{
"id": "python-cpp-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "python-cpp",
"Code1": "def numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n",
"Code2": "int numofsubset ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-STOOGE_SORT",
"pair": "python-cpp",
"Code1": "def stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n",
"Code2": "void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) swap ( arr [ l ] , arr [ h ] ) ;\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n\n"
},
{
"id": "python-cpp-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "python-cpp",
"Code1": "def solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n",
"Code2": "void solve ( int n , int t , string s ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == 'B' && s [ j + 1 ] == 'G' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n cout << s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n\n"
},
{
"id": "python-cpp-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "python-cpp",
"Code1": "def turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n",
"Code2": "int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n\n"
},
{
"id": "python-cpp-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "python-cpp",
"Code1": "def printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n",
"Code2": "void printEqualModNumbers ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n vector < int > v ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . push_back ( i ) ;\n if ( i != d / i ) v . push_back ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v [ i ] ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v [ i ] != temp ) break ;\n if ( j == n ) cout << v [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "python-cpp",
"Code1": "def findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n",
"Code2": "int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-cpp-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "python-cpp",
"Code1": "def stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n",
"Code2": "int stringReduction ( string str ) {\n int n = str . length ( ) ;\n int count [ 3 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) count [ str [ i ] - 'a' ] ++ ;\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) return n ;\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) return 2 ;\n return 1 ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n\n"
},
{
"id": "python-cpp-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "python-cpp",
"Code1": "def KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n",
"Code2": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int dp [ W + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n\n"
},
{
"id": "python-cpp-SUM_PAIRWISE_PRODUCTS_1",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n",
"Code2": "long long int findSum ( int n ) {\n long long int multiTerms = n * ( n + 1 ) / 2 ;\n long long int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n\n"
},
{
"id": "python-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "python-cpp",
"Code1": "def recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n",
"Code2": "void recursiveReverse ( string & str ) {\n stack < char > st ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n str [ i ] = st . top ( ) ;\n st . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n\n"
},
{
"id": "python-cpp-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "python-cpp",
"Code1": "def subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << i << \" and \" << j - 1 ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n\n"
},
{
"id": "python-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "python-cpp",
"Code1": "def getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result",
"Code2": "int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] & x ) sum ++ ;\n }\n if ( sum % 3 ) result |= x ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result\n"
},
{
"id": "python-cpp-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "python-cpp",
"Code1": "def getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n",
"Code2": "unsigned int getModulo ( unsigned int n , unsigned int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n\n"
},
{
"id": "python-cpp-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "python-cpp",
"Code1": "def allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n",
"Code2": "bool allCharactersSame ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s [ i ] != s [ 0 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "python-cpp",
"Code1": "def maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n",
"Code2": "long long int maxDecimalValue ( int mat [ ] [ N ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) return 0 ;\n int result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) return pow ( 2 , p ) + result ;\n else return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n\n"
},
{
"id": "python-cpp-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "python-cpp",
"Code1": "def countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n",
"Code2": "long long int countBT ( int h ) {\n long long int dp [ h + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n i ++ ) {\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % mod + dp [ i - 1 ] ) % mod ) % mod ;\n }\n return dp [ h ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n\n"
},
{
"id": "python-cpp-COUNTING_INVERSIONS",
"pair": "python-cpp",
"Code1": "def getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n\n"
},
{
"id": "python-cpp-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "python-cpp",
"Code1": "def printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n",
"Code2": "void printRect ( int X [ ] , int Y [ ] , int n ) {\n int Xmax = * max_element ( X , X + n ) ;\n int Xmin = * min_element ( X , X + n ) ;\n int Ymax = * max_element ( Y , Y + n ) ;\n int Ymin = * min_element ( Y , Y + n ) ;\n cout << \"{\" << Xmin << \", \" << Ymin << \"}\" << endl ;\n cout << \"{\" << Xmin << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymax << \"}\" << endl ;\n cout << \"{\" << Xmax << \", \" << Ymin << \"}\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n\n"
},
{
"id": "python-cpp-DELANNOY_NUMBER_1",
"pair": "python-cpp",
"Code1": "def dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n",
"Code2": "int dealnnoy ( int n , int m ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "python-cpp",
"Code1": "def power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n",
"Code2": "int power ( int x , unsigned int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( y & 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n\n"
},
{
"id": "python-cpp-PROGRAM_CHECK_ISBN",
"pair": "python-cpp",
"Code1": "def isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n",
"Code2": "bool isValidISBN ( string & isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn [ i ] - '0' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn [ 9 ] ;\n if ( last != 'X' && ( last < '0' || last > '9' ) ) return false ;\n sum += ( ( last == 'X' ) ? 10 : ( last - '0' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n\n"
},
{
"id": "python-cpp-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "python-cpp",
"Code1": "def NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n",
"Code2": "void NFG ( int a [ ] , int n , int freq [ ] ) {\n stack < int > s ;\n s . push ( 0 ) ;\n int res [ n ] = {\n 0 }\n ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . top ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . top ( ) ] ] < freq [ a [ i ] ] && ! s . empty ( ) ) {\n res [ s . top ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( ! s . empty ( ) ) {\n res [ s . top ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << res [ i ] << \" \" ;\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n\n"
},
{
"id": "python-cpp-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "python-cpp",
"Code1": "def swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )",
"Code2": "int swapBits ( unsigned int x , unsigned int p1 , unsigned int p2 , unsigned int n ) {\n unsigned int set1 = ( x >> p1 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int set2 = ( x >> p2 ) & ( ( 1U << n ) - 1 ) ;\n unsigned int Xor = ( set1 ^ set2 ) ;\n Xor = ( Xor << p1 )",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )\n"
},
{
"id": "python-cpp-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "python-cpp",
"Code1": "def printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n",
"Code2": "void printEqualSumSets ( int arr [ ] , int n ) {\n int i , currSum ;\n int sum = accumulate ( arr , arr + n , 0 ) ;\n if ( sum & 1 ) {\n cout << \"-1\" ;\n return ;\n }\n int k = sum >> 1 ;\n bool dp [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-HYPERCUBE_GRAPH",
"pair": "python-cpp",
"Code1": "def power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n",
"Code2": "int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n\n"
},
{
"id": "python-cpp-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "python-cpp",
"Code1": "def findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void findElements ( int arr [ ] , int n ) {\n int first = INT_MIN , second = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "python-cpp",
"Code1": "def lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n",
"Code2": "int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n\n"
},
{
"id": "python-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "python-cpp",
"Code1": "def reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n",
"Code2": "void reverseStr ( string & str ) {\n int n = str . length ( ) ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) swap ( str [ i ] , str [ j ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n\n"
},
{
"id": "python-cpp-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "python-cpp",
"Code1": "def findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"Code2": "int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low + 1 ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n else break ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n\n"
},
{
"id": "python-cpp-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "python-cpp",
"Code1": "def longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n",
"Code2": "int longestPrefixSuffix ( string s ) {\n int n = s . length ( ) ;\n int lps [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s [ i ] == s [ len ] ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n\n"
},
{
"id": "python-cpp-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "python-cpp",
"Code1": "def MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n",
"Code2": "int MaxTotalRectangleArea ( int a [ ] , int n ) {\n sort ( a , a + n , greater < int > ( ) ) ;\n int sum = 0 ;\n bool flag = false ;\n int len ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( ! flag ) ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "python-cpp",
"Code1": "def printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n",
"Code2": "void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n cout << f2 << \" \" ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "python-cpp",
"Code1": "def minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n",
"Code2": "void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n for ( int j = pos ;\n j > i ;\n -- j ) swap ( arr [ j ] , arr [ j - 1 ] ) ;\n k -= pos - i ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n\n"
},
{
"id": "python-cpp-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "python-cpp",
"Code1": "def isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n",
"Code2": "bool isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) return true ;\n 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 ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n\n"
},
{
"id": "python-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "python-cpp",
"Code1": "def findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n",
"Code2": "int findLength ( string str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str [ l ] - '0' ;\n rsum += str [ r ] - '0' ;\n if ( lsum == rsum ) ans = max ( ans , r - l + 1 ) ;\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "python-cpp",
"Code1": "def countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n",
"Code2": "int countSubarrays ( int arr [ ] , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int hash_positive [ n + 1 ] , hash_negative [ n + 1 ] ;\n fill_n ( hash_positive , n + 1 , 0 ) ;\n fill_n ( hash_negative , n + 1 , 0 ) ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] & 1 == 1 ) difference ++ ;\n else difference -- ;\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n\n"
},
{
"id": "python-cpp-KNAPSACK_PROBLEM_1",
"pair": "python-cpp",
"Code1": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n\n"
},
{
"id": "python-cpp-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "python-cpp",
"Code1": "def multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n",
"Code2": "void multiply ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "python-cpp",
"Code1": "def maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n",
"Code2": "int maxDP ( int n ) {\n int res [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n\n"
},
{
"id": "python-cpp-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n",
"Code2": "int findDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = max ( max_count , count ) ;\n min_count = min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n\n"
},
{
"id": "python-cpp-NUMBER_SINK_NODES_GRAPH",
"pair": "python-cpp",
"Code1": "def countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n",
"Code2": "int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int mark [ n ] ;\n memset ( mark , 0 , sizeof mark ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( ! mark [ i ] ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "python-cpp",
"Code1": "def countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n",
"Code2": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n\n"
},
{
"id": "python-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "python-cpp",
"Code1": "def middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n\n"
},
{
"id": "python-cpp-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "python-cpp",
"Code1": "def countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n",
"Code2": "int countOfSubstringWithKOnes ( string s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int freq [ N + 1 ] = {\n 0 }\n ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s [ i ] - '0' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "python-cpp",
"Code1": "def findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n",
"Code2": "bool findPairs ( int arr [ ] , int n ) {\n map < int , pair < int , int >> Hash ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( Hash . find ( sum ) == Hash . end ( ) ) Hash [ sum ] = make_pair ( i , j ) ;\n else {\n pair < int , int > pp = Hash [ sum ] ;\n cout << \"(\" << arr [ pp . first ] << \", \" << arr [ pp . second ] << \") and (\" << arr [ i ] << \", \" << arr [ j ] << \")n\" ;\n return true ;\n }\n }\n }\n cout << \"No pairs found\" ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n\n"
},
{
"id": "python-cpp-LINEAR_SEARCH",
"pair": "python-cpp",
"Code1": "def search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-cpp-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "python-cpp",
"Code1": "def check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n",
"Code2": "bool check ( string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n bool dp [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( toupper ( s1 [ i ] ) == s2 [ j ] ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! isupper ( s1 [ i ] ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n\n"
},
{
"id": "python-cpp-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "python-cpp",
"Code1": "def binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n",
"Code2": "int binaryToDecimal ( string n ) {\n string num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num [ i ] == '1' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n\n"
},
{
"id": "python-cpp-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "python-cpp",
"Code1": "def countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n",
"Code2": "long countWays ( int n ) {\n long dp [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n\n"
},
{
"id": "python-cpp-MIRROR_CHARACTERS_STRING",
"pair": "python-cpp",
"Code1": "def compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n",
"Code2": "string compute ( string str , int n ) {\n string reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) str [ i ] = reverseAlphabet [ str [ i ] - 'a' ] ;\n return str ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n\n"
},
{
"id": "python-cpp-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "python-cpp",
"Code1": "def maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n",
"Code2": "int maxLenSub ( int arr [ ] , int n ) {\n int mls [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n\n"
},
{
"id": "python-cpp-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "python-cpp",
"Code1": "def exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n",
"Code2": "long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n\n"
},
{
"id": "python-cpp-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "python-cpp",
"Code1": "def sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n",
"Code2": "int sequence ( int n ) {\n int f [ n + 1 ] ;\n int i ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n",
"Code2": "int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int * lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int * lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "python-cpp",
"Code1": "def maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n",
"Code2": "int maximumSum ( int a [ ] [ M ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a [ i ] , a [ i ] + M ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n\n"
},
{
"id": "python-cpp-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "python-cpp",
"Code1": "def fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n",
"Code2": "int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n\n"
},
{
"id": "python-cpp-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "python-cpp",
"Code1": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n",
"Code2": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( str [ i ] - str [ j ] ) == abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n\n"
},
{
"id": "python-cpp-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n",
"Code2": "bool flipsPossible ( int a [ ] , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] & 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 && count_even % 2 ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n\n"
},
{
"id": "python-cpp-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "python-cpp",
"Code1": "def checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n",
"Code2": "bool checkDuplicatesWithinK ( int arr [ ] , int n , int k ) {\n unordered_set < int > myset ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) return true ;\n myset . insert ( arr [ i ] ) ;\n if ( i >= k ) myset . erase ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n\n"
},
{
"id": "python-cpp-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "python-cpp",
"Code1": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n",
"Code2": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \" \\nDiagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ i ] * mat [ i ] [ i ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n cout << mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n\n"
},
{
"id": "python-cpp-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "python-cpp",
"Code1": "def maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n",
"Code2": "int maxArea ( bool mat [ R ] [ C ] ) {\n int hist [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ R + 1 ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) count [ hist [ i ] [ j ] ] ++ ;\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) max_area = curr_area ;\n }\n }\n return max_area ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n\n"
},
{
"id": "python-cpp-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "python-cpp",
"Code1": "def longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n",
"Code2": "int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n\n"
},
{
"id": "python-cpp-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "python-cpp",
"Code1": "def maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n",
"Code2": "int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "python-cpp",
"Code1": "def maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n",
"Code2": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n sort ( arr , arr + N ) ;\n int dp [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n\n"
},
{
"id": "python-cpp-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "python-cpp",
"Code1": "def minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n",
"Code2": "int minOperation ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 ;\n for ( auto i : hash ) if ( max_count < i . second ) max_count = i . second ;\n return ( n - max_count ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n\n"
},
{
"id": "python-cpp-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "python-cpp",
"Code1": "def kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n",
"Code2": "void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n cout << \"k pairs don't exist\" ;\n return ;\n }\n int index2 [ n1 ] ;\n memset ( index2 , 0 , sizeof ( index2 ) ) ;\n while ( k > 0 ) {\n int min_sum = INT_MAX ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n cout << \"(\" << arr1 [ min_index ] << \", \" << arr2 [ index2 [ min_index ] ] << \") \" ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n\n"
},
{
"id": "python-cpp-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "python-cpp",
"Code1": "def spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n",
"Code2": "void spiralPrint ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n cout << a [ k ] [ i ] << \" \" ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n cout << a [ i ] [ n - 1 ] << \" \" ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n cout << a [ m - 1 ] [ i ] << \" \" ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n cout << a [ i ] [ l ] << \" \" ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n\n"
},
{
"id": "python-cpp-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "python-cpp",
"Code1": "def findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n",
"Code2": "int findSum ( string str ) {\n string temp = \"\" ;\n int sum = 0 ;\n for ( char ch : str ) {\n if ( isdigit ( ch ) ) temp += ch ;\n else {\n sum += atoi ( temp . c_str ( ) ) ;\n temp = \"\" ;\n }\n }\n return sum + atoi ( temp . c_str ( ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n\n"
},
{
"id": "python-cpp-NTH_PENTAGONAL_NUMBER",
"pair": "python-cpp",
"Code1": "def pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n",
"Code2": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n\n"
},
{
"id": "python-cpp-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "python-cpp",
"Code1": "def countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n",
"Code2": "long long int countNonDecreasing ( int n ) {\n int N = 10 ;\n long long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n\n"
},
{
"id": "python-cpp-FREQUENT_ELEMENT_ARRAY_1",
"pair": "python-cpp",
"Code1": "def mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n",
"Code2": "int mostFrequent ( int arr [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n int max_count = 0 , res = - 1 ;\n for ( auto i : hash ) {\n if ( max_count < i . second ) {\n res = i . first ;\n max_count = i . second ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n\n"
},
{
"id": "python-cpp-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "python-cpp",
"Code1": "def kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n",
"Code2": "int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int sorted1 [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "python-cpp",
"Code1": "def binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n",
"Code2": "int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n\n"
},
{
"id": "python-cpp-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "python-cpp",
"Code1": "def firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n",
"Code2": "string firstLetterWord ( string str ) {\n string result = \"\" ;\n bool v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ' ' ) v = true ;\n else if ( str [ i ] != ' ' && v == true ) {\n result . push_back ( str [ i ] ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n\n"
},
{
"id": "python-cpp-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "python-cpp",
"Code1": "def assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n",
"Code2": "void assign ( int a [ ] , int n ) {\n sort ( a , a + n ) ;\n int ans [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "python-cpp",
"Code1": "def printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n\n"
},
{
"id": "python-cpp-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "python-cpp",
"Code1": "def countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n",
"Code2": "int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "python-cpp",
"Code1": "def relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n",
"Code2": "void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n cout << arr1 [ i ] << \" \" ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) cout << arr1 [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "python-cpp",
"Code1": "def findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n",
"Code2": "int findFourElements ( int arr [ ] , int n ) {\n unordered_map < int , pair < int , int >> mp ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) mp [ arr [ i ] + arr [ j ] ] = {\n i , j }\n ;\n int d = INT_MIN ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = abs ( arr [ i ] - arr [ j ] ) ;\n if ( mp . find ( abs_diff ) != mp . end ( ) ) {\n pair < int , int > p = mp [ abs_diff ] ;\n if ( p . first != i && p . first != j && p . second != i && p . second != j ) d = max ( d , max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n return d ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n\n"
},
{
"id": "python-cpp-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "python-cpp",
"Code1": "def findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n",
"Code2": "int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n\n"
},
{
"id": "python-cpp-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "python-cpp",
"Code1": "def isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n",
"Code2": "bool isPrime ( int p ) {\n long long checkNumber = pow ( 2 , p ) - 1 ;\n long long nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n\n"
},
{
"id": "python-cpp-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "python-cpp",
"Code1": "def CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n",
"Code2": "int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == 'a' ) {\n a_index = i + 1 ;\n ans -= min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == 'b' ) {\n b_index = i + 1 ;\n ans -= min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n\n"
},
{
"id": "python-cpp-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "python-cpp",
"Code1": "def isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n",
"Code2": "bool isPalindrome ( string str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "python-cpp",
"Code1": "def maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n",
"Code2": "int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int sum [ n ] , curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( um . find ( curr_rem ) == um . end ( ) ) um [ curr_rem ] = i ;\n else if ( maxSum < ( sum [ i ] - sum [ um [ curr_rem ] ] ) ) maxSum = sum [ i ] - sum [ um [ curr_rem ] ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n\n"
},
{
"id": "python-cpp-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "python-cpp",
"Code1": "def decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n",
"Code2": "string decode ( string str ) {\n stack < int > integerstack ;\n stack < char > stringstack ;\n string temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n while ( str [ i ] >= '0' && str [ i ] <= '9' ) {\n count = count * 10 + str [ i ] - '0' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str [ i ] == ']' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . empty ( ) ) {\n count = integerstack . top ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . empty ( ) && stringstack . top ( ) != '[' ) {\n temp = stringstack . top ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . top ( ) == '[' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result [ j ] ) ;\n result = \"\" ;\n }\n else if ( str [ i ] == '[' ) {\n if ( str [ i - 1 ] >= '0' && str [ i - 1 ] <= '9' ) stringstack . push ( str [ i ] ) ;\n else {\n stringstack . push ( str [ i ] ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str [ i ] ) ;\n }\n while ( ! stringstack . empty ( ) ) {\n result = stringstack . top ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n\n"
},
{
"id": "python-cpp-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "python-cpp",
"Code1": "def minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n",
"Code2": "int minSum ( int A [ ] , int n ) {\n int min_val = * min_element ( A , A + n ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n\n"
},
{
"id": "python-cpp-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "python-cpp",
"Code1": "def isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n",
"Code2": "bool isPower ( int x , int y ) {\n int res1 = log ( y ) / log ( x ) ;\n double res2 = log ( y ) / log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n\n"
},
{
"id": "python-cpp-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "python-cpp",
"Code1": "def countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n",
"Code2": "int countWords ( string str [ ] , int n ) {\n unordered_map < string , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ str [ i ] ] += 1 ;\n int res = 0 ;\n for ( auto it = m . begin ( ) ;\n it != m . end ( ) ;\n it ++ ) if ( ( it -> second == 2 ) ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "python-cpp",
"Code1": "def findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n",
"Code2": "int findLargestd ( int S [ ] , int n ) {\n bool found = false ;\n sort ( S , S + n ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return INT_MIN ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n\n"
},
{
"id": "python-cpp-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "python-cpp",
"Code1": "def minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n",
"Code2": "e9 int minMaxValues ( int arr [ ] , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n bool dp [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = 1 ;\n }\n }\n }\n int max_value = - INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = max ( max_value , temp * ( sum - temp ) ) ;\n min_value = min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n cout << \"Maximum Value: \" << max_value << \"\\n\" << \"Minimum Value: \" << min_value << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n\n"
},
{
"id": "python-cpp-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "python-cpp",
"Code1": "def constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n",
"Code2": "void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n cout << \"1 2\" << endl ;\n return ;\n }\n cout << \"-1\" << endl ;\n return ;\n }\n if ( d > 2 * h ) {\n cout << \"-1\" << endl ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) cout << i << \" \" << i + 1 << endl ;\n if ( d > h ) {\n cout << \"1\" << \" \" << h + 2 << endl ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n cout << i << \" \" << i + 1 << endl ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n cout << k << \" \" << i + 1 << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n\n"
},
{
"id": "python-cpp-NUMBER_RECTANGLES_NM_GRID",
"pair": "python-cpp",
"Code1": "def rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n",
"Code2": "int rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n\n"
},
{
"id": "python-cpp-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "python-cpp",
"Code1": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n",
"Code2": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int hash [ max + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-cpp-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "python-cpp",
"Code1": "def subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n",
"Code2": "void subarrayDivisibleByK ( int arr [ ] , int n , int k ) {\n map < int , int > mp ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n cout << \"The maximum size is \" << maxe - maxs + 1 << \" and \" \"the subarray is as follows\\n\" ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n\n"
},
{
"id": "python-cpp-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "python-cpp",
"Code1": "def isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n",
"Code2": "bool isDivisible ( char str [ ] , int k ) {\n int n = strlen ( str ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ;\n return ( c == k ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n\n"
},
{
"id": "python-cpp-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "python-cpp",
"Code1": "def divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n",
"Code2": "int divisible ( string num ) {\n int n = num . length ( ) ;\n int sum = accumulate ( begin ( num ) , end ( num ) , 0 ) - '0' * 1 ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num [ i ] - '0' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n\n"
},
{
"id": "python-cpp-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "python-cpp",
"Code1": "def superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n",
"Code2": "int superSeq ( char * X , char * Y , int m , int n ) {\n if ( ! m ) return n ;\n if ( ! n ) return m ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n\n"
},
{
"id": "python-cpp-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "python-cpp",
"Code1": "def swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n",
"Code2": "void swapUpperToLower ( int arr [ n ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << arr [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n\n"
},
{
"id": "python-cpp-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "python-cpp",
"Code1": "def kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n",
"Code2": "int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n\n"
},
{
"id": "python-cpp-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "python-cpp",
"Code1": "def isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n",
"Code2": "bool isMagicSquare ( int mat [ ] [ N ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "python-cpp",
"Code1": "def isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n",
"Code2": "bool isScalarMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "python-cpp",
"Code1": "def longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n",
"Code2": "int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > um ;\n int mod_arr [ n ] , max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . find ( mod_arr [ i ] ) == um . end ( ) ) um [ mod_arr [ i ] ] = i ;\n else if ( max < ( i - um [ mod_arr [ i ] ] ) ) max = i - um [ mod_arr [ i ] ] ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n\n"
},
{
"id": "python-cpp-REVERSE_A_STRING_USING_RECURSION",
"pair": "python-cpp",
"Code1": "def reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n",
"Code2": "void reverse ( string str ) {\n if ( str . size ( ) == 0 ) {\n return ;\n }\n reverse ( str . substr ( 1 ) ) ;\n cout << str [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n\n"
},
{
"id": "python-cpp-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "python-cpp",
"Code1": "def arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n",
"Code2": "long long arrangeBraces ( int n , int pos [ ] , int k ) {\n bool h [ N ] ;\n int dp [ N ] [ N ] ;\n memset ( h , 0 , sizeof h ) ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) h [ pos [ i ] ] = 1 ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 0 ;\n }\n else {\n if ( j != 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n\n"
},
{
"id": "python-cpp-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "python-cpp",
"Code1": "def isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n",
"Code2": "bool isDvisibleBy12 ( string num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num [ num . length ( ) - 1 ] ;\n if ( d1 % 2 != 0 ) return ( 0 ) ;\n int d2 = ( int ) num [ num . length ( ) - 2 ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num [ i ] ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = stoi ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n\n"
},
{
"id": "python-cpp-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "python-cpp",
"Code1": "def maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n",
"Code2": "int maxDiff ( int arr [ ] , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n bool isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "python-cpp",
"Code1": "def lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n",
"Code2": "string lexSmallest ( string a [ ] , int n ) {\n sort ( a , a + n , compare ) ;\n string answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n\n"
},
{
"id": "python-cpp-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "python-cpp",
"Code1": "def maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n",
"Code2": "int maxCost ( int mat [ ] [ MAX ] , int N ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n\n"
},
{
"id": "python-cpp-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "python-cpp",
"Code1": "def xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n",
"Code2": "int xorZero ( string str ) {\n int one_count = 0 , zero_count = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == '1' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n\n"
},
{
"id": "python-cpp-N_TH_ROOT_NUMBER",
"pair": "python-cpp",
"Code1": "def nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n",
"Code2": "double nthRoot ( int A , int N ) {\n double xPre = rand ( ) % 10 ;\n double eps = 1 e - 3 ;\n double delX = INT_MAX ;\n double xK ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n\n"
},
{
"id": "python-cpp-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "python-cpp",
"Code1": "def findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n",
"Code2": "string findLeft ( string str ) {\n int n = str . length ( ) ;\n while ( n -- ) {\n if ( str [ n ] == 'd' ) {\n str [ n ] = 'c' ;\n break ;\n }\n if ( str [ n ] == 'b' ) {\n str [ n ] = 'a' ;\n break ;\n }\n if ( str [ n ] == 'a' ) str [ n ] = 'b' ;\n else if ( str [ n ] == 'c' ) str [ n ] = 'd' ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n",
"Code2": "int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n sort ( ar , ar + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = max ( res , count ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n\n"
},
{
"id": "python-cpp-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "python-cpp",
"Code1": "def minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n",
"Code2": "void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n unordered_set < int > s ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . insert ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) cout << \"Invalid k\" ;\n else cout << l << \" \" << r ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n\n"
},
{
"id": "python-cpp-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "python-cpp",
"Code1": "def findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n",
"Code2": "int findSum ( int A [ ] , int B [ ] , int n ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n hash [ A [ i ] ] ++ ;\n hash [ B [ i ] ] ++ ;\n }\n int sum = 0 ;\n for ( auto x : hash ) if ( x . second == 1 ) sum += x . first ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n\n"
},
{
"id": "python-cpp-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "python-cpp",
"Code1": "def printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n",
"Code2": "void printSubStr ( string str , int low , int high ) {\n for ( int i = low ;\n i <= high ;\n ++ i ) cout << str [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n\n"
},
{
"id": "python-cpp-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "python-cpp",
"Code1": "def evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n",
"Code2": "int evenSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "python-cpp",
"Code1": "def getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n",
"Code2": "int getMinSquares ( int n ) {\n int * dp = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= ceil ( sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n delete [ ] dp ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "python-cpp",
"Code1": "def arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n",
"Code2": "void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n int t ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n swap ( arr [ i ] , arr [ j ] ) ;\n }\n j ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n\n"
},
{
"id": "python-cpp-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "python-cpp",
"Code1": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n",
"Code2": "void diagonalsquare ( int mat [ ] [ MAX ] , int row , int column ) {\n cout << \"Diagonal one : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n cout << \" \\n\\nDiagonal two : \" ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) cout << mat [ i ] [ j ] * mat [ i ] [ j ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n\n"
},
{
"id": "python-cpp-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "python-cpp",
"Code1": "def areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n",
"Code2": "bool areSumSame ( int a [ ] [ MAX ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 , sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n\n"
},
{
"id": "python-cpp-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "python-cpp",
"Code1": "def printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n",
"Code2": "void printClosest ( int arr [ ] , int n , int x ) {\n int res_l , res_r ;\n int l = 0 , r = n - 1 , diff = INT_MAX ;\n while ( r > l ) {\n if ( abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n cout << \" The closest pair is \" << arr [ res_l ] << \" and \" << arr [ res_r ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n\n"
},
{
"id": "python-cpp-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "python-cpp",
"Code1": "def countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n",
"Code2": "int countSubStr ( char str [ ] ) {\n int m = 0 ;\n for ( int i = 0 ;\n str [ i ] != '\\0' ;\n i ++ ) {\n if ( str [ i ] == '1' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n\n"
},
{
"id": "python-cpp-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "python-cpp",
"Code1": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n",
"Code2": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s [ i ] == s [ j ] ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n\n"
},
{
"id": "python-cpp-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "python-cpp",
"Code1": "def calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n",
"Code2": "int calcMaxValue ( string str ) {\n int res = str [ 0 ] - '0' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == '0' || str [ i ] == '1' || res < 2 ) res += ( str [ i ] - '0' ) ;\n else res *= ( str [ i ] - '0' ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n\n"
},
{
"id": "python-cpp-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-cpp",
"Code1": "def bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-cpp-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "python-cpp",
"Code1": "def countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n",
"Code2": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] ) {\n cout << a [ i ] << \"->\" << cumul << endl ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n\n"
},
{
"id": "python-cpp-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "python-cpp",
"Code1": "def isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n",
"Code2": "bool isSubSeqDivisible ( string str ) {\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = i ;\n j < l ;\n j ++ ) {\n for ( int k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "python-cpp",
"Code1": "def getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n",
"Code2": "unsigned int getAbs ( int n ) {\n int const mask = n >> ( sizeof ( int ) * CHARBIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "python-cpp",
"Code1": "def countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n\n"
},
{
"id": "python-cpp-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "python-cpp",
"Code1": "def minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n",
"Code2": "int minCost ( int a [ ] , int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-cpp-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "python-cpp",
"Code1": "def containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n",
"Code2": "bool containsOdd ( int G [ ] [ V ] , int src ) {\n int colorArr [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n queue < int > q ;\n q . push ( src ) ;\n while ( ! q . empty ( ) ) {\n int u = q . front ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "python-cpp",
"Code1": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n",
"Code2": "int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n\n"
},
{
"id": "python-cpp-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "python-cpp",
"Code1": "def isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n",
"Code2": "bool isAnBn ( string str ) {\n int n = str . length ( ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] != 'a' ) break ;\n if ( i * 2 != n ) return false ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) if ( str [ j ] != 'b' ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "python-cpp",
"Code1": "def getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n",
"Code2": "int getMinSquares ( unsigned int n ) {\n if ( sqrt ( n ) - floor ( sqrt ( n ) ) == 0 ) return 1 ;\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n\n"
},
{
"id": "python-cpp-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "python-cpp",
"Code1": "def maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n",
"Code2": "int maxDistance ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . find ( arr [ i ] ) == mp . end ( ) ) mp [ arr [ i ] ] = i ;\n else max_dist = max ( max_dist , i - mp [ arr [ i ] ] ) ;\n }\n return max_dist ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "python-cpp",
"Code1": "def maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n",
"Code2": "int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n\n"
},
{
"id": "python-cpp-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "python-cpp",
"Code1": "def checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n",
"Code2": "void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n bool flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( floor ( l ) == ceil ( l ) && l >= k ) {\n flag = true ;\n cout << \"i = \" << i << \"\\n\" ;\n cout << \"j = \" << j << \"\\n\" ;\n cout << \"k = \" << k << \"\\n\" ;\n cout << \"l = \" << ( int ) l << \"\\n\" ;\n cout << \"Product of \" << a << \" and \" << b << \" can be written as sum of squares\" << \" of i, j, k, l \\n\" ;\n cout << ab + \" = \" << i << \"*\" << i << \" + \" << j << \"*\" << j << \" + \" << k << \"*\" << k << \" + \" << ( int ) l << \"*\" << ( int ) l << \"\\n\" ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n cout << \"Solution doesn't exist!\\n\" ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n\n"
},
{
"id": "python-cpp-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "python-cpp",
"Code1": "def nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n",
"Code2": "int nobleInteger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "python-cpp",
"Code1": "def countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n",
"Code2": "int countIslands ( int mat [ ] [ N ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 'X' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == 'O' ) && ( j == 0 || mat [ i ] [ j - 1 ] == 'O' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "python-cpp",
"Code1": "def selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n",
"Code2": "int selectRandom ( int x ) {\n static int res ;\n static int count = 0 ;\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n int i = rand ( ) % count ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n\n"
},
{
"id": "python-cpp-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "python-cpp",
"Code1": "def productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n",
"Code2": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n cout << 0 ;\n return ;\n }\n int i , temp = 1 ;\n int * prod = new int [ ( sizeof ( int ) * n ) ] ;\n memset ( prod , 1 , n ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << prod [ i ] << \" \" ;\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n\n"
},
{
"id": "python-cpp-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n",
"Code2": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) j ++ ;\n sort ( A + i , A + 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n",
"Code2": "int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n\n"
},
{
"id": "python-cpp-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "python-cpp",
"Code1": "def cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n",
"Code2": "int cost ( int a [ ] , int n ) {\n return ( n - 1 ) * ( * min_element ( a , a + n ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n\n"
},
{
"id": "python-cpp-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "python-cpp",
"Code1": "def minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n",
"Code2": "int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = INT_MAX , max = INT_MIN ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) min = val ;\n if ( val > max ) max = val ;\n if ( 2 * min <= max ) break ;\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) return n ;\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n\n"
},
{
"id": "python-cpp-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "python-cpp",
"Code1": "def getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n\n"
},
{
"id": "python-cpp-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "python-cpp",
"Code1": "def surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n",
"Code2": "double surface_area_octahedron ( double side ) {\n return ( 2 * ( sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n\n"
},
{
"id": "python-cpp-GNOME_SORT_A_STUPID_ONE",
"pair": "python-cpp",
"Code1": "def gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n",
"Code2": "void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n swap ( arr [ index ] , arr [ index - 1 ] ) ;\n index -- ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n\n"
},
{
"id": "python-cpp-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "python-cpp",
"Code1": "def find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n",
"Code2": "int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n\n"
},
{
"id": "python-cpp-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "python-cpp",
"Code1": "def countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n",
"Code2": "int countUnique ( int mat [ ] [ MAX ] , int n , int m ) {\n int rowsum [ n ] , colsum [ m ] ;\n memset ( colsum , 0 , sizeof ( colsum ) ) ;\n memset ( rowsum , 0 , sizeof ( rowsum ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n\n"
},
{
"id": "python-cpp-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "python-cpp",
"Code1": "def generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n",
"Code2": "void generate ( int ones , int zeroes , string str , int len ) {\n if ( len == str . length ( ) ) {\n cout << str << \" \" ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n\n"
},
{
"id": "python-cpp-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "python-cpp",
"Code1": "def midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n",
"Code2": "void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n if ( r > 0 ) {\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \")\\n\" ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n cout << \"(\" << x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << y + y_centre << \") \" ;\n cout << \"(\" << x + x_centre << \", \" << - y + y_centre << \") \" ;\n cout << \"(\" << - x + x_centre << \", \" << - y + y_centre << \")\\n\" ;\n if ( x != y ) {\n cout << \"(\" << y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << x + y_centre << \") \" ;\n cout << \"(\" << y + x_centre << \", \" << - x + y_centre << \") \" ;\n cout << \"(\" << - y + x_centre << \", \" << - x + y_centre << \")\\n\" ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n\n"
},
{
"id": "python-cpp-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "python-cpp",
"Code1": "def printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n",
"Code2": "void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n cout << fact << \" \" ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n\n"
},
{
"id": "python-cpp-FRIENDS_PAIRING_PROBLEM",
"pair": "python-cpp",
"Code1": "def countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n",
"Code2": "int countFriendsPairings ( int n ) {\n int dp [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "python-cpp",
"Code1": "def remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n",
"Code2": "int remainder ( string str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str [ i ] - '0' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n\n"
},
{
"id": "python-cpp-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "python-cpp",
"Code1": "def findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n",
"Code2": "int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n\n"
},
{
"id": "python-cpp-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "python-cpp",
"Code1": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n",
"Code2": "bool sortedAfterSwap ( int A [ ] , bool B [ ] , int n ) {\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n if ( A [ i ] != i + 1 ) swap ( A [ i ] , A [ i + 1 ] ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "python-cpp",
"Code1": "def maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n",
"Code2": "int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = INT_MAX ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n\n"
},
{
"id": "python-cpp-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "python-cpp",
"Code1": "def printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n",
"Code2": "void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n cout << square << \" \" ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n\n"
},
{
"id": "python-cpp-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "python-cpp",
"Code1": "def checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n",
"Code2": "bool checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n int i ;\n for ( i = 1 ;\n i < n && arr [ i - 1 ] < arr [ i ] ;\n i ++ ) ;\n if ( i == n ) return true ;\n int j = i ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) return false ;\n j ++ ;\n }\n if ( j == n ) return true ;\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) return false ;\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) return false ;\n k ++ ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n\n"
},
{
"id": "python-cpp-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "python-cpp",
"Code1": "def vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n",
"Code2": "double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( sqrt ( 2 ) / 3 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "python-cpp",
"Code1": "def numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n\n"
},
{
"id": "python-cpp-BINARY_SEARCH",
"pair": "python-cpp",
"Code1": "def binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "python-cpp",
"Code1": "def numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int count [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "python-cpp",
"Code1": "def answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n",
"Code2": "long long answer ( int n ) {\n int dp [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n\n"
},
{
"id": "python-cpp-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "python-cpp",
"Code1": "def maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n",
"Code2": "int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n sort ( arr , arr + N , greater < int > ( ) ) ;\n M = max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "python-cpp",
"Code1": "def maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n",
"Code2": "int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ n ] , bw [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n\n"
},
{
"id": "python-cpp-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "python-cpp",
"Code1": "def moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n",
"Code2": "void moveSpaceInFront ( char str [ ] ) {\n int i = strlen ( str ) ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ' ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n\n"
},
{
"id": "python-cpp-RECAMANS_SEQUENCE",
"pair": "python-cpp",
"Code1": "def recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n",
"Code2": "int recaman ( int n ) {\n int arr [ n ] ;\n arr [ 0 ] = 0 ;\n printf ( \"%d, \" , arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n printf ( \"%d, \" , arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "python-cpp",
"Code1": "def findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n",
"Code2": "int findMaxPoints ( int A [ ] [ M ] ) {\n int P1S [ M + 1 ] [ N + 1 ] , P1E [ M + 1 ] [ N + 1 ] ;\n memset ( P1S , 0 , sizeof ( P1S ) ) ;\n memset ( P1E , 0 , sizeof ( P1E ) ) ;\n int P2S [ M + 1 ] [ N + 1 ] , P2E [ M + 1 ] [ N + 1 ] ;\n memset ( P2S , 0 , sizeof ( P2S ) ) ;\n memset ( P2E , 0 , sizeof ( P2E ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = max ( ans , max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n\n"
},
{
"id": "python-cpp-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "python-cpp",
"Code1": "def KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n",
"Code2": "int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ 2 ] [ W + 1 ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n else mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n else mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n\n"
},
{
"id": "python-cpp-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "python-cpp",
"Code1": "def modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n",
"Code2": "int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n\n"
},
{
"id": "python-cpp-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n",
"Code2": "int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 , i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n\n"
},
{
"id": "python-cpp-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "python-cpp",
"Code1": "def countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n",
"Code2": "int countOfBinaryNumberLessThanN ( int N ) {\n queue < int > q ;\n q . push ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( ! q . empty ( ) ) {\n t = q . front ( ) ;\n q . pop ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . push ( t * 10 ) ;\n q . push ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n\n"
},
{
"id": "python-cpp-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "python-cpp",
"Code1": "def findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n",
"Code2": "int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n\n"
},
{
"id": "python-cpp-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "python-cpp",
"Code1": "def substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n",
"Code2": "int substringConversions ( string str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i ;\n i < k ;\n i ++ ) {\n sum = sum + ( ( str . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter -- ;\n }\n cout << sum << \" \" ;\n int prev = sum ;\n sum = 0 , counter = 0 ;\n for ( i ;\n i < str . size ( ) ;\n i ++ ) {\n sum = prev - ( ( str . at ( i - k ) - '0' ) * pow ( b , k - 1 ) ) ;\n sum = sum * b ;\n sum = sum + ( str . at ( i ) - '0' ) ;\n cout << sum << \" \" ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "python-cpp",
"Code1": "def maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n",
"Code2": "int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n sort ( arr , arr + N ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n\n"
},
{
"id": "python-cpp-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "python-cpp",
"Code1": "def longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n",
"Code2": "string longestRepeatedSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n string res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str [ i - 1 ] ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n reverse ( res . begin ( ) , res . end ( ) ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n\n"
},
{
"id": "python-cpp-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "python-cpp",
"Code1": "def isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "bool isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) return false ;\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "python-cpp",
"Code1": "def calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n",
"Code2": "int calculateEnergy ( int mat [ SIZE ] [ SIZE ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += abs ( i_des - i ) + abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n\n"
},
{
"id": "python-cpp-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "python-cpp",
"Code1": "def rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n",
"Code2": "void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) swap ( a [ positive ] , a [ negative ] ) ;\n else break ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n\n"
},
{
"id": "python-cpp-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "python-cpp",
"Code1": "def antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n",
"Code2": "void antiSpiralTraversal ( int m , int n , int a [ R ] [ C ] ) {\n int i , k = 0 , l = 0 ;\n stack < int > stk ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n cout << stk . top ( ) << \" \" ;\n stk . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n\n"
},
{
"id": "python-cpp-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "python-cpp",
"Code1": "def maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n",
"Code2": "void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n cout << \"No pairs exists\\n\" ;\n return ;\n }\n if ( n == 2 ) {\n cout << arr [ 0 ] << \" \" << arr [ 1 ] << endl ;\n return ;\n }\n int posa = INT_MIN , posb = INT_MIN ;\n int nega = INT_MIN , negb = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && abs ( arr [ i ] ) > abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) cout << \"Max product pair is {\" << nega << \", \" << negb << \"}\" ;\n else cout << \"Max product pair is {\" << posa << \", \" << posb << \"}\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n\n"
},
{
"id": "python-cpp-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "python-cpp",
"Code1": "def findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n",
"Code2": "int findMaxVal ( int arr [ ] , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int dp [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] || dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n\n"
},
{
"id": "python-cpp-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "python-cpp",
"Code1": "def Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n",
"Code2": "int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n\n"
},
{
"id": "python-cpp-BUBBLE_SORT",
"pair": "python-cpp",
"Code1": "def bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n",
"Code2": "void bubbleSort ( int arr [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) for ( j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) swap ( & arr [ j ] , & arr [ j + 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n\n"
},
{
"id": "python-cpp-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "python-cpp",
"Code1": "def superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"Code2": "int superSeq ( char * X , char * Y , int m , int n ) {\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "python-cpp",
"Code1": "def countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n",
"Code2": "int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "python-cpp",
"Code1": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = INT_MAX ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != INT_MAX ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n",
"Code2": "int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int dp [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = INT_MAX ;\n for ( int k = max ( j - target , 0 ) ;\n k <= min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) ) ;\n }\n }\n int res = INT_MAX ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n\n"
},
{
"id": "python-cpp-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n",
"Code2": "int kthSmallest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n ) ;\n return arr [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n\n"
},
{
"id": "python-cpp-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "python-cpp",
"Code1": "def minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n",
"Code2": "INT_MAX int minCost ( int cost [ ] [ N ] ) {\n int dist [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n\n"
},
{
"id": "python-cpp-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "python-cpp",
"Code1": "def reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n",
"Code2": "string reversingString ( string str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n\n"
},
{
"id": "python-cpp-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "python-cpp",
"Code1": "def minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n",
"Code2": "int minimalSteps ( string s , int n ) {\n int dp [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = INT_MAX ;\n string s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s [ i ] ;\n s2 = s . substr ( i + 1 , i + 1 ) ;\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n\n"
},
{
"id": "python-cpp-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "python-cpp",
"Code1": "def MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n",
"Code2": "int MinimumCost ( int cost [ ] , int n , int W ) {\n vector < int > val , wt ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . push_back ( cost [ i ] ) ;\n wt . push_back ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = INF ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt [ i - 1 ] > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == INF ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n\n"
},
{
"id": "python-cpp-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "python-cpp",
"Code1": "def bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n",
"Code2": "void bitonicGenerator ( int arr [ ] , int n ) {\n vector < int > evenArr ;\n vector < int > oddArr ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! ( i % 2 ) ) evenArr . push_back ( arr [ i ] ) ;\n else oddArr . push_back ( arr [ i ] ) ;\n }\n sort ( evenArr . begin ( ) , evenArr . end ( ) ) ;\n sort ( oddArr . begin ( ) , oddArr . end ( ) , greater < int > ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) arr [ i ++ ] = evenArr [ j ] ;\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) arr [ i ++ ] = oddArr [ j ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n\n"
},
{
"id": "python-cpp-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "python-cpp",
"Code1": "def countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n",
"Code2": "int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n\n"
},
{
"id": "python-cpp-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "python-cpp",
"Code1": "def printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n",
"Code2": "void printFirstRepeating ( int arr [ ] , int n ) {\n int min = - 1 ;\n set < int > myset ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( myset . find ( arr [ i ] ) != myset . end ( ) ) min = i ;\n else myset . insert ( arr [ i ] ) ;\n }\n if ( min != - 1 ) cout << \"The first repeating element is \" << arr [ min ] ;\n else cout << \"There are no repeating elements\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "python-cpp",
"Code1": "def minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n",
"Code2": "int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != INT_MAX && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "python-cpp",
"Code1": "def pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n",
"Code2": "void pairSum ( int mat [ ] [ MAX ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( mat [ i ] , mat [ i ] + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n cout << \"(\" << mat [ i ] [ left ] << \", \" << mat [ j ] [ right ] << \"), \" ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n\n"
},
{
"id": "python-cpp-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "python-cpp",
"Code1": "def minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n",
"Code2": "int minimum_cost ( int a [ ] , int n ) {\n int mn = INT_MAX ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n",
"Code2": "int lps ( char * str ) {\n int n = strlen ( str ) ;\n int i , j , cl ;\n int L [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( str [ i ] == str [ j ] && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( str [ i ] == str [ j ] ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "python-cpp",
"Code1": "def censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n",
"Code2": "string censor ( string text , string word ) {\n vector < string > word_list ;\n boost :: split ( word_list , text , boost :: is_any_of ( \"\\\\ +\" ) ) ;\n string result = \"\" ;\n string stars = \"\" ;\n for ( int i = 0 ;\n i < word . size ( ) ;\n i ++ ) stars += '*' ;\n int index = 0 ;\n for ( string i : word_list ) {\n if ( i . compare ( word ) == 0 ) {\n word_list [ index ] = stars ;\n }\n index ++ ;\n }\n for ( string i : word_list ) {\n result += i + ' ' ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n\n"
},
{
"id": "python-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "python-cpp",
"Code1": "def isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n",
"Code2": "public : bool isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n\n"
},
{
"id": "python-cpp-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "python-cpp",
"Code1": "def getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n",
"Code2": "float getArea ( int a ) {\n float area = ( M_PI * a * a ) / 4.0 ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n\n"
},
{
"id": "python-cpp-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "python-cpp",
"Code1": "def distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n",
"Code2": "int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n\n"
},
{
"id": "python-cpp-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "python-cpp",
"Code1": "def findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n",
"Code2": "void findMax ( int arr [ ] [ N ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( arr [ i ] [ j ] == 1 && j >= 0 ) {\n row = i ;\n j -- ;\n }\n }\n cout << \"Row number = \" << row + 1 ;\n cout << \", MaxCount = \" << N - 1 - j ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n\n"
},
{
"id": "python-cpp-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "python-cpp",
"Code1": "def lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n",
"Code2": "int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n\n"
},
{
"id": "python-cpp-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "python-cpp",
"Code1": "def evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n",
"Code2": "int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long long int ef1 = 0 , ef2 = 2 ;\n long long int sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long long int ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n\n"
},
{
"id": "python-cpp-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "python-cpp",
"Code1": "def search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + abs ( arr [ i ] - x ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n\n"
},
{
"id": "python-cpp-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "python-cpp",
"Code1": "def isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n",
"Code2": "bool isRotated ( string str1 , string str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n string clock_rot = \"\" ;\n string anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substr ( len - 2 , 2 ) + str2 . substr ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substr ( 2 ) + str2 . substr ( 0 , 2 ) ;\n return ( str1 . compare ( clock_rot ) == 0 || str1 . compare ( anticlock_rot ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n\n"
},
{
"id": "python-cpp-HOSOYAS_TRIANGLE",
"pair": "python-cpp",
"Code1": "def printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n",
"Code2": "void printHosoya ( int n ) {\n int dp [ N ] [ N ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) cout << dp [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n\n"
},
{
"id": "python-cpp-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "python-cpp",
"Code1": "def findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n",
"Code2": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n ( arr [ j ] == 0 ) ? ( sum += - 1 ) : ( sum += 1 ) ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n if ( maxsize == - 1 ) cout << \"No such subarray\" ;\n else cout << startindex << \" to \" << startindex + maxsize - 1 ;\n return maxsize ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n\n"
},
{
"id": "python-cpp-RECURSIVE_INSERTION_SORT",
"pair": "python-cpp",
"Code1": "def insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n",
"Code2": "void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n\n"
},
{
"id": "python-cpp-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n",
"Code2": "int findDiff ( int arr [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ arr [ i ] ] ++ ;\n int max_count = 0 , min_count = n ;\n for ( auto x : hm ) {\n max_count = max ( max_count , x . second ) ;\n min_count = min ( min_count , x . second ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n\n"
},
{
"id": "python-cpp-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "python-cpp",
"Code1": "def playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n",
"Code2": "int playGame ( int arr [ ] , int n ) {\n unordered_set < int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash . insert ( arr [ i ] ) ;\n return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "python-cpp",
"Code1": "def subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n",
"Code2": "int subset ( int arr [ ] , int n ) {\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n int res = 0 ;\n for ( auto x : mp ) res = max ( res , x . second ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n\n"
},
{
"id": "python-cpp-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "python-cpp",
"Code1": "def isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n",
"Code2": "bool isProduct ( int arr [ ] , int n , int x ) {\n if ( n < 2 ) return false ;\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true ;\n s . insert ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n\n"
},
{
"id": "python-cpp-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "python-cpp",
"Code1": "def largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n",
"Code2": "double largestSumOfAverages ( vector < int > & A , int K ) {\n int n = A . size ( ) ;\n double pre_sum [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double dp [ n ] = {\n 0 }\n ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n\n"
},
{
"id": "python-cpp-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "python-cpp",
"Code1": "def getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n ",
"Code2": "int getMinSteps ( int n ) {\n int table [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 ) ) table [ i / 2 ] = min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 ) ) table [ i / 3 ] = min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n \n"
},
{
"id": "python-cpp-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "python-cpp",
"Code1": "def nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n",
"Code2": "int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "python-cpp",
"Code1": "def findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n",
"Code2": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "python-cpp",
"Code1": "def eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n",
"Code2": "int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = INT_MAX , x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n\n"
},
{
"id": "python-cpp-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "python-cpp",
"Code1": "def count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n",
"Code2": "int count ( string s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( s [ i ] == c ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n\n"
},
{
"id": "python-cpp-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "python-cpp",
"Code1": "def findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n",
"Code2": "int findRotations ( string str ) {\n string tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n string substring = tmp . substr ( i , str . size ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n\n"
},
{
"id": "python-cpp-SHUFFLE_A_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n",
"Code2": "void randomize ( int arr [ ] , int n ) {\n srand ( time ( NULL ) ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = rand ( ) % ( i + 1 ) ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n\n"
},
{
"id": "python-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "python-cpp",
"Code1": "def findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n",
"Code2": "int findLength ( string str , int n ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str [ i - 1 ] - '0' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n\n"
},
{
"id": "python-cpp-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "python-cpp",
"Code1": "def translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n",
"Code2": "void translate ( char * str ) {\n int len = strlen ( str ) ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == 'A' && str [ j + 1 ] == 'B' ) {\n j = j + 2 ;\n str [ i ++ ] = 'C' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ' ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n\n"
},
{
"id": "python-cpp-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "python-cpp",
"Code1": "def maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n",
"Code2": "int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long long factorCount [ n + 1 ] ;\n bool prime [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n\n"
},
{
"id": "python-cpp-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "python-cpp",
"Code1": "def catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n",
"Code2": "unsigned long int catalan ( unsigned int n ) {\n if ( n <= 1 ) return 1 ;\n unsigned long int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res += catalan ( i ) * catalan ( n - i - 1 ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n\n"
},
{
"id": "python-cpp-SUM_SERIES_12_32_52_2N_12",
"pair": "python-cpp",
"Code1": "def sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n",
"Code2": "int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n\n"
},
{
"id": "python-cpp-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "python-cpp",
"Code1": "def minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n",
"Code2": "int minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return ceil ( d / ( 2 * r ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n\n"
},
{
"id": "python-cpp-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "python-cpp",
"Code1": "def printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n",
"Code2": "void printString ( string str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n cout << str ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) cout << str . substr ( i + 1 , str . length ( ) - ( i + 1 ) ) ;\n else cout << \"Empty string\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n\n"
},
{
"id": "python-cpp-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "python-cpp",
"Code1": "def largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n",
"Code2": "int largestKSubmatrix ( int a [ ] [ Col ] ) {\n int dp [ Row ] [ Col ] ;\n memset ( dp , sizeof ( dp ) , 0 ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1 ;\n else dp [ i ] [ j ] = 1 ;\n }\n result = max ( result , dp [ i ] [ j ] ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n\n"
},
{
"id": "python-cpp-PASCAL_TRIANGLE",
"pair": "python-cpp",
"Code1": "def printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "void printPascal ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n cout << arr [ line ] [ i ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "python-cpp",
"Code1": "def answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n",
"Code2": "int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-CASSINIS_IDENTITY",
"pair": "python-cpp",
"Code1": "def cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n",
"Code2": "int cassini ( int n ) {\n return ( n & 1 ) ? - 1 : 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n\n"
},
{
"id": "python-cpp-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "python-cpp",
"Code1": "def compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n",
"Code2": "int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n\n"
},
{
"id": "python-cpp-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "python-cpp",
"Code1": "def waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n",
"Code2": "int waysToArrange ( int N , int K , int k [ ] ) {\n int C [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n int dp [ K ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n\n"
},
{
"id": "python-cpp-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "python-cpp",
"Code1": "def findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n",
"Code2": "void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n cout << \"Not Possible\\n\" ;\n return ;\n }\n double apb = sqrt ( H * H + 4 * A ) ;\n double asb = sqrt ( H * H - 4 * A ) ;\n cout . precision ( 2 ) ;\n cout << \"P = \" << fixed << ( apb - asb ) / 2.0 << \"\\n\" ;\n cout << \"B = \" << ( apb + asb ) / 2.0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n\n"
},
{
"id": "python-cpp-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "python-cpp",
"Code1": "def maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n",
"Code2": "int maxTripletSum ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "python-cpp",
"Code1": "def MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n",
"Code2": "long long int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n long long int dp [ n + 1 ] [ m + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "python-cpp",
"Code1": "def findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n",
"Code2": "int findMinDiff ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n\n"
},
{
"id": "python-cpp-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "python-cpp",
"Code1": "def findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "int findLastIndex ( string & str , char x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str [ i ] == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-cpp-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "python-cpp",
"Code1": "def maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n",
"Code2": "int maxLower ( string str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) if ( count [ j ] > 0 ) currCount ++ ;\n maxCount = max ( maxCount , currCount ) ;\n memset ( count , 0 , sizeof ( count ) ) ;\n }\n if ( str [ i ] >= 'a' && str [ i ] <= 'z' ) count [ str [ i ] - 'a' ] ++ ;\n }\n return maxCount ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n\n"
},
{
"id": "python-cpp-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "python-cpp",
"Code1": "def findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-NTH_EVEN_LENGTH_PALINDROME",
"pair": "python-cpp",
"Code1": "def evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n",
"Code2": "string evenlength ( string n ) {\n string res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n [ j ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n\n"
},
{
"id": "python-cpp-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "python-cpp",
"Code1": "def maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n unordered_map < int , int > hM ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . find ( sum + n ) != hM . end ( ) ) {\n if ( max_len < i - hM [ sum + n ] ) {\n max_len = i - hM [ sum + n ] ;\n ending_index = i ;\n }\n }\n else hM [ sum + n ] = i ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n printf ( \"%d to %d\\n\" , ending_index - max_len + 1 , ending_index ) ;\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "python-cpp",
"Code1": "def possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n",
"Code2": "int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n\n"
},
{
"id": "python-cpp-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "python-cpp",
"Code1": "def numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n",
"Code2": "int numberofways ( string A , string B , int N , int M ) {\n vector < int > pos [ MAX ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B [ i ] ] . push_back ( i + 1 ) ;\n int dpl [ N + 2 ] [ M + 2 ] ;\n memset ( dpl , 0 , sizeof ( dpl ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int dpr [ N + 2 ] [ M + 2 ] ;\n memset ( dpr , 0 , sizeof ( dpr ) ) ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A [ i - 1 ] == B [ j - 1 ] ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( auto x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "python-cpp",
"Code1": "def circumference ( r ) :\n return ( 2 * PI * r )\n",
"Code2": "double circumference ( double r ) {\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef circumference ( r ) :\n return ( 2 * PI * r )\n\n"
},
{
"id": "python-cpp-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "python-cpp",
"Code1": "def substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n",
"Code2": "int substringConversions ( string str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . size ( ) ;\n i ++ ) {\n string sub = str . substr ( i , k ) ;\n int sum = 0 , counter = 0 ;\n for ( int i = sub . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n sum = sum + ( ( sub . at ( i ) - '0' ) * pow ( b , counter ) ) ;\n counter ++ ;\n }\n cout << sum << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "python-cpp",
"Code1": "def maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n",
"Code2": "int maxPathSum ( int tri [ ] [ N ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n\n"
},
{
"id": "python-cpp-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "python-cpp",
"Code1": "def SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n",
"Code2": "int SumOfKsubArray ( int arr [ ] , int n , int k ) {\n int sum = 0 ;\n deque < int > S ( k ) , G ( k ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n for ( ;\n i < n ;\n i ++ ) {\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n while ( ! S . empty ( ) && S . front ( ) <= i - k ) S . pop_front ( ) ;\n while ( ! G . empty ( ) && G . front ( ) <= i - k ) G . pop_front ( ) ;\n while ( ( ! S . empty ( ) ) && arr [ S . back ( ) ] >= arr [ i ] ) S . pop_back ( ) ;\n while ( ( ! G . empty ( ) ) && arr [ G . back ( ) ] <= arr [ i ] ) G . pop_back ( ) ;\n G . push_back ( i ) ;\n S . push_back ( i ) ;\n }\n sum += arr [ S . front ( ) ] + arr [ G . front ( ) ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n\n"
},
{
"id": "python-cpp-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "python-cpp",
"Code1": "def fun ( n ) :\n return n & ( n - 1 )\n",
"Code2": "int fun ( unsigned int n ) {\n return n & ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fun ( n ) :\n return n & ( n - 1 )\n\n"
},
{
"id": "python-cpp-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "python-cpp",
"Code1": "def mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n",
"Code2": "pair < double , double > mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return make_pair ( x , y ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n\n"
},
{
"id": "python-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "python-cpp",
"Code1": "def printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n cout << arr [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "python-cpp",
"Code1": "def printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n",
"Code2": "int printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n cout << arr2 [ j ] << \" \" ;\n i ++ ;\n j ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n\n"
},
{
"id": "python-cpp-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "python-cpp",
"Code1": "def search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + max ( 1 , abs ( arr [ i ] - x ) / k ) ;\n }\n cout << \"number is not present!\" ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n\n"
},
{
"id": "python-cpp-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "python-cpp",
"Code1": "def arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n",
"Code2": "string arrangeString ( string str ) {\n int char_count [ MAX_CHAR ] = {\n 0 }\n ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) char_count [ str [ i ] - 'A' ] ++ ;\n else sum = sum + ( str [ i ] - '0' ) ;\n }\n string res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( 'A' + i ) ;\n while ( char_count [ i ] -- ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + to_string ( sum ) ;\n return res ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "python-cpp",
"Code1": "def countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n",
"Code2": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n\n"
},
{
"id": "python-cpp-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "python-cpp",
"Code1": "def minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n",
"Code2": "int minSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n\n"
},
{
"id": "python-cpp-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "python-cpp",
"Code1": "def printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n",
"Code2": "string printSequence ( string arr [ ] , string input ) {\n string output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input [ i ] == ' ' ) output = output + \"0\" ;\n else {\n int position = input [ i ] - 'A' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n\n"
},
{
"id": "python-cpp-ROTATE_MATRIX_ELEMENTS",
"pair": "python-cpp",
"Code1": "def rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n",
"Code2": "void rotatematrix ( int m , int n , int mat [ R ] [ C ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << mat [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n\n"
},
{
"id": "python-cpp-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "python-cpp",
"Code1": "def maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n",
"Code2": "int maxcoefficientvalue ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "python-cpp",
"Code1": "def gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n",
"Code2": "double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( fabs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - floor ( a / b ) * b ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n\n"
},
{
"id": "python-cpp-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "python-cpp",
"Code1": "def sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n",
"Code2": "void sortByPattern ( string & str , string pat ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) count [ str [ i ] - 'a' ] ++ ;\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ( ) ;\n i ++ ) for ( int j = 0 ;\n j < count [ pat [ i ] - 'a' ] ;\n j ++ ) str [ index ++ ] = pat [ i ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n\n"
},
{
"id": "python-cpp-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "python-cpp",
"Code1": "def rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n",
"Code2": "void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n int * jumps = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return INT_MAX ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = INT_MAX ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != INT_MAX ) {\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n\n"
},
{
"id": "python-cpp-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "python-cpp",
"Code1": "def find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n",
"Code2": "float find_prob ( int N , float P ) {\n double dp [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n\n"
},
{
"id": "python-cpp-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "python-cpp",
"Code1": "def waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n",
"Code2": "int waysToIncreaseLCSBy1 ( string str1 , string str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n vector < int > position [ M ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ toInt ( str2 [ i - 1 ] ) ] . push_back ( i ) ;\n int lcsl [ m + 2 ] [ n + 2 ] ;\n int lcsr [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char c = 'a' ;\n c <= 'z' ;\n c ++ ) {\n for ( int j = 0 ;\n j < position [ toInt ( c ) ] . size ( ) ;\n j ++ ) {\n int p = position [ toInt ( c ) ] [ j ] ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n\n"
},
{
"id": "python-cpp-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "python-cpp",
"Code1": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n\n"
},
{
"id": "python-cpp-STERN_BROCOT_SEQUENCE",
"pair": "python-cpp",
"Code1": "def SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n",
"Code2": "void SternSequenceFunc ( vector < int > & BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence [ i ] ;\n int precedent = BrocotSequence [ i - 1 ] ;\n BrocotSequence . push_back ( considered_element + precedent ) ;\n BrocotSequence . push_back ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) cout << BrocotSequence [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-PRUFER_CODE_TREE_CREATION",
"pair": "python-cpp",
"Code1": "def printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n",
"Code2": "void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n cout << \"\\nThe edge set E(G) is :\\n\" ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n cout << \"(\" << ( j + 1 ) << \", \" << prufer [ i ] << \") \" ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n cout << \"(\" << ( i + 1 ) << \", \" ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) cout << ( i + 1 ) << \")\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "python-cpp",
"Code1": "def countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n",
"Code2": "int countDecodingDP ( char * digits , int n ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == '0' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > '0' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == '1' || ( digits [ i - 2 ] == '2' && digits [ i - 1 ] < '7' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n\n"
},
{
"id": "python-cpp-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "python-cpp",
"Code1": "def countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n",
"Code2": "int countStrings ( int n ) {\n int a [ n ] , b [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "python-cpp",
"Code1": "def maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n",
"Code2": "int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ n + 1 ] ;\n memset ( dp , - 1 , sizeof ( dp ) ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-PRINT_BRACKET_NUMBER",
"pair": "python-cpp",
"Code1": "def printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n",
"Code2": "void printBracketNumber ( string exp , int n ) {\n int left_bnum = 1 ;\n stack < int > right_bnum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp [ i ] == '(' ) {\n cout << left_bnum << \" \" ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp [ i ] == ')' ) {\n cout << right_bnum . top ( ) << \" \" ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n\n"
},
{
"id": "python-cpp-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "python-cpp",
"Code1": "def countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n",
"Code2": "int countWords ( char str [ ] , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str [ 0 ] == str [ 1 ] ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str [ j ] == str [ j - 1 ] && str [ j ] == str [ j + 1 ] ) count *= 1 ;\n else if ( str [ j ] == str [ j - 1 ] || str [ j ] == str [ j + 1 ] || str [ j - 1 ] == str [ j + 1 ] ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str [ len - 1 ] == str [ len - 2 ] ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n\n"
},
{
"id": "python-cpp-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "python-cpp",
"Code1": "def largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"Code2": "int largest ( int arr [ ] , int n ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "python-cpp",
"Code1": "def findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n",
"Code2": "int findMinDiff ( int arr [ ] , int n ) {\n int diff = INT_MAX ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ;\n return diff ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n",
"Code2": "int maxSum ( int arr [ ] , int n ) {\n int res = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n\n"
},
{
"id": "python-cpp-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "python-cpp",
"Code1": "def volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n",
"Code2": "float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = 3.14 ;\n return 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n\n"
},
{
"id": "python-cpp-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "python-cpp",
"Code1": "def lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n",
"Code2": "int lcsOf3 ( string X , string Y , string Z , int m , int n , int o ) {\n int L [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] && X [ i - 1 ] == Z [ k - 1 ] ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_ENDLESS_POINTS",
"pair": "python-cpp",
"Code1": "def countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n",
"Code2": "int countEndless ( bool input [ ] [ MAX ] , int n ) {\n bool row [ n ] [ n ] , col [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n bool isEndless = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool isEndless = 1 ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == 0 ) isEndless = 0 ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n\n"
},
{
"id": "python-cpp-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-cpp",
"Code1": "def NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] , j = 0 ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-cpp-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "python-cpp",
"Code1": "def lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n",
"Code2": "int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) return n ;\n if ( n == 2 ) return ( set [ 1 ] % set [ 0 ] == 0 ) ;\n sort ( set , set + n ) ;\n int L [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) if ( set [ n - 1 ] % set [ i ] == 0 ) L [ i ] [ n - 1 ] = 2 ;\n else L [ i ] [ n - 1 ] = 1 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) ++ k ;\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) llgp = L [ i ] [ j ] ;\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) L [ i ] [ j ] = 2 ;\n else L [ i ] [ j ] = 1 ;\n -- i ;\n }\n }\n return llgp ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "python-cpp",
"Code1": "def checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n",
"Code2": "bool checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n\n"
},
{
"id": "python-cpp-DIAGONALLY_DOMINANT_MATRIX",
"pair": "python-cpp",
"Code1": "def isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n",
"Code2": "bool isDDM ( int m [ N ] [ N ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += abs ( m [ i ] [ j ] ) ;\n sum -= abs ( m [ i ] [ i ] ) ;\n if ( abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "python-cpp",
"Code1": "def transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n",
"Code2": "void transpose ( int A [ ] [ N ] , int B [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "python-cpp",
"Code1": "def returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n",
"Code2": "int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n unordered_set < int > mp ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . find ( A [ i ] ) != mp . end ( ) ) {\n mp . erase ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . insert ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n\n"
},
{
"id": "python-cpp-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "python-cpp",
"Code1": "def sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n",
"Code2": "int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n\n"
},
{
"id": "python-cpp-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "python-cpp",
"Code1": "def shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n",
"Code2": "INT_MAX int shortestDist ( int graph [ N ] [ N ] ) {\n int dist [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) continue ;\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n\n"
},
{
"id": "python-cpp-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "python-cpp",
"Code1": "def calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n",
"Code2": "long long int calculateSum ( int n ) {\n long long int sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n\n"
},
{
"id": "python-cpp-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "python-cpp",
"Code1": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n",
"Code2": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n\n"
},
{
"id": "python-cpp-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "python-cpp",
"Code1": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n",
"Code2": "void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) cout << a << \" \" ;\n if ( n >= 1 ) cout << b << \" \" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n cout << a + b << \" \" ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n\n"
},
{
"id": "python-cpp-K_TH_DIGIT_RAISED_POWER_B",
"pair": "python-cpp",
"Code1": "def kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n",
"Code2": "int kthdigit ( int a , int b , int k ) {\n int p = pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "python-cpp",
"Code1": "def isEven ( n ) :\n return ( not ( n & 1 ) )\n",
"Code2": "bool isEven ( int n ) {\n return ( ! ( n & 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isEven ( n ) :\n return ( not ( n & 1 ) )\n\n"
},
{
"id": "python-cpp-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "python-cpp",
"Code1": "def printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n",
"Code2": "void printPath ( string str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str [ i ] - 'A' ) / 5 ;\n int nextY = ( str [ i ] - 'B' + 1 ) % 5 ;\n while ( curX > nextX ) {\n cout << \"Move Up\" << endl ;\n curX -- ;\n }\n while ( curY > nextY ) {\n cout << \"Move Left\" << endl ;\n curY -- ;\n }\n while ( curX < nextX ) {\n cout << \"Move Down\" << endl ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n cout << \"Move Right\" << endl ;\n curY ++ ;\n }\n cout << \"Press OK\" << endl ;\n i ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n\n"
},
{
"id": "python-cpp-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "python-cpp",
"Code1": "def checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n",
"Code2": "bool checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n\n"
},
{
"id": "python-cpp-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "python-cpp",
"Code1": "def isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n",
"Code2": "bool isMinHeap ( int level [ ] , int n ) {\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n\n"
},
{
"id": "python-cpp-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n",
"Code2": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = INT_MIN ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n\n"
},
{
"id": "python-cpp-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "python-cpp",
"Code1": "def maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n",
"Code2": "int maxHamming ( int arr [ ] , int n ) {\n int brr [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n\n"
},
{
"id": "python-cpp-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "python-cpp",
"Code1": "def findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n",
"Code2": "int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n\n"
},
{
"id": "python-cpp-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "python-cpp",
"Code1": "def seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n",
"Code2": "double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n bool sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n\n"
},
{
"id": "python-cpp-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "python-cpp",
"Code1": "def countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n",
"Code2": "int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n bool k = 0 ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n ans += k ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "python-cpp",
"Code1": "def getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n",
"Code2": "int getPairsCount ( int arr [ ] , int n , int sum ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twice_count += m [ sum - arr [ i ] ] ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n\n"
},
{
"id": "python-cpp-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "python-cpp",
"Code1": "def isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n",
"Code2": "bool isDiagonalMatrix ( int mat [ N ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "python-cpp",
"Code1": "def printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n",
"Code2": "void printSorted ( int a , int b , int c ) {\n int get_max = max ( a , max ( b , c ) ) ;\n int get_min = - max ( - a , max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n cout << get_min << \" \" << get_mid << \" \" << get_max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n\n"
},
{
"id": "python-cpp-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "python-cpp",
"Code1": "def isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n",
"Code2": "bool isDivisible ( long long int n ) {\n while ( n / 100 ) {\n int last_digit = n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n\n"
},
{
"id": "python-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "python-cpp",
"Code1": "def getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos",
"Code2": "int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos\n"
},
{
"id": "python-cpp-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "python-cpp",
"Code1": "def minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n",
"Code2": "int minSumPath ( vector < vector < int >> & A ) {\n int memo [ A . size ( ) ] ;\n int n = A . size ( ) - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . size ( ) ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . size ( ) - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . size ( ) ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n\n"
},
{
"id": "python-cpp-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "python-cpp",
"Code1": "def rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n",
"Code2": "void GFG :: rearrange ( int arr [ ] , int n ) {\n int i = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n swap ( & arr [ i ] , & arr [ j ] ) ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n swap ( & arr [ neg ] , & arr [ pos ] ) ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n\n"
},
{
"id": "python-cpp-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "python-cpp",
"Code1": "def countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n",
"Code2": "int countNum ( int arr [ ] , int n ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n\n"
},
{
"id": "python-cpp-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "python-cpp",
"Code1": "def largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n",
"Code2": "int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = * max_element ( arr , arr + n ) ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = max ( ans , count ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n\n"
},
{
"id": "python-cpp-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "python-cpp",
"Code1": "def isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n",
"Code2": "bool isNumber ( string s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "python-cpp",
"Code1": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n",
"Code2": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n unordered_set < int > us ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . insert ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . find ( x - arr2 [ j ] ) != us . end ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "python-cpp",
"Code1": "def CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n",
"Code2": "int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n\n"
},
{
"id": "python-cpp-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "python-cpp",
"Code1": "def minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n",
"Code2": "int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n\n"
},
{
"id": "python-cpp-NTH_NON_FIBONACCI_NUMBER",
"pair": "python-cpp",
"Code1": "def nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n",
"Code2": "int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "python-cpp",
"Code1": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int lis [ n ] ;\n lis [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n lis [ i ] = 1 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n }\n return * max_element ( lis , lis + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n\n"
},
{
"id": "python-cpp-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n",
"Code2": "void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) cout << arr [ i % n ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n\n"
},
{
"id": "python-cpp-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "python-cpp",
"Code1": "def repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n",
"Code2": "string repeat ( string s , int n ) {\n string s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n\n"
},
{
"id": "python-cpp-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "python-cpp",
"Code1": "def findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n",
"Code2": "string findSubString ( string str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n bool visited [ MAX_CHARS ] = {\n false }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str [ i ] ] == false ) {\n visited [ str [ i ] ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 , min_len = INT_MAX ;\n int count = 0 ;\n int curr_count [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str [ j ] ] ++ ;\n if ( curr_count [ str [ j ] ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str [ start ] ] > 1 ) {\n if ( curr_count [ str [ start ] ] > 1 ) curr_count [ str [ start ] ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substr ( start_index , min_len ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n\n"
},
{
"id": "python-cpp-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "python-cpp",
"Code1": "def findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n",
"Code2": "public : int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n\n"
},
{
"id": "python-cpp-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "python-cpp",
"Code1": "def printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n",
"Code2": "void printSubsequences ( int arr [ ] , int n ) {\n unsigned int opsize = pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( counter & ( 1 << j ) ) cout << arr [ j ] << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "python-cpp",
"Code1": "def minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n",
"Code2": "int minXOR ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int minXor = INT_MAX ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n\n"
},
{
"id": "python-cpp-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "python-cpp",
"Code1": "def luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n",
"Code2": "void luDecomposition ( int mat [ ] [ MAX ] , int n ) {\n int lower [ n ] [ n ] , upper [ n ] [ n ] ;\n memset ( lower , 0 , sizeof ( lower ) ) ;\n memset ( upper , 0 , sizeof ( upper ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n cout << setw ( 6 ) << \" Lower Triangular\" << setw ( 32 ) << \"Upper Triangular\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << lower [ i ] [ j ] << \"\\t\" ;\n cout << \"\\t\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 6 ) << upper [ i ] [ j ] << \"\\t\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n\n"
},
{
"id": "python-cpp-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "python-cpp",
"Code1": "def bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n",
"Code2": "void bin ( unsigned n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n printf ( \"%d\" , n & 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n\n"
},
{
"id": "python-cpp-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "python-cpp",
"Code1": "def CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n",
"Code2": "int CountPS ( char str [ ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n bool P [ n ] [ n ] ;\n memset ( P , false , sizeof ( P ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "python-cpp",
"Code1": "def modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n",
"Code2": "void modularEquation ( int a , int b ) {\n if ( a < b ) {\n cout << \"No solution possible \" << endl ;\n return ;\n }\n if ( a == b ) {\n cout << \"Infinite Solution possible \" << endl ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n cout << count << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n\n"
},
{
"id": "python-cpp-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "python-cpp",
"Code1": "def minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n",
"Code2": "int minimumSquare ( int a , int b ) {\n long long result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n long long rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "python-cpp",
"Code1": "def maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n",
"Code2": "int maxSum ( int mat [ SIZE ] [ SIZE ] , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ n ] [ n ] ;\n int maxSum = INT_MIN , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = INT_MIN ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n\n"
},
{
"id": "python-cpp-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "python-cpp",
"Code1": "def findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n",
"Code2": "long long int findMinSum ( int a [ ] , int b [ ] , int n ) {\n sort ( a , a + n ) ;\n sort ( b , b + n ) ;\n long long int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n\n"
},
{
"id": "python-cpp-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "python-cpp",
"Code1": "def deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n",
"Code2": "void deleteElements ( int arr [ ] , int n , int k ) {\n stack < int > s ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . top ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n vector < int > v ( m ) ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . top ( ) ;\n s . pop ( ) ;\n }\n for ( auto x : v ) cout << x << \" \" ;\n cout << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "python-cpp",
"Code1": "def first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n",
"Code2": "char first ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n\n"
},
{
"id": "python-cpp-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "python-cpp",
"Code1": "def minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n",
"Code2": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = INT_MAX ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > abs ( i - j ) ) {\n min_dist = abs ( i - j ) ;\n }\n }\n }\n return min_dist ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n\n"
},
{
"id": "python-cpp-ARC_LENGTH_ANGLE",
"pair": "python-cpp",
"Code1": "def arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n",
"Code2": "double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n cout << \"Angle cannot\" , \" be formed\" ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n\n"
},
{
"id": "python-cpp-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "python-cpp",
"Code1": "def findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n",
"Code2": "void findSymPairs ( int arr [ ] [ 2 ] , int row ) {\n unordered_map < int , int > hM ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n if ( hM . find ( sec ) != hM . end ( ) && hM [ sec ] == first ) cout << \"(\" << sec << \", \" << first << \")\" << endl ;\n else hM [ first ] = sec ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n\n"
},
{
"id": "python-cpp-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "python-cpp",
"Code1": "def isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n",
"Code2": "bool isValidString ( string str ) {\n int freq [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) count_freq1 ++ ;\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) count_freq1 ++ ;\n if ( freq [ k ] == freq2 ) count_freq2 ++ ;\n else return false ;\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) return false ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-PRIME_NUMBERS",
"pair": "python-cpp",
"Code1": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n",
"Code2": "bool isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "python-cpp",
"Code1": "def findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n",
"Code2": "int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int * csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n delete [ ] csum ;\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n\n"
},
{
"id": "python-cpp-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "python-cpp",
"Code1": "def maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n",
"Code2": "void maximizecube ( int l , int b , int h ) {\n int side = __gcd ( l , __gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n cout << side << \" \" << num << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n\n"
},
{
"id": "python-cpp-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "python-cpp",
"Code1": "def horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n",
"Code2": "int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n\n"
},
{
"id": "python-cpp-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "python-cpp",
"Code1": "def rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n",
"Code2": "void rotate ( int arr [ ] , int n ) {\n int x = arr [ n - 1 ] , i ;\n for ( i = n - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n\n"
},
{
"id": "python-cpp-N_BONACCI_NUMBERS_1",
"pair": "python-cpp",
"Code1": "def bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "void bonacciseries ( long n , int m ) {\n int a [ m ] = {\n 0 }\n ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << a [ i ] << \" \" ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "python-cpp",
"Code1": "def numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n",
"Code2": "int numberOfWays ( int x ) {\n int dp [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n\n"
},
{
"id": "python-cpp-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "python-cpp",
"Code1": "def findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n",
"Code2": "int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int screen [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "python-cpp",
"Code1": "def maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n",
"Code2": "int maxRowDiff ( int mat [ ] [ MAX ] , int m , int n ) {\n int rowSum [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n\n"
},
{
"id": "python-cpp-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "python-cpp",
"Code1": "def isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n",
"Code2": "int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ MAX ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) return 1 ;\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) return dp [ index ] [ modulo ] ;\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n bool res = ( placeAdd || placeMinus ) ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n\n"
},
{
"id": "python-cpp-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "python-cpp",
"Code1": "def fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n",
"Code2": "int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 , fn = 5 ;\n while ( t < n ) {\n fn = round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "python-cpp",
"Code1": "def minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n",
"Code2": "int minCost ( int cost [ R ] [ C ] , int m , int n ) {\n int i , j ;\n int tc [ R ] [ C ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "python-cpp",
"Code1": "def amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n",
"Code2": "void amendSentence ( string str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str [ i ] >= 'A' && str [ i ] <= 'Z' ) {\n str [ i ] = str [ i ] + 32 ;\n if ( i != 0 ) cout << \" \" ;\n cout << str [ i ] ;\n }\n else cout << str [ i ] ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n\n"
},
{
"id": "python-cpp-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "python-cpp",
"Code1": "def countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n",
"Code2": "int countWays ( int arr [ ] , int m , int N ) {\n int count [ N + 1 ] ;\n memset ( count , 0 , sizeof ( count ) ) ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n\n"
},
{
"id": "python-cpp-BREAK_NUMBER_THREE_PARTS",
"pair": "python-cpp",
"Code1": "def count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n",
"Code2": "ll count_of_ways ( ll n ) {\n ll count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "python-cpp",
"Code1": "def sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n",
"Code2": "float sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n\n"
},
{
"id": "python-cpp-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "python-cpp",
"Code1": "def findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n",
"Code2": "void findDivision ( string & str , int a , int b ) {\n int len = str . length ( ) ;\n vector < int > lr ( len + 1 , 0 ) ;\n lr [ 0 ] = ( str [ 0 ] - '0' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( str [ i ] - '0' ) ) % a ;\n vector < int > rl ( len + 1 , 0 ) ;\n rl [ len - 1 ] = ( str [ len - 1 ] - '0' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( str [ i ] - '0' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n cout << \"YES\\n\" ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) cout << str [ k ] ;\n cout << \", \" ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) cout << str [ k ] ;\n return ;\n }\n }\n cout << \"NO\\n\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n\n"
},
{
"id": "python-cpp-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "python-cpp",
"Code1": "def countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n",
"Code2": "int countCommon ( int mat [ ] [ MAX ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n\n"
},
{
"id": "python-cpp-HEXAGONAL_NUMBER",
"pair": "python-cpp",
"Code1": "def hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n",
"Code2": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n\n"
},
{
"id": "python-cpp-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "python-cpp",
"Code1": "def findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n",
"Code2": "int findGreatest ( int arr [ ] , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n\n"
},
{
"id": "python-cpp-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "python-cpp",
"Code1": "def squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n",
"Code2": "void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n cout << \"Square root is \" << x ;\n return ;\n }\n }\n cout << \"Square root doesn't exist\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "python-cpp",
"Code1": "def count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n",
"Code2": "int count ( string a , string b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ m + 1 ] [ n + 1 ] = {\n {\n 0 }\n }\n ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "python-cpp",
"Code1": "def find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n",
"Code2": "int find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) {\n int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ;\n return indexOf ( arrA , extra_element , n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n\n"
},
{
"id": "python-cpp-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "python-cpp",
"Code1": "def find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n",
"Code2": "int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . insert ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( s . find ( a [ i ] ) == s . end ( ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "python-cpp",
"Code1": "def sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n",
"Code2": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n int sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n int sum = sumLastLevel * l ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n\n"
},
{
"id": "python-cpp-LEONARDO_NUMBER_1",
"pair": "python-cpp",
"Code1": "def leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n",
"Code2": "int leonardo ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "python-cpp",
"Code1": "def countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n",
"Code2": "int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n stack < int > s ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . top ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "python-cpp",
"Code1": "def check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n",
"Code2": "bool check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) deg_sum += degree [ i ] ;\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n\n"
},
{
"id": "python-cpp-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "python-cpp",
"Code1": "def evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n",
"Code2": "int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "python-cpp",
"Code1": "def findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n",
"Code2": "int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-cpp-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "python-cpp",
"Code1": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"Code2": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n\n"
},
{
"id": "python-cpp-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "python-cpp",
"Code1": "def getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n",
"Code2": "char getMaxOccuringChar ( char * str ) {\n int count [ ASCII_SIZE ] = {\n 0 }\n ;\n int len = strlen ( str ) ;\n int max = 0 ;\n char result ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n count [ str [ i ] ] ++ ;\n if ( max < count [ str [ i ] ] ) {\n max = count [ str [ i ] ] ;\n result = str [ i ] ;\n }\n }\n return result ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n\n"
},
{
"id": "python-cpp-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "python-cpp",
"Code1": "def countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n",
"Code2": "int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n\n"
},
{
"id": "python-cpp-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "python-cpp",
"Code1": "def printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n",
"Code2": "void printSumSimple ( int mat [ ] [ n ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n cout << sum << \" \" ;\n }\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "python-cpp",
"Code1": "def findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n",
"Code2": "void findCount ( int n , int sum ) {\n int start = pow ( 10 , n - 1 ) ;\n int end = pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i <= end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n cout << count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n\n"
},
{
"id": "python-cpp-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "python-cpp",
"Code1": "def countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n",
"Code2": "int countGroups ( int position , int previous_sum , int length , char * num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - '0' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n\n"
},
{
"id": "python-cpp-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "python-cpp",
"Code1": "def intersection ( n ) :\n return n * ( n - 1 )\n",
"Code2": "int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef intersection ( n ) :\n return n * ( n - 1 )\n\n"
},
{
"id": "python-cpp-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n",
"Code2": "int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n\n"
},
{
"id": "python-cpp-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "python-cpp",
"Code1": "def findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n",
"Code2": "int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-cpp-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "python-cpp",
"Code1": "def smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n",
"Code2": "int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x && y && z ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n\n"
},
{
"id": "python-cpp-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "python-cpp",
"Code1": "def maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n",
"Code2": "double maxAverageOfPath ( int cost [ M ] [ M ] , int N ) {\n int dp [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j <= N ;\n j ++ ) dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "python-cpp",
"Code1": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n",
"Code2": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "python-cpp",
"Code1": "def longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n",
"Code2": "int longLenSub ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . find ( arr [ i ] - 1 ) != um . end ( ) && len < um [ arr [ i ] - 1 ] ) len = um [ arr [ i ] - 1 ] ;\n if ( um . find ( arr [ i ] + 1 ) != um . end ( ) && len < um [ arr [ i ] + 1 ] ) len = um [ arr [ i ] + 1 ] ;\n um [ arr [ i ] ] = len + 1 ;\n if ( longLen < um [ arr [ i ] ] ) longLen = um [ arr [ i ] ] ;\n }\n return longLen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n\n"
},
{
"id": "python-cpp-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "python-cpp",
"Code1": "def isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n",
"Code2": "bool isPrime ( int n , int i = 2 ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n\n"
},
{
"id": "python-cpp-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "python-cpp",
"Code1": "def computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n",
"Code2": "int computeLastDigit ( long long int A , long long int B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long long int i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n\n"
},
{
"id": "python-cpp-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "python-cpp",
"Code1": "def minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n",
"Code2": "int minOperation ( bool arr [ N ] [ M ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == 0 ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == 1 ) arr [ k ] [ h ] = 0 ;\n else arr [ k ] [ h ] = 1 ;\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n\n"
},
{
"id": "python-cpp-NEXT_POWER_OF_2_1",
"pair": "python-cpp",
"Code1": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n\n"
},
{
"id": "python-cpp-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "python-cpp",
"Code1": "def getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n",
"Code2": "int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n sort ( arr , arr + n ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n if ( small > big ) swap ( small , big ) ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return min ( ans , big - small ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n\n"
},
{
"id": "python-cpp-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "python-cpp",
"Code1": "def numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n",
"Code2": "int numberofways ( int n , int m ) {\n int dp [ n + 2 ] [ n + 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n\n"
},
{
"id": "python-cpp-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "python-cpp",
"Code1": "def check ( n ) :\n return 1162261467 % n == 0\n",
"Code2": "bool check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( n ) :\n return 1162261467 % n == 0\n\n"
},
{
"id": "python-cpp-NEWMAN_CONWAY_SEQUENCE",
"pair": "python-cpp",
"Code1": "def sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n",
"Code2": "int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n\n"
},
{
"id": "python-cpp-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "python-cpp",
"Code1": "def generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n",
"Code2": "void generate_derangement ( int N ) {\n int S [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N && i % N != 0 ) {\n int temp = D [ N ] D [ N ] = D [ N - 1 ] ;\n D [ N - 1 ] = temp ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) printf ( \"%d \" , D [ i ] ) ;\n printf ( \"\\n\" ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "python-cpp",
"Code1": "def countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n",
"Code2": "int countTriangle ( int graph [ V ] [ V ] , bool isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] && graph [ j ] [ k ] && graph [ k ] [ i ] ) count_Triangle ++ ;\n }\n }\n }\n isDirected ? count_Triangle /= 3 : count_Triangle /= 6 ;\n return count_Triangle ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n\n"
},
{
"id": "python-cpp-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "python-cpp",
"Code1": "def findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n",
"Code2": "int findHeight ( int * parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = max ( res , current ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n\n"
},
{
"id": "python-cpp-LEONARDO_NUMBER",
"pair": "python-cpp",
"Code1": "def leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n",
"Code2": "int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n\n"
},
{
"id": "python-cpp-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "python-cpp",
"Code1": "def findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n",
"Code2": "int findLargestPlus ( int mat [ N ] [ N ] ) {\n int left [ N ] [ N ] , right [ N ] [ N ] , top [ N ] [ N ] , bottom [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n\n"
},
{
"id": "python-cpp-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "python-cpp",
"Code1": "def HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n",
"Code2": "bool HalfDiagonalSums ( int mat [ ] [ MAX ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n\n"
},
{
"id": "python-cpp-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "python-cpp",
"Code1": "def sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n",
"Code2": "int sumAtKthLevel ( string tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree [ i ] == '(' ) level ++ ;\n else if ( tree [ i ] == ')' ) level -- ;\n else {\n if ( level == k ) sum += ( tree [ i ] - '0' ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n\n"
},
{
"id": "python-cpp-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "python-cpp",
"Code1": "def LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n",
"Code2": "void LeibnizHarmonicTriangle ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) cout << \"1/\" << i * C [ i - 1 ] [ j - 1 ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "python-cpp",
"Code1": "def countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n",
"Code2": "int countWays ( string s ) {\n int count [ 26 ] = {\n 0 }\n ;\n for ( char x : s ) count [ x - 'a' ] ++ ;\n count [ s [ 0 ] - 'a' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "python-cpp",
"Code1": "def countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n",
"Code2": "int countWays ( int n , int m ) {\n int count [ n + 1 ] ;\n count [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n\n"
},
{
"id": "python-cpp-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "python-cpp",
"Code1": "def printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n",
"Code2": "void printCommonElements ( int mat [ M ] [ N ] ) {\n unordered_map < int , int > mp ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp [ mat [ 0 ] [ j ] ] = 1 ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp [ mat [ i ] [ j ] ] == i ) {\n mp [ mat [ i ] [ j ] ] = i + 1 ;\n if ( i == M - 1 ) cout << mat [ i ] [ j ] << \" \" ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-FLOOR_IN_A_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n",
"Code2": "int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n\n"
},
{
"id": "python-cpp-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "python-cpp",
"Code1": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned int p = 1 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n\n"
},
{
"id": "python-cpp-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "python-cpp",
"Code1": "def printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n",
"Code2": "void printkthnode ( vector < pair < int , int >> adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( adj [ i ] . begin ( ) , adj [ i ] . end ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) cout << adj [ i ] [ adj [ i ] . size ( ) - k ] . second ;\n else cout << \"-1\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n\n"
},
{
"id": "python-cpp-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "void longest ( int a [ ] , int n , int k ) {\n unordered_map < int , int > freq ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) end = i , start = l ;\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "python-cpp",
"Code1": "def minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n",
"Code2": "int minimumflip ( int mat [ ] [ N ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n\n"
},
{
"id": "python-cpp-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "python-cpp",
"Code1": "def breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n",
"Code2": "int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "python-cpp",
"Code1": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n",
"Code2": "int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "python-cpp",
"Code1": "def alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n",
"Code2": "void alternateSubarray ( bool arr [ ] , int n ) {\n int len [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == 1 ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) cout << len [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "python-cpp",
"Code1": "def subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n",
"Code2": "void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = 'z' ;\n ch >= 'a' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = '\\0' ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n\n"
},
{
"id": "python-cpp-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "python-cpp",
"Code1": "def maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n\n"
},
{
"id": "python-cpp-DICE_THROW_PROBLEM",
"pair": "python-cpp",
"Code1": "def findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n",
"Code2": "int findWays ( int m , int n , int x ) {\n int table [ n + 1 ] [ x + 1 ] ;\n memset ( table , 0 , sizeof ( table ) ) ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= x ;\n j ++ ) for ( int k = 1 ;\n k <= m && k < j ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n return table [ n ] [ x ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n\n"
},
{
"id": "python-cpp-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "python-cpp",
"Code1": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n",
"Code2": "bool checkCorrectOrNot ( string s ) {\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s [ i ] - 'a' ] ++ ;\n count [ s [ j ] - 'a' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "python-cpp",
"Code1": "def findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n",
"Code2": "int findNumberOfTriangles ( int arr [ ] , int n ) {\n qsort ( arr , n , sizeof ( arr [ 0 ] ) , comp ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n\n"
},
{
"id": "python-cpp-TILING_WITH_DOMINOES",
"pair": "python-cpp",
"Code1": "def countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n",
"Code2": "int countWays ( int n ) {\n int A [ n + 1 ] , B [ n + 1 ] ;\n A [ 0 ] = 1 , A [ 1 ] = 0 , B [ 0 ] = 0 , B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"Code2": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n\n"
},
{
"id": "python-cpp-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "python-cpp",
"Code1": "def minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n",
"Code2": "int minValue ( int A [ ] , int B [ ] , int n ) {\n sort ( A , A + n ) ;\n sort ( B , B + n ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n\n"
},
{
"id": "python-cpp-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "python-cpp",
"Code1": "def isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n",
"Code2": "bool isOneFlip ( string str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str [ i ] - '0' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "python-cpp",
"Code1": "def MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n",
"Code2": "int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int k ;\n int min = INT_MAX ;\n int count ;\n for ( k = i ;\n k < j ;\n k ++ ) {\n count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n\n"
},
{
"id": "python-cpp-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "python-cpp",
"Code1": "def multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n",
"Code2": "public : int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "python-cpp",
"Code1": "def countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n",
"Code2": "int countP ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= i ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-cpp-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-cpp",
"Code1": "def worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ n ] ;\n memset ( allocation , - 1 , sizeof ( allocation ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n cout << \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << \" \" << i + 1 << \"\\t\\t\" << processSize [ i ] << \"\\t\\t\" ;\n if ( allocation [ i ] != - 1 ) cout << allocation [ i ] + 1 ;\n else cout << \"Not Allocated\" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-cpp-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "python-cpp",
"Code1": "def maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n",
"Code2": "int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n\n"
},
{
"id": "python-cpp-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "python-cpp",
"Code1": "def findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n",
"Code2": "int findLength ( char * str ) {\n int n = strlen ( str ) ;\n int maxlen = 0 ;\n int sum [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str [ i ] - '0' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n\n"
},
{
"id": "python-cpp-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "python-cpp",
"Code1": "def subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n cout << \"Sum found between indexes \" << start << \" and \" << i - 1 ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n cout << \"No subarray found\" ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n\n"
},
{
"id": "python-cpp-COMMON_CHARACTERS_N_STRINGS",
"pair": "python-cpp",
"Code1": "def commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n",
"Code2": "void commonCharacters ( string str [ ] , int n ) {\n bool prim [ MAX_CHAR ] ;\n memset ( prim , true , sizeof ( prim ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n bool sec [ MAX_CHAR ] = {\n false }\n ;\n for ( int j = 0 ;\n str [ i ] [ j ] ;\n j ++ ) {\n if ( prim [ str [ i ] [ j ] - 'a' ] ) sec [ str [ i ] [ j ] - 'a' ] = true ;\n }\n memcpy ( prim , sec , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) printf ( \"%c \" , i + 'a' ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "python-cpp",
"Code1": "def canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n",
"Code2": "bool canMakeStr2 ( string str1 , string str2 ) {\n int count [ MAX ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count [ str1 [ i ] ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) {\n if ( count [ str2 [ i ] ] == 0 ) return false ;\n count [ str2 [ i ] ] -- ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n\n"
},
{
"id": "python-cpp-MAGIC_SQUARE",
"pair": "python-cpp",
"Code1": "def generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n",
"Code2": "void generateSquare ( int n ) {\n int magicSquare [ n ] [ n ] ;\n memset ( magicSquare , 0 , sizeof ( magicSquare ) ) ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n cout << \"The Magic Square for n=\" << n << \":\\nSum of \" \"each row or column \" << n * ( n * n + 1 ) / 2 << \":\\n\\n\" ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) cout << magicSquare [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "python-cpp",
"Code1": "def count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n",
"Code2": "int count ( string a , string b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a [ m - 1 ] == b [ n - 1 ] ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n\n"
},
{
"id": "python-cpp-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "python-cpp",
"Code1": "def numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n",
"Code2": "int numofArray ( int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n vector < int > di [ MAX ] ;\n vector < int > mu [ MAX ] ;\n memset ( dp , 0 , sizeof dp ) ;\n memset ( di , 0 , sizeof di ) ;\n memset ( mu , 0 , sizeof mu ) ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . push_back ( i ) ;\n mu [ i ] . push_back ( j ) ;\n }\n di [ i ] . push_back ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( auto x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( auto x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "python-cpp",
"Code1": "def countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n",
"Code2": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n\n"
},
{
"id": "python-cpp-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "python-cpp",
"Code1": "def ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n",
"Code2": "int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n\n"
},
{
"id": "python-cpp-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "python-cpp",
"Code1": "def decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n",
"Code2": "string decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n string bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? '0' : '1' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n\n"
},
{
"id": "python-cpp-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "python-cpp",
"Code1": "def printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n",
"Code2": "public : void printNos ( unsigned int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n cout << n << \" \" ;\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n\n"
},
{
"id": "python-cpp-PREFIX_SUM_2D_ARRAY",
"pair": "python-cpp",
"Code1": "def prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "void prefixSum2D ( int a [ ] [ C ] ) {\n int psa [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) {\n for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) cout << psa [ i ] [ j ] << \" \" ;\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-EULERIAN_NUMBER",
"pair": "python-cpp",
"Code1": "def eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n",
"Code2": "int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n\n"
},
{
"id": "python-cpp-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n",
"Code2": "long long int findSubarraySum ( int arr [ ] , int n ) {\n int res = 0 ;\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n m [ sum ] ++ ;\n }\n }\n for ( auto x : m ) if ( x . second == 1 ) res += x . first ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n\n"
},
{
"id": "python-cpp-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "python-cpp",
"Code1": "def isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n",
"Code2": "int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n ) {\n if ( n & 1 ) odd_count ++ ;\n if ( n & 2 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( abs ( odd_count - even_count ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n\n"
},
{
"id": "python-cpp-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "python-cpp",
"Code1": "def longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n",
"Code2": "int longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ n + 1 ] [ m + 1 ] ;\n int cnt [ n + 1 ] [ m + 1 ] ;\n memset ( lcs , 0 , sizeof ( lcs ) ) ;\n memset ( cnt , 0 , sizeof ( cnt ) ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n\n"
},
{
"id": "python-cpp-PROGRAM_AREA_SQUARE",
"pair": "python-cpp",
"Code1": "def areaSquare ( side ) :\n area = side * side\n return area\n",
"Code2": "int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef areaSquare ( side ) :\n area = side * side\n return area\n\n"
},
{
"id": "python-cpp-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "python-cpp",
"Code1": "def findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n",
"Code2": "void findpath ( int graph [ ] [ 5 ] , int n ) {\n vector < int > numofadj ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . push_back ( accumulate ( graph [ i ] , graph [ i ] + 5 , 0 ) ) ;\n int startpoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj [ i ] % 2 == 1 ) {\n numofodd ++ ;\n startpoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n cout << \"No Solution\" << endl ;\n return ;\n }\n stack < int > stack ;\n vector < int > path ;\n int cur = startpoint ;\n while ( ! stack . empty ( ) or accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , graph [ cur ] + 5 , 0 ) == 0 ) {\n path . push_back ( cur ) ;\n cur = stack . top ( ) ;\n stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . push ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( auto ele : path ) cout << ele << \" -> \" ;\n cout << cur << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n\n"
},
{
"id": "python-cpp-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "python-cpp",
"Code1": "def lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n",
"Code2": "int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) return 0 ;\n if ( dp [ i ] [ j ] [ k ] != - 1 ) return dp [ i ] [ j ] [ k ] ;\n if ( X [ i ] == Y [ j ] && Y [ j ] == Z [ k ] ) return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n else return dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n\n"
},
{
"id": "python-cpp-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "python-cpp",
"Code1": "def findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n",
"Code2": "void findLarger ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n\n"
},
{
"id": "python-cpp-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "python-cpp",
"Code1": "def spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n",
"Code2": "int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n",
"Code2": "int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n\n"
},
{
"id": "python-cpp-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "python-cpp",
"Code1": "def sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n",
"Code2": "int sumBetweenTwoKth ( int arr [ ] , int n , int k1 , int k2 ) {\n sort ( arr , arr + n ) ;\n return accumulate ( arr + k1 , arr + k2 - 1 , 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "python-cpp",
"Code1": "def calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n",
"Code2": "int calculate ( int a [ ] , int n ) {\n int * maximum = max_element ( a , a + 5 ) ;\n int frequency [ * maximum + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( * maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n\n"
},
{
"id": "python-cpp-DOUBLE_FACTORIAL_1",
"pair": "python-cpp",
"Code1": "def doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n",
"Code2": "unsigned int doublefactorial ( unsigned int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n\n"
},
{
"id": "python-cpp-LONGEST_COMMON_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"Code2": "int lcs ( char * X , char * Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n\n"
},
{
"id": "python-cpp-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "python-cpp",
"Code1": "def maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n",
"Code2": "int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) return 0 ;\n if ( count_neg & 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) return 0 ;\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n\n"
},
{
"id": "python-cpp-TEMPLE_OFFERINGS",
"pair": "python-cpp",
"Code1": "def offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n",
"Code2": "int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n\n"
},
{
"id": "python-cpp-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "python-cpp",
"Code1": "def SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n",
"Code2": "int sumNodes ( int l ) {\n int leafNodeCount = pow ( 2 , l - 1 ) ;\n vector < int > vec [ l ] ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec [ l - 1 ] . push_back ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec [ i + 1 ] . size ( ) - 1 ) {\n vec [ i ] . push_back ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec [ i ] . size ( ) ;\n j ++ ) sum += vec [ i ] [ j ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n\n"
},
{
"id": "python-cpp-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "python-cpp",
"Code1": "def constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n",
"Code2": "string constructPalin ( string str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != '*' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == '*' ) {\n str [ i ] = 'a' ;\n str [ j ] = 'a' ;\n continue ;\n }\n else if ( str [ i ] == '*' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == '*' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n cout << \"Not Possible\" ;\n return \"\" ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n\n"
},
{
"id": "python-cpp-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "python-cpp",
"Code1": "def countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n\n"
},
{
"id": "python-cpp-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "python-cpp",
"Code1": "def russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n",
"Code2": "unsigned int russianPeasant ( unsigned int a , unsigned int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( b & 1 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n\n"
},
{
"id": "python-cpp-CAESAR_CIPHER",
"pair": "python-cpp",
"Code1": "def encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n",
"Code2": "string encrypt ( string text , int s ) {\n string result = \"\" ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( isupper ( text [ i ] ) ) result += char ( int ( text [ i ] + s - 65 ) % 26 + 65 ) ;\n else result += char ( int ( text [ i ] + s - 97 ) % 26 + 97 ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n\n"
},
{
"id": "python-cpp-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "python-cpp",
"Code1": "def distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n",
"Code2": "long double distance ( long double lat1 , long double long1 , long double lat2 , long double long2 ) {\n lat1 = toRadians ( lat1 ) ;\n long1 = toRadians ( long1 ) ;\n lat2 = toRadians ( lat2 ) ;\n long2 = toRadians ( long2 ) ;\n long double dlong = long2 - long1 ;\n long double dlat = lat2 - lat1 ;\n long double ans = pow ( sin ( dlat / 2 ) , 2 ) + cos ( lat1 ) * cos ( lat2 ) * pow ( sin ( dlong / 2 ) , 2 ) ;\n ans = 2 * asin ( sqrt ( ans ) ) ;\n long double R = 6371 ;\n ans = ans * R ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n\n"
},
{
"id": "python-cpp-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "python-cpp",
"Code1": "def evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n",
"Code2": "long int evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n\n"
},
{
"id": "python-cpp-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "python-cpp",
"Code1": "def gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a",
"Code2": "int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a\n"
},
{
"id": "python-cpp-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "python-cpp",
"Code1": "def isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n",
"Code2": "bool isPowerOfTwo ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return 0 ;\n n = n / 2 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n\n"
},
{
"id": "python-cpp-SUM_PAIRWISE_PRODUCTS",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n",
"Code2": "long long int findSum ( int n ) {\n long long int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n\n"
},
{
"id": "python-cpp-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "python-cpp",
"Code1": "def binomialCoeffSum ( n ) :\n return ( 1 << n )\n",
"Code2": "int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binomialCoeffSum ( n ) :\n return ( 1 << n )\n\n"
},
{
"id": "python-cpp-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "python-cpp",
"Code1": "def calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n",
"Code2": "int calculateSum ( string arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n string s = arr [ 0 ] ;\n int value = stoi ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n int value = stoi ( s ) ;\n char operation = arr [ i - 1 ] [ 0 ] ;\n if ( operation == '+' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "python-cpp",
"Code1": "def checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n",
"Code2": "void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n float polarradius = sqrt ( x * x + y * y ) ;\n float Angle = atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) printf ( \"Point (%d, %d) exist in the circle sector\\n\" , x , y ) ;\n else printf ( \"Point (%d, %d) does not exist in the circle sector\\n\" , x , y ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n\n"
},
{
"id": "python-cpp-PRINTING_ITEMS_01_KNAPSACK",
"pair": "python-cpp",
"Code1": "def printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n",
"Code2": "void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n printf ( \"%d\\n\" , res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n printf ( \"%d \" , wt [ i - 1 ] ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n\n"
},
{
"id": "python-cpp-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "python-cpp",
"Code1": "def getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n",
"Code2": "int getTotalNumberOfSequences ( int m , int n ) {\n int T [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n",
"Code2": "int findSum ( int n ) {\n int arr [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n\n"
},
{
"id": "python-cpp-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "python-cpp",
"Code1": "def replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n",
"Code2": "string replace ( string s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( s [ i ] == c1 ) s [ i ] = c2 ;\n else if ( s [ i ] == c2 ) s [ i ] = c1 ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n\n"
},
{
"id": "python-cpp-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "python-cpp",
"Code1": "def discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n",
"Code2": "int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) sqrt ( m ) + 1 ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n unordered_map < int , int > value ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( ! value [ cur ] ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "python-cpp",
"Code1": "def maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n",
"Code2": "long long maxPrimeFactors ( long long n ) {\n long long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n\n"
},
{
"id": "python-cpp-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "python-cpp",
"Code1": "def isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n",
"Code2": "bool isPossibleTriangle ( int arr [ ] , int N ) {\n if ( N < 3 ) return false ;\n sort ( arr , arr + N ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "python-cpp",
"Code1": "def numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n",
"Code2": "int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ k ] [ n ] , sum = 0 ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) sum += dp [ k - 1 ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n\n"
},
{
"id": "python-cpp-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "python-cpp",
"Code1": "def solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n",
"Code2": "int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ N ] [ N ] ) {\n if ( ! k ) return 0 ;\n if ( l < 0",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n\n"
},
{
"id": "python-cpp-REMAINDER_7_LARGE_NUMBERS",
"pair": "python-cpp",
"Code1": "def remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n",
"Code2": "int remainderWith7 ( string num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . size ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num [ i ] - '0' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n\n"
},
{
"id": "python-cpp-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "python-cpp",
"Code1": "def isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n",
"Code2": "bool isSubSequence ( char str1 [ ] , char str2 [ ] , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 [ m - 1 ] == str2 [ n - 1 ] ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "python-cpp",
"Code1": "def getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n",
"Code2": "int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n\n"
},
{
"id": "python-cpp-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "python-cpp",
"Code1": "def minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n",
"Code2": "int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int max_neg = INT_MIN ;\n int min_pos = INT_MAX ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = max ( max_neg , a [ i ] ) ;\n }\n if ( a [ i ] > 0 ) min_pos = min ( min_pos , a [ i ] ) ;\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return min_pos ;\n if ( ! ( count_neg & 1 ) && count_neg != 0 ) {\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n\n"
},
{
"id": "python-cpp-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "python-cpp",
"Code1": "def getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n",
"Code2": "public : int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n\n"
},
{
"id": "python-cpp-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "python-cpp",
"Code1": "def findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n",
"Code2": "int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += log10 ( i ) ;\n return floor ( digits ) + 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n\n"
},
{
"id": "python-cpp-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "python-cpp",
"Code1": "def mergeTwoHalf ( A , n ) :\n A.sort ( )\n",
"Code2": "void mergeTwoHalf ( int A [ ] , int n ) {\n sort ( A , A + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef mergeTwoHalf ( A , n ) :\n A.sort ( )\n\n"
},
{
"id": "python-cpp-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "python-cpp",
"Code1": "def fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ m ] [ n ] ;\n char x = 'X' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == '0' ) ? 'X' : '0' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) printf ( \"%c \" , a [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "python-cpp",
"Code1": "def minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n",
"Code2": "int minPerimeter ( int n ) {\n int l = sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long long int row = n / l ;\n long long int perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n\n"
},
{
"id": "python-cpp-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "python-cpp",
"Code1": "def possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n",
"Code2": "void possibleOrNot ( long long a1 , long long a2 , long long b1 , long long b2 , long long c1 , long long c2 ) {\n long long dis1 = pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) ;\n long long dis2 = pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) cout << \"No\" ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) cout << \"No\" ;\n else cout << \"Yes\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_SLOPE_LINE",
"pair": "python-cpp",
"Code1": "def slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n",
"Code2": "float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "python-cpp",
"Code1": "def CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n",
"Code2": "int countSquares ( int a , int b ) {\n return ( floor ( sqrt ( b ) ) - ceil ( sqrt ( a ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n\n"
},
{
"id": "python-cpp-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "python-cpp",
"Code1": "def countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n",
"Code2": "int countStrings ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] [ 2 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n\n"
},
{
"id": "python-cpp-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "python-cpp",
"Code1": "def findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n",
"Code2": "void findSmallestRange ( int arr [ ] [ N ] , int n , int k ) {\n int i , minval , maxval , minrange , minel , maxel , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) ptr [ i ] = 0 ;\n minrange = INT_MAX ;\n while ( 1 ) {\n minind = - 1 ;\n minval = INT_MAX ;\n maxval = INT_MIN ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag ) break ;\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "python-cpp",
"Code1": "def lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n",
"Code2": "string lexicographicSubConcat ( string s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n string arr [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) arr [ index ++ ] = s . substr ( i , len ) ;\n sort ( arr , arr + sub_count ) ;\n string res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "python-cpp",
"Code1": "def maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n",
"Code2": "void maxelement ( int no_of_rows , int arr [ ] [ N ] ) {\n int i = 0 ;\n int max = 0 ;\n int result [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result , no_of_rows ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n\n"
},
{
"id": "python-cpp-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "python-cpp",
"Code1": "def countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n",
"Code2": "int countNegative ( int M [ ] [ 4 ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n\n"
},
{
"id": "python-cpp-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "python-cpp",
"Code1": "def findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n",
"Code2": "int findpos ( string n ) {\n int i = 0 , pos = 0 ;\n while ( n [ i ] != '\\0' ) {\n switch ( n [ i ] ) {\n case '4' : pos = pos * 2 + 1 ;\n break ;\n case '7' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n\n"
},
{
"id": "python-cpp-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "python-cpp",
"Code1": "def yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n",
"Code2": "long long int yMod ( long long int y , long long int x ) {\n if ( log2 ( y ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << x ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n",
"Code2": "int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n\n"
},
{
"id": "python-cpp-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "python-cpp",
"Code1": "def maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n",
"Code2": "int maxLength ( char s [ ] , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == '(' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n\n"
},
{
"id": "python-cpp-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n",
"Code2": "ll lis ( ll arr [ ] , ll n ) {\n ll mpis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n return * max_element ( mpis , mpis + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n\n"
},
{
"id": "python-cpp-PETERSON_GRAPH",
"pair": "python-cpp",
"Code1": "def findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n",
"Code2": "bool findthepath ( char * S , int v ) {\n result [ 0 ] = v + '0' ;\n for ( int i = 1 ;\n S [ i ] ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - 'A' ] || adj [ S [ i ] - 'A' ] [ v ] ) {\n v = S [ i ] - 'A' ;\n }\n else if ( adj [ v ] [ S [ i ] - 'A' + 5 ] || adj [ S [ i ] - 'A' + 5 ] [ v ] ) {\n v = S [ i ] - 'A' + 5 ;\n }\n else return false ;\n result [ i ] = v + '0' ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n\n"
},
{
"id": "python-cpp-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "python-cpp",
"Code1": "def checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n",
"Code2": "bool checkSorted ( int n , queue < int > & q ) {\n stack < int > st ;\n int expected = 1 ;\n int fnt ;\n while ( ! q . empty ( ) ) {\n fnt = q . front ( ) ;\n q . pop ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . empty ( ) ) {\n st . push ( fnt ) ;\n }\n else if ( ! st . empty ( ) && st . top ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( ! st . empty ( ) && st . top ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . empty ( ) ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "python-cpp",
"Code1": "def generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n",
"Code2": "void generate ( set < string > & st , string s ) {\n if ( s . size ( ) == 0 ) return ;\n if ( st . find ( s ) == st . end ( ) ) {\n st . insert ( s ) ;\n for ( int i = 0 ;\n i < s . size ( ) ;\n i ++ ) {\n string t = s ;\n t . erase ( i , 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n\n"
},
{
"id": "python-cpp-RECURSIVE_FUNCTIONS",
"pair": "python-cpp",
"Code1": "def tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n",
"Code2": "void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n cout << \"Move the disk \" << n << \" from \" << sourcePole << \" to \" << destinationPole << endl ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n\n"
},
{
"id": "python-cpp-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "python-cpp",
"Code1": "def findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n",
"Code2": "int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "python-cpp",
"Code1": "def minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n",
"Code2": "string minLexRotation ( string str ) {\n int n = str . length ( ) ;\n string arr [ n ] ;\n string concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = concat . substr ( i , n ) ;\n sort ( arr , arr + n ) ;\n return arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "python-cpp",
"Code1": "def findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n",
"Code2": "int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return INT_MAX ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n\n"
},
{
"id": "python-cpp-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "python-cpp",
"Code1": "def octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n",
"Code2": "int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n\n"
},
{
"id": "python-cpp-FIND_THE_MISSING_NUMBER",
"pair": "python-cpp",
"Code1": "def getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n",
"Code2": "int getMissingNo ( int a [ ] , int n ) {\n int total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n\n"
},
{
"id": "python-cpp-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "python-cpp",
"Code1": "def printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n",
"Code2": "void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n cout << square << \" \" ;\n prev_x = x ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n\n"
},
{
"id": "python-cpp-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "python-cpp",
"Code1": "def isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n",
"Code2": "bool isPossible ( int a [ ] , int b [ ] , int n , int k ) {\n sort ( a , a + n ) ;\n sort ( b , b + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "python-cpp",
"Code1": "def fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n",
"Code2": "void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = sqrt ( pow ( x , 2 ) + pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) cout << \"Fits\\n\" ;\n else cout << \"Doesn't Fit\\n\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n\n"
},
{
"id": "python-cpp-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "python-cpp",
"Code1": "def findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n",
"Code2": "int findPosition ( int k , int n ) {\n unsigned long long int f1 = 0 , f2 = 1 , f3 ;\n for ( int i = 2 ;\n i <= MAX ;\n i ++ ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) return n * i ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n\n"
},
{
"id": "python-cpp-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "python-cpp",
"Code1": "def sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n",
"Code2": "void sequence ( int n ) {\n int f [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n cout << f [ 1 ] << \" \" << f [ 2 ] << \" \" ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n cout << f [ i ] << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "python-cpp",
"Code1": "def countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n",
"Code2": "int countManipulations ( string s1 , string s2 ) {\n int count = 0 ;\n int char_count [ 26 ] ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) {\n char_count [ i ] = 0 ;\n }\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) {\n char_count [ s2 [ i ] - 'a' ] -- ;\n if ( char_count [ s2 [ i ] - 'a' ] < 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "python-cpp",
"Code1": "def count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n",
"Code2": "int count ( int n ) {\n int table [ n + 1 ] , i ;\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) table [ j ] = 0 ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n\n"
},
{
"id": "python-cpp-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "python-cpp",
"Code1": "def maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n",
"Code2": "int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n\n"
},
{
"id": "python-cpp-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n",
"Code2": "int findLongestRepeatingSubSeq ( string str ) {\n int n = str . length ( ) ;\n int dp [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "python-cpp",
"Code1": "def isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n",
"Code2": "bool isCornerPresent ( string str , string corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substr ( 0 , cl ) . compare ( corner ) == 0 && str . substr ( n - cl , cl ) . compare ( corner ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n\n"
},
{
"id": "python-cpp-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "python-cpp",
"Code1": "def getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n",
"Code2": "int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n\n"
},
{
"id": "python-cpp-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "python-cpp",
"Code1": "def countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n",
"Code2": "int countZeroes ( int mat [ N ] [ N ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n\n"
},
{
"id": "python-cpp-JUMP_SEARCH",
"pair": "python-cpp",
"Code1": "def jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n",
"Code2": "int jumpSearch ( int arr [ ] , int x , int n ) {\n int step = sqrt ( n ) ;\n int prev = 0 ;\n while ( arr [ min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += sqrt ( n ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_X_Y_SATISFYING_AX_N",
"pair": "python-cpp",
"Code1": "def solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n",
"Code2": "void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n cout << \"x = \" << i << \", y = \" << ( n - ( i * a ) ) / b ;\n return ;\n }\n }\n cout << \"No solution\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n\n"
},
{
"id": "python-cpp-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "python-cpp",
"Code1": "def longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n",
"Code2": "string longDivision ( string number , int divisor ) {\n string ans ;\n int idx = 0 ;\n int temp = number [ idx ] - '0' ;\n while ( temp < divisor ) temp = temp * 10 + ( number [ ++ idx ] - '0' ) ;\n while ( number . size ( ) > idx ) {\n ans += ( temp / divisor ) + '0' ;\n temp = ( temp % divisor ) * 10 + number [ ++ idx ] - '0' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n\n"
},
{
"id": "python-cpp-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "python-cpp",
"Code1": "def sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n",
"Code2": "void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : swap ( a [ lo ++ ] , a [ mid ++ ] ) ;\n break ;\n case 1 : mid ++ ;\n break ;\n case 2 : swap ( a [ mid ] , a [ hi -- ] ) ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n\n"
},
{
"id": "python-cpp-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "python-cpp",
"Code1": "def canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n",
"Code2": "bool canRepresentBST ( int pre [ ] , int n ) {\n stack < int > s ;\n int root = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) return false ;\n while ( ! s . empty ( ) && s . top ( ) < pre [ i ] ) {\n root = s . top ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n\n"
},
{
"id": "python-cpp-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "python-cpp",
"Code1": "def find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n",
"Code2": "int find ( bool arr [ n ] [ n ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == 0 ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == 0 || i == j ) ) j -- ;\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else i ++ ;\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == 1 || i == j ) ) i ++ ;\n if ( i == n ) {\n res = j ;\n break ;\n }\n else j -- ;\n }\n }\n if ( res == - 1 ) return res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( res != i && arr [ i ] [ res ] != 1 ) return - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( res != j && arr [ res ] [ j ] != 0 ) return - 1 ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n\n"
},
{
"id": "python-cpp-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "python-cpp",
"Code1": "def printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n",
"Code2": "void printArray ( int * a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << a [ i ] << \" \" ;\n cout << endl ;\n return ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "python-cpp",
"Code1": "def sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n",
"Code2": "void sortSquares ( int arr [ ] , int n ) {\n int K = 0 ;\n for ( K = 0 ;\n K < n ;\n K ++ ) if ( arr [ K ] >= 0 ) break ;\n int i = K - 1 ;\n int j = K ;\n int ind = 0 ;\n int temp [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n ind ++ ;\n }\n while ( j < n ) {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n ind ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n\n"
},
{
"id": "python-cpp-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "python-cpp",
"Code1": "def find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n",
"Code2": "int find_maximum ( int a [ ] , int n , int k ) {\n unordered_map < int , int > b ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = min ( 1 + i , n - i ) ;\n if ( b . find ( x ) == b . end ( ) ) b [ x ] = d ;\n else b [ x ] = min ( d , b [ x ] ) ;\n }\n int ans = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . find ( k - x ) != b . end ( ) ) ans = min ( max ( b [ x ] , b [ k - x ] ) , ans ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n\n"
},
{
"id": "python-cpp-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "python-cpp",
"Code1": "def maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n",
"Code2": "char maxRepeating ( string str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str [ 0 ] ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str [ i ] == str [ i + 1 ] ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str [ i ] ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n\n"
},
{
"id": "python-cpp-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "python-cpp",
"Code1": "def solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n",
"Code2": "int solveQuery ( int start , int end , int arr [ ] ) {\n unordered_map < int , int > frequency ;\n for ( int i = start ;\n i <= end ;\n i ++ ) frequency [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto x : frequency ) if ( x . first == x . second ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "python-cpp",
"Code1": "def Circumference ( a ) :\n return ( 4 * a )\n",
"Code2": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef Circumference ( a ) :\n return ( 4 * a )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "python-cpp",
"Code1": "def numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n\n"
},
{
"id": "python-cpp-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "python-cpp",
"Code1": "def pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n",
"Code2": "void pointClip ( int XY [ ] [ 2 ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n cout << \"Point inside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n }\n cout << \"\\n\" << endl ;\n cout << \"Point outside the viewing pane:\" << endl ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) cout << \"[\" << XY [ i ] [ 0 ] << \",\" << XY [ i ] [ 1 ] << \"] \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "python-cpp",
"Code1": "def pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n",
"Code2": "ll pre_compute ( ll a [ ] , ll n , ll index , ll k ) {\n ll dp [ n ] [ n ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n\n"
},
{
"id": "python-cpp-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "python-cpp",
"Code1": "def splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n",
"Code2": "void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n\n"
},
{
"id": "python-cpp-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "python-cpp",
"Code1": "def smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n",
"Code2": "int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n\n"
},
{
"id": "python-cpp-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "python-cpp",
"Code1": "def winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n",
"Code2": "int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n\n"
},
{
"id": "python-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "python-cpp",
"Code1": "def divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n",
"Code2": "bool divisibleBy20 ( string num ) {\n int lastTwoDigits = stoi ( num . substr ( num . length ( ) - 2 , num . length ( ) - 1 ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n\n"
},
{
"id": "python-cpp-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "python-cpp",
"Code1": "def countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n",
"Code2": "int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "python-cpp",
"Code1": "def CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n",
"Code2": "void CountTriangles ( vector < int > A ) {\n int n = A . size ( ) ;\n sort ( A . begin ( ) , A . end ( ) ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else l ++ ;\n }\n }\n cout << \"No of possible solutions: \" << count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n\n"
},
{
"id": "python-cpp-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "python-cpp",
"Code1": "def snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit",
"Code2": "uint_t snoob ( uint_t x ) {\n uint_t rightOne ;\n uint_t nextHigherOneBit ;\n uint_t rightOnesPattern ;\n uint_t next = 0 ;\n if ( x ) {\n rightOne = x & - ( signed ) x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit\n"
},
{
"id": "python-cpp-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "python-cpp",
"Code1": "def isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "bool isInorder ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"Code2": "int lis ( int arr [ ] , int n ) {\n int max = 1 ;\n _lis ( arr , n , & max ) ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "python-cpp",
"Code1": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n",
"Code2": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = INT_MIN ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n\n"
},
{
"id": "python-cpp-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n",
"Code2": "void countFreq ( int a [ ] , int n ) {\n unordered_map < int , int > hm ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n set < pair < int , int >> st ;\n for ( auto x : hm ) {\n st . insert ( {\n x . first , x . second }\n ) ;\n }\n int cumul = 0 ;\n for ( auto x : st ) {\n cumul += x . second ;\n cout << x . first << \" \" << cumul << endl ;\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n\n"
},
{
"id": "python-cpp-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "python-cpp",
"Code1": "def nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n",
"Code2": "int nCrModp ( int n , int r , int p ) {\n int C [ r + 1 ] ;\n memset ( C , 0 , sizeof ( C ) ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n\n"
},
{
"id": "python-cpp-COCKTAIL_SORT",
"pair": "python-cpp",
"Code1": "def cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n",
"Code2": "void CocktailSort ( int a [ ] , int n ) {\n bool swapped = true ;\n int start = 0 ;\n int end = n - 1 ;\n while ( swapped ) {\n swapped = false ;\n for ( int i = start ;\n i < end ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n if ( ! swapped ) break ;\n swapped = false ;\n -- end ;\n for ( int i = end - 1 ;\n i >= start ;\n -- i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n swap ( a [ i ] , a [ i + 1 ] ) ;\n swapped = true ;\n }\n }\n ++ start ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n\n"
},
{
"id": "python-cpp-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "python-cpp",
"Code1": "def solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n",
"Code2": "void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ n ] ;\n int ans [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = INT_MAX ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n cout << i + 1 << \" \" << ans [ i ] + 1 << \" \" ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n\n"
},
{
"id": "python-cpp-BINARY_SEARCH_1",
"pair": "python-cpp",
"Code1": "def binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n\n"
},
{
"id": "python-cpp-MINIMUM_XOR_VALUE_PAIR",
"pair": "python-cpp",
"Code1": "def minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n",
"Code2": "int minXOR ( int arr [ ] , int n ) {\n int min_xor = INT_MAX ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n\n"
},
{
"id": "python-cpp-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "python-cpp",
"Code1": "def sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n",
"Code2": "int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 , curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n\n"
},
{
"id": "python-cpp-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "python-cpp",
"Code1": "def first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n",
"Code2": "char first ( string str , int i = 0 ) {\n if ( str [ i ] == '\\0' ) return 0 ;\n if ( isupper ( str [ i ] ) ) return str [ i ] ;\n return first ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n\n"
},
{
"id": "python-cpp-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "python-cpp",
"Code1": "def maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n",
"Code2": "int maxGameByWinner ( int N ) {\n int dp [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n\n"
},
{
"id": "python-cpp-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n\n"
},
{
"id": "python-cpp-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "python-cpp",
"Code1": "def procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n",
"Code2": "double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n\n"
},
{
"id": "python-cpp-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "python-cpp",
"Code1": "def rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n",
"Code2": "void rearrange ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int small = 0 , large = n - 1 ;\n int flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n\n"
},
{
"id": "python-cpp-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "python-cpp",
"Code1": "def greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n",
"Code2": "void greatest ( string s ) {\n int n = s . length ( ) ;\n int a [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s [ i ] - '0' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 ) {\n if ( a [ n - 2 ] % 2 != 0 or ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n cout << \"-1\" << endl ;\n }\n else {\n cout << n << endl ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) cout << - 1 << endl ;\n else {\n cout << del + 1 << endl ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n\n"
},
{
"id": "python-cpp-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "python-cpp",
"Code1": "def isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n",
"Code2": "int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n\n"
},
{
"id": "python-cpp-LONGEST_COMMON_SUBSTRING",
"pair": "python-cpp",
"Code1": "def LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n",
"Code2": "int LCSubStr ( char * X , char * Y , int m , int n ) {\n int LCSuff [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCSuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = max ( result , LCSuff [ i ] [ j ] ) ;\n }\n else LCSuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "python-cpp",
"Code1": "def maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n",
"Code2": "int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n\n"
},
{
"id": "python-cpp-FIBONACCI_MODULO_P",
"pair": "python-cpp",
"Code1": "def findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n",
"Code2": "int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n\n"
},
{
"id": "python-cpp-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "python-cpp",
"Code1": "def reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n",
"Code2": "void reorder ( int arr [ ] , int index [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n\n"
},
{
"id": "python-cpp-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "python-cpp",
"Code1": "def longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n",
"Code2": "int longestNull ( string str ) {\n vector < pair < char , int >> arr ;\n arr . push_back ( {\n '@' , - 1 }\n ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . push_back ( {\n str [ i ] , i }\n ) ;\n while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n arr . pop_back ( ) ;\n }\n int tmp = arr . back ( ) . second ;\n maxlen = max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n\n"
},
{
"id": "python-cpp-SUM_FIBONACCI_NUMBERS",
"pair": "python-cpp",
"Code1": "def calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n",
"Code2": "int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ n + 1 ] ;\n fibo [ 0 ] = 0 , fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n\n"
},
{
"id": "python-cpp-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "python-cpp",
"Code1": "def shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n",
"Code2": "INT_MAX int shortestPath ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n\n"
},
{
"id": "python-cpp-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "python-cpp",
"Code1": "def sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n",
"Code2": "int sumofsquare ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n\n"
},
{
"id": "python-cpp-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "python-cpp",
"Code1": "def constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n",
"Code2": "void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n\n"
},
{
"id": "python-cpp-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "python-cpp",
"Code1": "def patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n",
"Code2": "int patternCount ( string str ) {\n char last = str [ 0 ] ;\n int i = 1 , counter = 0 ;\n while ( i < str . size ( ) ) {\n if ( str [ i ] == '0' && last == '1' ) {\n while ( str [ i ] == '0' ) i ++ ;\n if ( str [ i ] == '1' ) counter ++ ;\n }\n last = str [ i ] ;\n i ++ ;\n }\n return counter ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n\n"
},
{
"id": "python-cpp-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "python-cpp",
"Code1": "def findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n",
"Code2": "int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i <= right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "python-cpp",
"Code1": "def parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n",
"Code2": "void parabola ( float a , float b , float c ) {\n cout << \"Vertex: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Focus: (\" << ( - b / ( 2 * a ) ) << \", \" << ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) << \")\" << endl ;\n cout << \"Directrix: y=\" << c - ( ( b * b ) + 1 ) * 4 * a << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n\n"
},
{
"id": "python-cpp-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "python-cpp",
"Code1": "def minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n",
"Code2": "int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n\n"
},
{
"id": "python-cpp-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "python-cpp",
"Code1": "def longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n",
"Code2": "void longestSubseqWithK ( string str , int k ) {\n int n = str . size ( ) ;\n int freq [ MAX_CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ str [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( freq [ str [ i ] - 'a' ] >= k ) cout << str [ i ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n\n"
},
{
"id": "python-cpp-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "python-cpp",
"Code1": "def pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n",
"Code2": "int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n\n"
},
{
"id": "python-cpp-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "python-cpp",
"Code1": "def middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n",
"Code2": "int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n\n"
},
{
"id": "python-cpp-NEXT_POWER_OF_2",
"pair": "python-cpp",
"Code1": "def nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n unsigned count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "python-cpp",
"Code1": "def maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n",
"Code2": "int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n\n"
},
{
"id": "python-cpp-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "python-cpp",
"Code1": "def reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n",
"Code2": "void reverse ( char str [ ] ) {\n int n = strlen ( str ) , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) swap ( & str [ i ] , & str [ n - i - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n\n"
},
{
"id": "python-cpp-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "python-cpp",
"Code1": "def nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n",
"Code2": "string nextWord ( string s ) {\n if ( s == \"\" ) return \"a\" ;\n int i = s . length ( ) - 1 ;\n while ( s [ i ] == 'z' && i >= 0 ) i -- ;\n if ( i == - 1 ) s = s + 'a' ;\n else s [ i ] ++ ;\n return s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n\n"
},
{
"id": "python-cpp-SUM_BINOMIAL_COEFFICIENTS",
"pair": "python-cpp",
"Code1": "def binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n",
"Code2": "int binomialCoeffSum ( int n ) {\n int C [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "python-cpp",
"Code1": "def isEven ( n ) :\n return ( n % 2 == 0 )\n",
"Code2": "bool isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isEven ( n ) :\n return ( n % 2 == 0 )\n\n"
},
{
"id": "python-cpp-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n",
"Code2": "int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n\n"
},
{
"id": "python-cpp-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "python-cpp",
"Code1": "def MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n",
"Code2": "void maxMin ( int arr [ ] [ MAX ] , int n ) {\n int min = INT_MAX ;\n int max = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n cout << \"Maximum = \" << max ;\n << \", Minimum = \" << min ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n\n"
},
{
"id": "python-cpp-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "python-cpp",
"Code1": "def isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n",
"Code2": "int bool isPowerOfTwo ( int x ) {\n return x && ( ! ( x & ( x - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n\n"
},
{
"id": "python-cpp-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "python-cpp",
"Code1": "def countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n",
"Code2": "int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n\n"
},
{
"id": "python-cpp-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "python-cpp",
"Code1": "def isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n",
"Code2": "bool isRectangle ( const vector < vector < int >> & matrix ) {\n int rows = matrix . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . size ( ) ;\n unordered_map < int , unordered_set < int >> table ;\n for ( int i = 0 ;\n i < rows ;\n ++ i ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n ++ j ) {\n for ( int k = j + 1 ;\n k < columns ;\n ++ k ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . find ( j ) != table . end ( ) && table [ j ] . find ( k ) != table [ j ] . end ( ) ) return true ;\n table [ j ] . insert ( k ) ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n\n"
},
{
"id": "python-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "python-cpp",
"Code1": "def decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n",
"Code2": "void decToBinary ( int n ) {\n int binaryNum [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << binaryNum [ j ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n\n"
},
{
"id": "python-cpp-FRIENDS_PAIRING_PROBLEM_1",
"pair": "python-cpp",
"Code1": "def countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n",
"Code2": "int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "python-cpp",
"Code1": "def maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n",
"Code2": "int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = numeric_limits < int > :: min ( ) ;\n int prefix_sum [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n\n"
},
{
"id": "python-cpp-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "python-cpp",
"Code1": "def countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n",
"Code2": "int countOccurrences ( string s , int K ) {\n int n = s . length ( ) ;\n int C , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == 'a' ) c1 ++ ;\n if ( s [ i ] == 'b' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n\n"
},
{
"id": "python-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "python-cpp",
"Code1": "def checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n",
"Code2": "bool checkDivisibility ( string num ) {\n int length = num . size ( ) ;\n if ( length == 1 && num [ 0 ] == '0' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n\n"
},
{
"id": "python-cpp-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "python-cpp",
"Code1": "def countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n",
"Code2": "int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n\n"
},
{
"id": "python-cpp-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "python-cpp",
"Code1": "def countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n",
"Code2": "public : unsigned int countSetBits ( int n ) {\n unsigned int count = 0 ;\n while ( n ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "python-cpp",
"Code1": "def lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n",
"Code2": "int lenOfLongSubarr ( int arr [ ] , int n ) {\n unordered_map < int , int > um ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ;\n if ( um . find ( sum - 1 ) != um . end ( ) ) {\n if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ;\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n\n"
},
{
"id": "python-cpp-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "python-cpp",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n",
"Code2": "int minJumps ( int arr [ ] , int n ) {\n if ( n == 1 ) return 0 ;\n int res = INT_MAX ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + arr [ i ] >= n - 1 ) {\n int sub_res = minJumps ( arr , i + 1 ) ;\n if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n\n"
},
{
"id": "python-cpp-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "python-cpp",
"Code1": "def minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n",
"Code2": "int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ N + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n\n"
},
{
"id": "python-cpp-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "python-cpp",
"Code1": "def carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "void carveCross ( string str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n cout << \"Not possible. Please enter \" << \"odd length string.\\n\" ;\n }\n else {\n char arr [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = 'X' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n cout << arr [ i ] [ j ] << \" \" ;\n }\n cout << \"\\n\" ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "python-cpp",
"Code1": "def sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n",
"Code2": "int sumoflength ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && s . find ( arr [ j ] ) == s . end ( ) ) {\n s . insert ( arr [ j ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . erase ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n\n"
},
{
"id": "python-cpp-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "python-cpp",
"Code1": "def findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n",
"Code2": "void findTriplets ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n unordered_set < int > s ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . find ( x ) != s . end ( ) ) {\n printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else s . insert ( arr [ j ] ) ;\n }\n }\n if ( found == false ) cout << \" No Triplet Found\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n\n"
},
{
"id": "python-cpp-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "python-cpp",
"Code1": "def maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n",
"Code2": "int maxPrefix ( char s [ ] , char t [ ] ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < strlen ( t ) ;\n i ++ ) {\n if ( count == strlen ( s ) ) break ;\n if ( t [ i ] == s [ count ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "python-cpp",
"Code1": "def segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n",
"Code2": "void segregateElements ( int arr [ ] , int n ) {\n int temp [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n memcpy ( arr , temp , sizeof ( temp ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n\n"
},
{
"id": "python-cpp-MERGING_INTERVALS",
"pair": "python-cpp",
"Code1": "def mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n",
"Code2": "void mergeIntervals ( Interval arr [ ] , int n ) {\n sort ( arr , arr + n , mycomp ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ index ] . e >= arr [ i ] . s ) {\n arr [ index ] . e = max ( arr [ index ] . e , arr [ i ] . e ) ;\n arr [ index ] . s = min ( arr [ index ] . s , arr [ i ] . s ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n cout << \"\\n The Merged Intervals are: \" ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) cout << \"[\" << arr [ i ] . s << \", \" << arr [ i ] . e << \"] \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "python-cpp",
"Code1": "def correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n",
"Code2": "float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ;\n return corr ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n\n"
},
{
"id": "python-cpp-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "python-cpp",
"Code1": "def findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n",
"Code2": "int findArea ( int arr [ ] , int n ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n int dimension [ 2 ] = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n\n"
},
{
"id": "python-cpp-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "python-cpp",
"Code1": "def minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n",
"Code2": "int minOps ( int arr [ ] , int n , int k ) {\n int max = * max_element ( arr , arr + n ) ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n\n"
},
{
"id": "python-cpp-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "python-cpp",
"Code1": "def floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n",
"Code2": "int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "python-cpp",
"Code1": "def isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n",
"Code2": "int isdivisible7 ( char num [ ] ) {\n int n = strlen ( num ) , gSum ;\n if ( n == 0 && num [ 0 ] == '\\n' ) return 1 ;\n if ( n % 3 == 1 ) {\n strcat ( num , \"00\" ) ;\n n += 2 ;\n }\n else if ( n % 3 == 2 ) {\n strcat ( num , \"0\" ) ;\n n ++ ;\n }\n int i , GSum = 0 , p = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num [ i -- ] - '0' ;\n group += ( num [ i -- ] - '0' ) * 10 ;\n group += ( num [ i ] - '0' ) * 100 ;\n gSum = gSum + group * p ;\n p *= ( - 1 ) ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n\n"
},
{
"id": "python-cpp-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "python-cpp",
"Code1": "def printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n",
"Code2": "void printMat ( int degseq [ ] , int n ) {\n int mat [ n ] [ n ] ;\n memset ( mat , 0 , sizeof ( mat ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n cout << \"\\n\" << setw ( 3 ) << \" \" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << setw ( 3 ) << \"(\" << i << \")\" ;\n cout << \"\\n\\n\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cout << setw ( 4 ) << \"(\" << i << \")\" ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) cout << setw ( 5 ) << mat [ i ] [ j ] ;\n cout << \"\\n\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n\n"
},
{
"id": "python-cpp-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "python-cpp",
"Code1": "def minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n",
"Code2": "int minTime ( int arr [ ] , int n , int m ) {\n int t = 0 ;\n while ( 1 ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n\n"
},
{
"id": "python-cpp-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "python-cpp",
"Code1": "def MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n",
"Code2": "long long int MaximumDecimalValue ( int mat [ ] [ N ] , int n ) {\n int dp [ n ] [ n ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n if ( mat [ 0 ] [ 0 ] == 1 ) dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + pow ( 2 , i ) ;\n else dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + pow ( 2 , i ) ;\n else dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + pow ( 2 , i + j ) ;\n else dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "python-cpp",
"Code1": "def isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n",
"Code2": "bool isDivisible999 ( string num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num [ 0 ] == '0' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num [ i ++ ] - '0' ) * 100 ;\n group += ( num [ i ++ ] - '0' ) * 10 ;\n group += num [ i ] - '0' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = to_string ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ;\n }\n return ( gSum == 999 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "python-cpp",
"Code1": "def maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n",
"Code2": "int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int msis [ n ] , msds [ n ] ;\n int max_sum = INT_MIN ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "python-cpp",
"Code1": "def findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n",
"Code2": "int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n\n"
},
{
"id": "python-cpp-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "python-cpp",
"Code1": "def rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n",
"Code2": "int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n\n"
},
{
"id": "python-cpp-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "python-cpp",
"Code1": "def assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n",
"Code2": "int assignValue ( int a , int b , bool x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n\n"
},
{
"id": "python-cpp-TRIANGULAR_NUMBERS",
"pair": "python-cpp",
"Code1": "def isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n",
"Code2": "bool isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n\n"
},
{
"id": "python-cpp-PANGRAM_CHECKING",
"pair": "python-cpp",
"Code1": "def checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n",
"Code2": "bool checkPangram ( string & str ) {\n vector < bool > mark ( 26 , false ) ;\n int index ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( 'A' <= str [ i ] && str [ i ] <= 'Z' ) index = str [ i ] - 'A' ;\n else if ( 'a' <= str [ i ] && str [ i ] <= 'z' ) index = str [ i ] - 'a' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n\n"
},
{
"id": "python-cpp-INTERPOLATION_SEARCH",
"pair": "python-cpp",
"Code1": "def interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n",
"Code2": "int interpolationSearch ( int arr [ ] , int n , int x ) {\n int lo = 0 , hi = ( n - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( double ) ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n\n"
},
{
"id": "python-cpp-FITTING_SHELVES_PROBLEM",
"pair": "python-cpp",
"Code1": "def minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n",
"Code2": "void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n cout << num_m << \" \" << num_n << \" \" << min_empty << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n\n"
},
{
"id": "python-cpp-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "python-cpp",
"Code1": "def findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n }\n return abs ( missingElement ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n\n"
},
{
"id": "python-cpp-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "python-cpp",
"Code1": "def kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void kLargest ( int arr [ ] , int n , int k ) {\n sort ( arr , arr + n , greater < int > ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "python-cpp",
"Code1": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n\n"
},
{
"id": "python-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "python-cpp",
"Code1": "def isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n",
"Code2": "bool isPowerOfFour ( unsigned int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ! ( n & 0xAAAAAAAA ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n\n"
},
{
"id": "python-cpp-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "python-cpp",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "python-cpp",
"Code1": "def findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n",
"Code2": "int findgroups ( int arr [ ] , int n ) {\n int c [ 3 ] = {\n 0 }\n , i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n\n"
},
{
"id": "python-cpp-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "python-cpp",
"Code1": "def kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n",
"Code2": "int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n priority_queue < int , vector < int > , greater < int >> Q ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . push ( x ) ;\n else {\n if ( Q . top ( ) < x ) {\n Q . pop ( ) ;\n Q . push ( x ) ;\n }\n }\n }\n }\n return Q . top ( ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n\n"
},
{
"id": "python-cpp-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "python-cpp",
"Code1": "def findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n",
"Code2": "int findMaxValue ( int mat [ ] [ N ] ) {\n int maxValue = INT_MIN ;\n int maxArr [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n\n"
},
{
"id": "python-cpp-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "python-cpp",
"Code1": "def kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n",
"Code2": "int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n\n"
},
{
"id": "python-cpp-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "python-cpp",
"Code1": "def printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void printDistinct ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . find ( arr [ i ] ) == s . end ( ) ) {\n s . insert ( arr [ i ] ) ;\n cout << arr [ i ] << \" \" ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "python-cpp",
"Code1": "def decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n",
"Code2": "int decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( k & 1 ) cout << \"1\" ;\n else cout << \"0\" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n\n"
},
{
"id": "python-cpp-SUPER_PRIME",
"pair": "python-cpp",
"Code1": "def SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n",
"Code2": "bool SieveOfEratosthenes ( int n , bool isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n\n"
},
{
"id": "python-cpp-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "python-cpp",
"Code1": "def abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n",
"Code2": "int abFree ( string s ) {\n int n = s . length ( ) ;\n char char_array [ n + 1 ] ;\n strcpy ( char_array , s . c_str ( ) ) ;\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( char_array [ n - i - 1 ] == 'a' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n\n"
},
{
"id": "python-cpp-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "python-cpp",
"Code1": "def countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n",
"Code2": "int countSubstrs ( string str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str [ i ] == str [ j ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n\n"
},
{
"id": "python-cpp-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "python-cpp",
"Code1": "def findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n",
"Code2": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n\n"
},
{
"id": "python-cpp-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "python-cpp",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "unsigned int factorial ( unsigned int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-cpp-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "python-cpp",
"Code1": "def minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n",
"Code2": "int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input || unlock_code ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n\n"
},
{
"id": "python-cpp-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "python-cpp",
"Code1": "def findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "void findFibSubset ( int arr [ ] , int n ) {\n int max = * std :: max_element ( arr , arr + n ) ;\n int a = 0 , b = 1 ;\n unordered_set < int > hash ;\n hash . insert ( a ) ;\n hash . insert ( b ) ;\n while ( b < max ) {\n int c = a + b ;\n a = b ;\n b = c ;\n hash . insert ( b ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( \"%d \" , arr [ i ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-MARKOV_MATRIX",
"pair": "python-cpp",
"Code1": "def checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n",
"Code2": "bool checkMarkov ( double m [ ] [ n ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "python-cpp",
"Code1": "def insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n",
"Code2": "int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n\n"
},
{
"id": "python-cpp-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "python-cpp",
"Code1": "def recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n",
"Code2": "void recursiveReverse ( string & str , int i = 0 ) {\n int n = str . length ( ) ;\n if ( i == n / 2 ) return ;\n swap ( str [ i ] , str [ n - i - 1 ] ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n\n"
},
{
"id": "python-cpp-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "python-cpp",
"Code1": "def areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n",
"Code2": "bool areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n bool * visited = ( bool * ) calloc ( n , sizeof ( bool ) ) ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n\n"
},
{
"id": "python-cpp-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "python-cpp",
"Code1": "def findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n",
"Code2": "double findMod ( double a , double b ) {\n double mod ;\n if ( a < 0 ) mod = - a ;\n else mod = a ;\n if ( b < 0 ) b = - b ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n\n"
},
{
"id": "python-cpp-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "python-cpp",
"Code1": "def sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n",
"Code2": "int sumOfSubstrings ( string num ) {\n int n = num . length ( ) ;\n int sumofdigit [ n ] ;\n sumofdigit [ 0 ] = toDigit ( num [ 0 ] ) ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = toDigit ( num [ i ] ) ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n\n"
},
{
"id": "python-cpp-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n",
"Code2": "int findGreatest ( int arr [ ] , int n ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) m [ arr [ i ] ] ++ ;\n sort ( arr , arr + n ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m [ result ] > 0 ) return arr [ i ] ;\n else if ( result == arr [ j ] && m [ result ] > 1 ) return arr [ i ] ;\n }\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_THE_MISSING_NUMBER_1",
"pair": "python-cpp",
"Code1": "def getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n",
"Code2": "int getMissingNo ( int a [ ] , int n ) {\n int i , total = 1 ;\n for ( i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n\n"
},
{
"id": "python-cpp-NEXT_POWER_OF_2_2",
"pair": "python-cpp",
"Code1": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n\n"
},
{
"id": "python-cpp-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "python-cpp",
"Code1": "def add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n",
"Code2": "void add ( int A [ ] [ N ] , int B [ ] [ N ] , int C [ ] [ N ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n\n"
},
{
"id": "python-cpp-ENTRINGER_NUMBER_1",
"pair": "python-cpp",
"Code1": "def zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n",
"Code2": "int zigzag ( int n , int k ) {\n int dp [ n + 1 ] [ k + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n return dp [ n ] [ k ] ;\n }\n int main ( ) {\n int n = 4 , k = 3 ;\n cout << zigzag ( n , k ) << endl ;\n return 0 ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "python-cpp",
"Code1": "def eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n",
"Code2": "int eggDrop ( int n , int k ) {\n int eggFloor [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = INT_MAX ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n\n"
},
{
"id": "python-cpp-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "python-cpp",
"Code1": "def noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n",
"Code2": "string noAdjacentDup ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = 'a' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n\n"
},
{
"id": "python-cpp-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "python-cpp",
"Code1": "def maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n",
"Code2": "int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n\n"
},
{
"id": "python-cpp-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "python-cpp",
"Code1": "def minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n",
"Code2": "int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int lis [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n\n"
},
{
"id": "python-cpp-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "python-cpp",
"Code1": "def isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n",
"Code2": "bool isMultipleOf10 ( int n ) {\n return ( n % 15 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n\n"
},
{
"id": "python-cpp-HARDY_RAMANUJAN_THEOREM",
"pair": "python-cpp",
"Code1": "def exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n",
"Code2": "int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "python-cpp",
"Code1": "def query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n",
"Code2": "void query ( char s [ ] , int i , int j ) {\n int n = strlen ( s ) ;\n i %= n ;\n j %= n ;\n ( s [ i ] == s [ j ] ) ? ( cout << \"Yes\" << endl ) : ( cout << \"No\" << endl ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n",
"Code2": "int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) return - 1 ;\n sort ( arr , arr + n ) ;\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n\n"
},
{
"id": "python-cpp-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "python-cpp",
"Code1": "def findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n",
"Code2": "void findMinAvgSubarray ( int arr [ ] , int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n cout << \"Subarray between [\" << res_index << \", \" << res_index + k - 1 << \"] has minimum average\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "python-cpp",
"Code1": "def countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n",
"Code2": "int countwalks ( int graph [ ] [ V ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n",
"Code2": "int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n set < int > Hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) Hash . insert ( arr [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . find ( product ) != Hash . end ( ) ) result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n\n"
},
{
"id": "python-cpp-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "python-cpp",
"Code1": "def print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n",
"Code2": "void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n cout << - 1 << endl ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) cout << r * i << \" \" ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n cout << res << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n\n"
},
{
"id": "python-cpp-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "python-cpp",
"Code1": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"Code2": "unsigned int nextPowerOf2 ( unsigned int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n\n"
},
{
"id": "python-cpp-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "python-cpp",
"Code1": "def findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n",
"Code2": "- 100000000 int findMaxValue ( int arr [ ] , int n ) {\n if ( n < 4 ) {\n printf ( \"The array should have atlest 4 elements\\n\" ) ;\n return MIN ;\n }\n int table1 [ n + 1 ] , table2 [ n ] , table3 [ n - 1 ] , table4 [ n - 2 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table1 [ i ] = table2 [ i ] = table3 [ i ] = table4 [ i ] = MIN ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n\n"
},
{
"id": "python-cpp-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "python-cpp",
"Code1": "def printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n",
"Code2": "void printInSortedOrder ( string arr [ ] , int n ) {\n int index [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) index [ i ] = i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compare ( arr [ index [ j ] ] ) > 0 ) min = j ;\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) cout << arr [ index [ i ] ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "python-cpp",
"Code1": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"Code2": "int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n\n"
},
{
"id": "python-cpp-RECURSION",
"pair": "python-cpp",
"Code1": "def printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n",
"Code2": "void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n cout << test << \" \" ;\n printFun ( test - 1 ) ;\n cout << test << \" \" ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n\n"
},
{
"id": "python-cpp-SHIFT_MATRIX_ELEMENTS_K",
"pair": "python-cpp",
"Code1": "def shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n",
"Code2": "void shiftMatrixByK ( int mat [ N ] [ N ] , int k ) {\n if ( k > N ) {\n cout << \"shifting is not possible\" << endl ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) cout << mat [ j ] [ i ] << \" \" ;\n cout << endl ;\n j ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n\n"
},
{
"id": "python-cpp-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "python-cpp",
"Code1": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n",
"Code2": "void sortUsingHash ( int a [ ] , int n ) {\n int max = * std :: max_element ( a , a + n ) ;\n int min = abs ( * std :: min_element ( a , a + n ) ) ;\n int hashpos [ max + 1 ] = {\n 0 }\n ;\n int hashneg [ min + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n cout << ( - 1 ) * i << \" \" ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n cout << i << \" \" ;\n }\n }\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-cpp-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "python-cpp",
"Code1": "def findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n",
"Code2": "void findPair ( int arr [ ] , int n ) {\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n\n"
},
{
"id": "python-cpp-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "python-cpp",
"Code1": "def findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n",
"Code2": "int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = max ( high , arr [ i ] ) ;\n int count [ high + 1 ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n counter = 0 ;\n while ( j <= high ) {\n if ( count [ j ] >= 2 ) return j ;\n else if ( count [ j ] == 1 ) counter ++ ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n }\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n\n"
},
{
"id": "python-cpp-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "python-cpp",
"Code1": "def squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n",
"Code2": "bool squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "python-cpp",
"Code1": "def count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n",
"Code2": "int count ( int n , int x ) {\n int count = = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n\n"
},
{
"id": "python-cpp-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "python-cpp",
"Code1": "def maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n",
"Code2": "int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n\n"
},
{
"id": "python-cpp-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "python-cpp",
"Code1": "def smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "void smallestSubsegment ( int a [ ] , int n ) {\n unordered_map < int , int > left ;\n unordered_map < int , int > count ;\n int mx = 0 ;\n int mn , strindex ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count [ x ] == 0 ) {\n left [ x ] = i ;\n count [ x ] = 1 ;\n }\n else count [ x ] ++ ;\n if ( count [ x ] > mx ) {\n mx = count [ x ] ;\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n else if ( count [ x ] == mx && i - left [ x ] + 1 < mn ) {\n mn = i - left [ x ] + 1 ;\n strindex = left [ x ] ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "python-cpp",
"Code1": "def findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n",
"Code2": "void findRandomIndexOfMax ( int arr [ ] , int n ) {\n unordered_map < int , int > freq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq [ arr [ i ] ] += 1 ;\n int max_element ;\n int max_so_far = INT_MIN ;\n for ( pair < int , int > p : freq ) {\n if ( p . second > max_so_far ) {\n max_so_far = p . second ;\n max_element = p . first ;\n }\n }\n int r = ( rand ( ) % max_so_far ) + 1 ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n cout << \"Element with maximum frequency present \" \"at index \" << i << endl ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "python-cpp",
"Code1": "def minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n",
"Code2": "int minRadius ( int k , int x [ ] , int y [ ] , int n ) {\n int dis [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n sort ( dis , dis + n ) ;\n return dis [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n\n"
},
{
"id": "python-cpp-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "python-cpp",
"Code1": "def singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n",
"Code2": "int singleNumber ( int a [ ] , int n ) {\n unordered_set < int > s ( a , a + n ) ;\n int arr_sum = accumulate ( a , a + n , 0 ) ;\n int set_sum = accumulate ( s . begin ( ) , s . end ( ) , 0 ) ;\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n\n"
},
{
"id": "python-cpp-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "python-cpp",
"Code1": "def countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n",
"Code2": "int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n\n"
},
{
"id": "python-cpp-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "python-cpp",
"Code1": "def findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n",
"Code2": "void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n ( m == 1 ) ? cout << \"Smallest number is \" << 0 : cout << \"Not possible\" ;\n return ;\n }\n if ( s > 9 * m ) {\n cout << \"Not possible\" ;\n return ;\n }\n int res [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n cout << \"Smallest number is \" ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) cout << res [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n\n"
},
{
"id": "python-cpp-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "python-cpp",
"Code1": "def isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n",
"Code2": "bool isPresent ( string s , string q ) {\n int freq [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s [ i ] ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q [ i ] ] -- ;\n if ( freq [ q [ i ] ] < 0 ) return false ;\n }\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "python-cpp",
"Code1": "def sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n",
"Code2": "void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index , maximum = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int new_arr [ n ] , k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = new_arr [ i ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n\n"
},
{
"id": "python-cpp-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "python-cpp",
"Code1": "def printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "void printDistance ( int mat [ N ] [ M ] ) {\n int ans [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = INT_MAX ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) cout << ans [ i ] [ j ] << \" \" ;\n cout << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-cpp-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "python-cpp",
"Code1": "def findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n",
"Code2": "int findLastIndex ( string & str , char x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str [ i ] == x ) index = i ;\n return index ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n\n"
},
{
"id": "python-cpp-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "python-cpp",
"Code1": "def printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n",
"Code2": "void printAllAPTriplets ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << \" \" << arr [ i ] << \" \" << arr [ j ] << endl ;\n }\n s . insert ( arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n\n"
},
{
"id": "python-cpp-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "python-cpp",
"Code1": "def simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n",
"Code2": "char * simplify ( string str ) {\n int len = str . length ( ) ;\n char * res = new char ( len ) ;\n int index = 0 , i = 0 ;\n stack < int > s ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str [ i ] == '+' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '-' ;\n if ( s . top ( ) == 0 ) res [ index ++ ] = '+' ;\n }\n else if ( str [ i ] == '-' ) {\n if ( s . top ( ) == 1 ) res [ index ++ ] = '+' ;\n else if ( s . top ( ) == 0 ) res [ index ++ ] = '-' ;\n }\n else if ( str [ i ] == '(' && i > 0 ) {\n if ( str [ i - 1 ] == '-' ) {\n int x = ( s . top ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str [ i - 1 ] == '+' ) s . push ( s . top ( ) ) ;\n }\n else if ( str [ i ] == ')' ) s . pop ( ) ;\n else res [ index ++ ] = str [ i ] ;\n i ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n\n"
},
{
"id": "python-cpp-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "python-cpp",
"Code1": "def vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n",
"Code2": "double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( sqrt ( 5 ) ) ) ) / 4 ) * ( pow ( side , 3 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n\n"
},
{
"id": "python-cpp-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "python-cpp",
"Code1": "def countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n",
"Code2": "int countTransformation ( string a , string b ) {\n int n = a . size ( ) , m = b . size ( ) ;\n if ( m == 0 ) return 1 ;\n int dp [ m + 1 ] [ n + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) dp [ i ] [ j ] = ( a [ j ] == b [ i ] ) ? 1 : 0 ;\n else if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n else {\n if ( a [ j ] == b [ i ] ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "python-cpp",
"Code1": "def sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n",
"Code2": "int sumAtKthLevel ( string tree , int k , int & i , int level ) {\n if ( tree [ i ++ ] == '(' ) {\n if ( tree [ i ] == ')' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree [ i ] - '0' ;\n int leftsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n int rightsum = sumAtKthLevel ( tree , k , ++ i , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n\n"
},
{
"id": "python-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int * count = new int [ sizeof ( int ) * ( size - 2 ) ] ;\n int i ;\n cout << \" Repeating elements are \" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) cout << arr [ i ] << \" \" ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n\n"
},
{
"id": "python-cpp-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "python-cpp",
"Code1": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n",
"Code2": "int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n sort ( arr , arr + n ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "python-cpp",
"Code1": "def isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n",
"Code2": "bool isSubsetSum ( int set [ ] , int n , int sum ) {\n bool subset [ n + 1 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ i ] [ 0 ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ 0 ] [ i ] = false ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= sum ;\n j ++ ) {\n if ( j < set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ;\n if ( j >= set [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - set [ i - 1 ] ] ;\n }\n }\n return subset [ n ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n\n"
},
{
"id": "python-cpp-MAJORITY_ELEMENT_1",
"pair": "python-cpp",
"Code1": "def findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n",
"Code2": "void findMajority ( int arr [ ] , int size ) {\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) m [ arr [ i ] ] ++ ;\n int count = 0 ;\n for ( auto i : m ) {\n if ( i . second > size / 2 ) {\n count = 1 ;\n cout << \"Majority found :- \" << i . first << endl ;\n break ;\n }\n }\n if ( count == 0 ) cout << \"No Majority element\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "python-cpp",
"Code1": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n\n"
},
{
"id": "python-cpp-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "python-cpp",
"Code1": "def replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n",
"Code2": "void replaceOriginal ( string s , int n ) {\n string r ( n , ' ' ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s [ n - 1 - i ] ;\n if ( s [ i ] != 'a' && s [ i ] != 'e' && s [ i ] != 'i' && s [ i ] != 'o' && s [ i ] != 'u' ) {\n cout << r [ i ] ;\n }\n }\n cout << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n\n"
},
{
"id": "python-cpp-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "python-cpp",
"Code1": "def findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n",
"Code2": "void findPair ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) s . insert ( arr [ i ] ) ;\n bool found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( s . find ( arr [ i ] + arr [ j ] ) != s . end ( ) ) {\n cout << arr [ i ] << \" \" << arr [ j ] << endl ;\n found = true ;\n }\n }\n }\n if ( found == false ) cout << \"Not exist\" << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n\n"
},
{
"id": "python-cpp-NUMBER_SUBSTRINGS_STRING",
"pair": "python-cpp",
"Code1": "def countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n",
"Code2": "int countNonEmptySubstr ( string str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n\n"
},
{
"id": "python-cpp-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "python-cpp",
"Code1": "def countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n",
"Code2": "int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n\n"
},
{
"id": "python-cpp-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "python-cpp",
"Code1": "def maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n",
"Code2": "int maxProfit ( int price [ ] , int n ) {\n int * profit = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n delete [ ] profit ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n\n"
},
{
"id": "python-cpp-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "python-cpp",
"Code1": "def countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n",
"Code2": "int countDer ( int n ) {\n int der [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n\n"
},
{
"id": "python-cpp-MAXIMUM_PATH_SUM_MATRIX",
"pair": "python-cpp",
"Code1": "def findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n",
"Code2": "int findMaxPath ( int mat [ ] [ M ] ) {\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n }\n }\n int res = 0 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) res = max ( mat [ N - 1 ] [ j ] , res ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n\n"
},
{
"id": "python-cpp-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n",
"Code2": "bool checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n sort ( arr , arr + n ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "python-cpp",
"Code1": "def check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n",
"Code2": "int check ( string str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str [ i ] - '0' ) ;\n else evenDigSum += ( str [ i ] - '0' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n\n"
},
{
"id": "python-cpp-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "python-cpp",
"Code1": "def swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n",
"Code2": "void swap ( int * xp , int * yp ) {\n * xp = * xp ^ * yp ;\n * yp = * xp ^ * yp ;\n * xp = * xp ^ * yp ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n\n"
},
{
"id": "python-cpp-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "python-cpp",
"Code1": "def find_Area ( r ) :\n return ( 2 * r * r )\n",
"Code2": "int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find_Area ( r ) :\n return ( 2 * r * r )\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "python-cpp",
"Code1": "def isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n",
"Code2": "bool isLucky ( int n ) {\n bool arr [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n\n"
},
{
"id": "python-cpp-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "python-cpp",
"Code1": "def countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n",
"Code2": "void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ n ] ;\n memset ( count_jump , 0 , sizeof ( count_jump ) ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << count_jump [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "python-cpp",
"Code1": "def zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n",
"Code2": "void zodiac_sign ( int day , string month ) {\n string astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n cout << astro_sign ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n\n"
},
{
"id": "python-cpp-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "python-cpp",
"Code1": "def countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n",
"Code2": "int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ rhs + 1 ] ;\n memset ( dp , 0 , sizeof ( dp ) ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "python-cpp",
"Code1": "def isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n",
"Code2": "bool isSymmetric ( int mat [ ] [ MAX ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "python-cpp",
"Code1": "def isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n",
"Code2": "bool isRectangle ( const vector < vector < int >> & m ) {\n int rows = m . size ( ) ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . size ( ) ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "python-cpp",
"Code1": "def isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n",
"Code2": "bool isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n\n"
},
{
"id": "python-cpp-KNAPSACK_PROBLEM",
"pair": "python-cpp",
"Code1": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"Code2": "int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n\n"
},
{
"id": "python-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "python-cpp",
"Code1": "def printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int Xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) Xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) Xor ^= i ;\n set_bit_no = Xor & ~ ( Xor - 1 ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i & set_bit_no ) x = x ^ i ;\n else y = y ^ i ;\n }\n cout << \"The two repeating elements are \" << y << \" \" << x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n\n"
},
{
"id": "python-cpp-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n",
"Code2": "int findSubsequenceCount ( string S , string T ) {\n int m = T . length ( ) , n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n\n"
},
{
"id": "python-cpp-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "python-cpp",
"Code1": "def breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n",
"Code2": "int breakSum ( int n ) {\n int dp [ n + 1 ] ;\n dp [ 0 ] = 0 , dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n\n"
},
{
"id": "python-cpp-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "python-cpp",
"Code1": "def decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n",
"Code2": "void decToHexa ( int n ) {\n char hexaDeciNum [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = temp + 48 ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = temp + 55 ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) cout << hexaDeciNum [ j ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n\n"
},
{
"id": "python-cpp-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "python-cpp",
"Code1": "def gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n",
"Code2": "int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ~ a & 1 ) {\n if ( b & 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ~ b & 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n\n"
},
{
"id": "python-cpp-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "python-cpp",
"Code1": "def oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n",
"Code2": "bool oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n\n"
},
{
"id": "python-cpp-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "python-cpp",
"Code1": "def arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "bool arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-cpp-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "python-cpp",
"Code1": "def strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n",
"Code2": "void strToBinary ( string s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n int val = int ( s [ i ] ) ;\n string bin = \"\" ;\n while ( val > 0 ) {\n ( val % 2 ) ? bin . push_back ( '1' ) : bin . push_back ( '0' ) ;\n val /= 2 ;\n }\n reverse ( bin . begin ( ) , bin . end ( ) ) ;\n cout << bin << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n\n"
},
{
"id": "python-cpp-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "python-cpp",
"Code1": "def evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n",
"Code2": "void evaluate ( long long int n ) {\n if ( n == 1 || n == 2 ) printf ( \"No Pythagoras Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n long long int var = 1LL * n * n / 4 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var - 1 , var + 1 ) ;\n }\n else if ( n % 2 != 0 ) {\n long long int var = 1LL * n * n + 1 ;\n printf ( \"Pythagoras Triplets exist i.e. \" ) ;\n printf ( \"%lld %lld %lld\" , n , var / 2 - 1 , var / 2 ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n\n"
},
{
"id": "python-cpp-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "python-cpp",
"Code1": "def isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n",
"Code2": "bool isOverflow ( long long a , long long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n\n"
},
{
"id": "python-cpp-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "python-cpp",
"Code1": "def findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n",
"Code2": "bool findDuplicateparenthesis ( string str ) {\n stack < char > Stack ;\n for ( char ch : str ) {\n if ( ch == ')' ) {\n char top = Stack . top ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != '(' ) {\n elementsInside ++ ;\n top = Stack . top ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return 1 ;\n }\n }\n else Stack . push ( ch ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n\n"
},
{
"id": "python-cpp-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "python-cpp",
"Code1": "def countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n",
"Code2": "int countRotations ( string n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . at ( 0 ) - '0' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . at ( i ) - '0' ) * 10 + ( n . at ( i + 1 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . at ( len - 1 ) - '0' ) * 10 + ( n . at ( 0 ) - '0' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-cpp-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "python-cpp",
"Code1": "def findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n",
"Code2": "void findTriplets ( int x ) {\n vector < int > fact ;\n unordered_set < int > factors ;\n for ( int i = 2 ;\n i <= sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . push_back ( i ) ;\n if ( x / i != i ) fact . push_back ( x / i ) ;\n factors . insert ( i ) ;\n factors . insert ( x / i ) ;\n }\n }\n bool found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact [ i ] ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact [ j ] ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n cout << a << \" \" << b << \" \" << ( x / ( a * b ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) cout << \"-1\" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n\n"
},
{
"id": "python-cpp-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "python-cpp",
"Code1": "def findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n",
"Code2": "void findCombinations ( string str , int index , string out ) {\n if ( index == str . length ( ) ) cout << out << endl ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substr ( index , i + 1 - index ) + \")\" ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n\n"
},
{
"id": "python-cpp-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "python-cpp",
"Code1": "def search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n",
"Code2": "int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "python-cpp",
"Code1": "def findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n unordered_set < int > s ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . insert ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( s . find ( a [ i ] ) == s . end ( ) ) cout << a [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "python-cpp",
"Code1": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n",
"Code2": "int countPairs ( string str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( abs ( str [ i + j ] - str [ i ] ) == j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n\n"
},
{
"id": "python-cpp-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "python-cpp",
"Code1": "def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n",
"Code2": "int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( 1 ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n\n"
},
{
"id": "python-cpp-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "python-cpp",
"Code1": "def solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n",
"Code2": "int solve ( int arr [ ] , int n ) {\n sort ( arr , arr + n ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i & 1 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n\n"
},
{
"id": "python-cpp-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "python-cpp",
"Code1": "def firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n",
"Code2": "int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n\n"
},
{
"id": "python-cpp-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "python-cpp",
"Code1": "def countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n",
"Code2": "int countMinOperations ( unsigned int target [ ] , int n ) {\n int result = 0 ;\n while ( 1 ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( target [ i ] & 1 ) break ;\n else if ( target [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) target [ j ] = target [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( target [ j ] & 1 ) {\n target [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n\n"
},
{
"id": "python-cpp-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "python-cpp",
"Code1": "def sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n",
"Code2": "void sortit ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n\n"
},
{
"id": "python-cpp-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "python-cpp",
"Code1": "def canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n",
"Code2": "bool canMakeAllSame ( string str ) {\n int zeros = 0 , ones = 0 ;\n for ( char ch : str ) ( ch == '0' ) ? ++ zeros : ++ ones ;\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n\n"
},
{
"id": "python-cpp-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "python-cpp",
"Code1": "def minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n",
"Code2": "void minheapify ( int a [ ] , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n swap ( a [ small ] , a [ index ] ) ;\n minheapify ( a , small ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "python-cpp",
"Code1": "def KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n",
"Code2": "void KMP ( int m , int n , string str2 , string str1 ) {\n int pos = 0 , len = 0 ;\n int p [ m + 1 ] ;\n int k = 0 ;\n p [ 1 ] = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && str1 [ k ] != str1 [ i - 1 ] ) k = p [ k ] ;\n if ( str1 [ k ] == str1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && str1 [ j ] != str2 [ i ] ) j = p [ j ] ;\n if ( str1 [ j ] == str2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n cout << \"Shift = \" << pos << endl ;\n cout << \"Prefix = \" << str1 . substr ( 0 , len ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n\n"
},
{
"id": "python-cpp-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "python-cpp",
"Code1": "def swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n",
"Code2": "void swapDiagonal ( int matrix [ ] [ N ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) swap ( matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n\n"
},
{
"id": "python-cpp-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "python-cpp",
"Code1": "def psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n",
"Code2": "void psuedoBinary ( int n ) {\n while ( n > 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n cout << m << \" \" ;\n n = n - m ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n\n"
},
{
"id": "python-cpp-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "python-cpp",
"Code1": "def findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n",
"Code2": "int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return min ( {\n a , b , c , d }\n ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n\n"
},
{
"id": "python-cpp-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "python-cpp",
"Code1": "def minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n",
"Code2": "int minCoins ( int coins [ ] , int m , int V ) {\n int table [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = INT_MAX ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != INT_MAX && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n\n"
},
{
"id": "python-cpp-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "python-cpp",
"Code1": "def maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n",
"Code2": "string maximumPalinUsingKChanges ( string str , int k ) {\n string palin = str ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str [ l ] != str [ r ] ) {\n palin [ l ] = palin [ r ] = max ( str [ l ] , str [ r ] ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) return \"Not possible\" ;\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) palin [ l ] = '9' ;\n }\n if ( palin [ l ] < '9' ) {\n if ( k >= 2 && palin [ l ] == str [ l ] && palin [ r ] == str [ r ] ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str [ l ] || palin [ r ] != str [ r ] ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = '9' ;\n }\n }\n l ++ ;\n r -- ;\n }\n return palin ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n\n"
},
{
"id": "python-cpp-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "python-cpp",
"Code1": "def findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n",
"Code2": "int findMinRooms ( string slots [ ] , int n , int m ) {\n int counts [ m ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ;\n return * max_element ( counts , counts + m ) ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n\n"
},
{
"id": "python-cpp-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "python-cpp",
"Code1": "def printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n",
"Code2": "void printMaxSum ( int arr [ ] , int n ) {\n int dp [ n ] ;\n memset ( dp , 0 , sizeof dp ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) cout << dp [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "python-cpp",
"Code1": "def maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n",
"Code2": "int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ n ] ;\n memset ( dec , 0 , sizeof ( dec ) ) ;\n int inc [ n ] ;\n memset ( inc , 0 , sizeof ( inc ) ) ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n\n"
},
{
"id": "python-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n printf ( \" Repeating elements are \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) for ( j = i + 1 ;\n j < size ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) cout << arr [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n\n"
},
{
"id": "python-cpp-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "python-cpp",
"Code1": "def minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n",
"Code2": "int minProduct ( int arr [ ] , int n , int k ) {\n priority_queue < int , vector < int > , greater < int >> pq ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . push ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . empty ( ) == false && count < k ) {\n ans = ans * pq . top ( ) ;\n pq . pop ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n\n"
},
{
"id": "python-cpp-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "python-cpp",
"Code1": "def largest ( arr , n ) :\n return max ( arr )\n",
"Code2": "int largest ( int arr [ ] , int n ) {\n return * max_element ( arr , arr + n ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef largest ( arr , n ) :\n return max ( arr )\n\n"
},
{
"id": "python-cpp-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "python-cpp",
"Code1": "def exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n",
"Code2": "float exponential ( int n , float x ) {\n float sum = 1.0f ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n\n"
},
{
"id": "python-cpp-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "python-cpp",
"Code1": "def firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n",
"Code2": "int firstElement ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > count_map ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count_map [ arr [ i ] ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( count_map [ arr [ i ] ] == k ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "python-cpp",
"Code1": "def maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n",
"Code2": "int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n\n"
},
{
"id": "python-cpp-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "python-cpp",
"Code1": "def maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n",
"Code2": "int maxSum ( int grid [ 2 ] [ MAX ] , int n ) {\n int incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = max ( excl , incl ) ;\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return max ( excl , incl ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n\n"
},
{
"id": "python-cpp-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "python-cpp",
"Code1": "def countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n",
"Code2": "int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-cpp-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "python-cpp",
"Code1": "def findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n",
"Code2": "int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n\n"
},
{
"id": "python-cpp-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "python-cpp",
"Code1": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n",
"Code2": "bool checkCorrectOrNot ( string s ) {\n int count1 [ MAX_CHAR ] = {\n 0 }\n ;\n int count2 [ MAX_CHAR ] = {\n 0 }\n ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s [ i ] - 'a' ] ++ ;\n count2 [ s [ j ] - 'a' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n\n"
},
{
"id": "python-cpp-SUM_FACTORS_NUMBER",
"pair": "python-cpp",
"Code1": "def divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n",
"Code2": "int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n\n"
},
{
"id": "python-cpp-ROTATE_MATRIX_180_DEGREE",
"pair": "python-cpp",
"Code1": "def rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n",
"Code2": "void rotateMatrix ( int mat [ ] [ N ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) printf ( \"%d \" , mat [ i ] [ j ] ) ;\n printf ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n\n"
},
{
"id": "python-cpp-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "python-cpp",
"Code1": "def printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n",
"Code2": "void printSpiral ( int mat [ ] [ MAX ] , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) cout << mat [ low_row ] [ i ] << \" \" ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) cout << mat [ i ] [ high_column ] << \" \" ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) cout << mat [ high_row ] [ i ] << \" \" ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) cout << mat [ i ] [ low_column ] << \" \" ;\n low_column -= 1 ;\n }\n cout << endl ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n\n"
},
{
"id": "python-cpp-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "python-cpp",
"Code1": "def countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n",
"Code2": "int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n\n"
},
{
"id": "python-cpp-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "python-cpp",
"Code1": "def areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n",
"Code2": "double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + sqrt ( 2 ) ) * side * side ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n\n"
},
{
"id": "python-cpp-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "python-cpp",
"Code1": "def findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n",
"Code2": "int findLongestConseqSubseq ( int arr [ ] , int n ) {\n unordered_set < int > S ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . insert ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . find ( arr [ i ] - 1 ) == S . end ( ) ) {\n int j = arr [ i ] ;\n while ( S . find ( j ) != S . end ( ) ) j ++ ;\n ans = max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n\n"
},
{
"id": "python-cpp-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "python-cpp",
"Code1": "def printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n",
"Code2": "void printSuperSeq ( string & a , string & b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int dp [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( ! i ) dp [ i ] [ j ] = j ;\n else if ( ! j ) dp [ i ] [ j ] = i ;\n else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int index = dp [ m ] [ n ] ;\n string res ( index + 1 , '\\0' ) ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a [ i - 1 ] == b [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n j -- ;\n index -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n else {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n }\n while ( i > 0 ) {\n res [ index - 1 ] = a [ i - 1 ] ;\n i -- ;\n index -- ;\n }\n while ( j > 0 ) {\n res [ index - 1 ] = b [ j - 1 ] ;\n j -- ;\n index -- ;\n }\n cout << res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n\n"
},
{
"id": "python-cpp-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "python-cpp",
"Code1": "def numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n",
"Code2": "int numberOfPaths ( int m , int n ) {\n int dp [ n ] = {\n 1 }\n ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n\n"
},
{
"id": "python-cpp-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "python-cpp",
"Code1": "def isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n",
"Code2": "bool isPowerOfFour ( unsigned int n ) {\n int count = 0 ;\n if ( n && ! ( n & ( n - 1 ) ) ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n\n"
},
{
"id": "python-cpp-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "python-cpp",
"Code1": "def sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n",
"Code2": "int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n\n"
},
{
"id": "python-cpp-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "python-cpp",
"Code1": "def findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n",
"Code2": "int findElement ( int arr [ ] , int n ) {\n int leftMax [ n ] ;\n leftMax [ 0 ] = INT_MIN ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = INT_MAX ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n\n"
},
{
"id": "python-cpp-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "python-cpp",
"Code1": "def search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n",
"Code2": "int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n\n"
},
{
"id": "python-cpp-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "python-cpp",
"Code1": "def exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n",
"Code2": "long int exponentiation ( long int base , long int exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long int t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n\n"
},
{
"id": "python-cpp-DIVISIBILITY_CHECK",
"pair": "python-cpp",
"Code1": "def divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n",
"Code2": "void divisibilityCheck ( int arr [ ] , int n ) {\n unordered_set < int > s ;\n int max_ele = INT_MIN ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . insert ( arr [ i ] ) ;\n max_ele = max ( max_ele , arr [ i ] ) ;\n }\n unordered_set < int > res ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] != 0 ) {\n for ( int j = arr [ i ] * 2 ;\n j <= max_ele ;\n j += arr [ i ] ) {\n if ( s . find ( j ) != s . end ( ) ) res . insert ( j ) ;\n }\n }\n }\n unordered_map < int , int > mp ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp [ arr [ i ] ] ++ ;\n unordered_map < int , int > :: iterator it ;\n vector < int > ans ;\n for ( it = mp . begin ( ) ;\n it != mp . end ( ) ;\n it ++ ) {\n if ( it -> second >= 2 ) {\n if ( res . find ( it -> first ) == res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n if ( res . find ( it -> first ) != res . end ( ) ) {\n int val = it -> second ;\n while ( val -- ) ans . push_back ( it -> first ) ;\n }\n }\n for ( auto x : ans ) cout << x << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n\n"
},
{
"id": "python-cpp-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "python-cpp",
"Code1": "def printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n cout << \"The repeating elements are\" ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ] ;\n else cout << \" \" << abs ( arr [ i ] ) << \" \" ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n\n"
},
{
"id": "python-cpp-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "python-cpp",
"Code1": "def minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n",
"Code2": "int minPalPartion ( char * str ) {\n int n = strlen ( str ) ;\n int C [ n ] [ n ] ;\n bool P [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str [ i ] == str [ j ] ) ;\n else P [ i ] [ j ] = ( str [ i ] == str [ j ] ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = INT_MAX ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-cpp-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "python-cpp",
"Code1": "def height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n",
"Code2": "int height ( int N ) {\n return ceil ( log2 ( N + 1 ) ) - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n\n"
},
{
"id": "python-cpp-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "python-cpp",
"Code1": "def checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n",
"Code2": "bool checkCount ( int arr [ ] , int n , int k ) {\n unordered_map < int , int > hash ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ arr [ i ] ] ++ ;\n for ( auto x : hash ) if ( x . second > 2 * k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n\n"
},
{
"id": "python-cpp-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "python-cpp",
"Code1": "def removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n",
"Code2": "void removeDuplicates ( char S [ ] ) {\n int n = strlen ( S ) ;\n if ( n < 2 ) return ;\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n j ++ ;\n S [ j ] = '\\0' ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n\n"
},
{
"id": "python-cpp-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "python-cpp",
"Code1": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n",
"Code2": "void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = INT_MIN , third = INT_MIN ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) third = arr [ i ] ;\n }\n printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n\n"
},
{
"id": "python-cpp-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "python-cpp",
"Code1": "def longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n",
"Code2": "int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int lioes [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n\n"
},
{
"id": "python-cpp-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "python-cpp",
"Code1": "def addOne ( x ) :\n return ( - ( ~ x ) )\n",
"Code2": "int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef addOne ( x ) :\n return ( - ( ~ x ) )\n\n"
},
{
"id": "python-cpp-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "python-cpp",
"Code1": "def getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n",
"Code2": "int getNumStrictMonotone ( int len ) {\n int DP [ len ] [ DP_s ] ;\n memset ( DP , 0 , sizeof ( DP ) ) ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n\n"
},
{
"id": "python-cpp-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "python-cpp",
"Code1": "def binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n\n"
},
{
"id": "python-cpp-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "python-cpp",
"Code1": "def bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n",
"Code2": "void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n cout << \"(\" << x << \",\" << y << \")\\n\" ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n\n"
},
{
"id": "python-cpp-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "python-cpp",
"Code1": "def maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n",
"Code2": "int maxRevenue ( int m , int x [ ] , int revenue [ ] , int n , int t ) {\n int maxRev [ m + 1 ] ;\n memset ( maxRev , 0 , sizeof ( maxRev ) ) ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n\n"
},
{
"id": "python-cpp-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "python-cpp",
"Code1": "def lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n",
"Code2": "pair < double , double > void lineFromPoints ( pdd P , pdd Q ) {\n double a = Q . second - P . second ;\n double b = P . first - Q . first ;\n double c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n cout << \"The line passing through points P and Q is: \" << a << \"x \" << b << \"y = \" << c << endl ;\n }\n else {\n cout << \"The line passing through points P and Q is: \" << a << \"x + \" << b << \"y = \" << c << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n\n"
},
{
"id": "python-cpp-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "python-cpp",
"Code1": "def findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n",
"Code2": "int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n\n"
},
{
"id": "python-cpp-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "python-cpp",
"Code1": "def find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n",
"Code2": "bool find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n cout << \"Triplet is \" << A [ i ] << \", \" << A [ j ] << \", \" << A [ k ] ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n\n"
},
{
"id": "python-cpp-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "python-cpp",
"Code1": "def KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n",
"Code2": "void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n priority_queue < int > pq ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . push ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n cout << pq . top ( ) << endl ;\n pq . pop ( ) ;\n count ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n\n"
},
{
"id": "python-cpp-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "python-cpp",
"Code1": "def numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n",
"Code2": "int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n\n"
},
{
"id": "python-cpp-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "python-cpp",
"Code1": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n",
"Code2": "int countSubstringWithEqualEnds ( string s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int count [ MAX_CHAR ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n\n"
},
{
"id": "python-cpp-DIVISIBILITY_BY_7",
"pair": "python-cpp",
"Code1": "def isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n",
"Code2": "int isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return 1 ;\n if ( num < 10 ) return 0 ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n\n"
},
{
"id": "python-cpp-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "python-cpp",
"Code1": "def findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n",
"Code2": "int findRepeatingNumber ( const int arr [ ] , int n ) {\n int sq = sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int count [ range ] = {\n 0 }\n ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n unordered_map < int , int > m ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m [ arr [ i ] ] ++ ;\n if ( m [ arr [ i ] ] > 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-cpp-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "python-cpp",
"Code1": "def findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n",
"Code2": "int findSDSFunc ( int n ) {\n int DP [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n\n"
},
{
"id": "python-cpp-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "python-cpp",
"Code1": "def recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n",
"Code2": "int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n\n"
},
{
"id": "python-cpp-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "python-cpp",
"Code1": "def check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n",
"Code2": "bool check ( string str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str [ 0 ] - '0' ) % 4 == 0 ) ;\n int last = str [ n - 1 ] - '0' ;\n int second_last = str [ n - 2 ] - '0' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n\n"
},
{
"id": "python-cpp-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "python-cpp",
"Code1": "def to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n",
"Code2": "string to_upper ( string & in ) {\n for ( int i = 0 ;\n i < in . length ( ) ;\n i ++ ) if ( 'a' <= in [ i ] <= 'z' ) in [ i ] = in [ i ] - 'a' + 'A' ;\n return in ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n\n"
},
{
"id": "python-cpp-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "python-cpp",
"Code1": "def remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n",
"Code2": "int remAnagram ( string str1 , string str2 ) {\n int count1 [ CHARS ] = {\n 0 }\n , count2 [ CHARS ] = {\n 0 }\n ;\n for ( int i = 0 ;\n str1 [ i ] != '\\0' ;\n i ++ ) count1 [ str1 [ i ] - 'a' ] ++ ;\n for ( int i = 0 ;\n str2 [ i ] != '\\0' ;\n i ++ ) count2 [ str2 [ i ] - 'a' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n\n"
},
{
"id": "python-cpp-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "python-cpp",
"Code1": "def sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n",
"Code2": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( & arr [ i ] , & arr [ i - 1 ] ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( & arr [ i ] , & arr [ i + 1 ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n\n"
},
{
"id": "python-cpp-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "python-cpp",
"Code1": "def getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n",
"Code2": "string getMinNumberForPattern ( string seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n string result ( n + 1 , ' ' ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq [ i ] == 'I' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = '0' + count ++ ;\n if ( j >= 0 && seq [ j ] == 'I' ) break ;\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n\n"
},
{
"id": "python-cpp-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "python-cpp",
"Code1": "def isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n",
"Code2": "bool isPossible ( string str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n\n"
},
{
"id": "python-cpp-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "python-cpp",
"Code1": "def center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n",
"Code2": "void center ( int x1 , int x2 , int y1 , int y2 ) {\n cout << ( float ) ( x1 + x2 ) / 2 << \", \" << ( float ) ( y1 + y2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n\n"
},
{
"id": "python-cpp-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "python-cpp",
"Code1": "def findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n",
"Code2": "void findMin ( int V ) {\n vector < int > ans ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . push_back ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) cout << ans [ i ] << \" \" ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n\n"
},
{
"id": "python-cpp-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "python-cpp",
"Code1": "def mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n",
"Code2": "ll mulmod ( ll a , ll b , ll mod ) {\n ll res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) res = ( res + a ) % mod ;\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n\n"
},
{
"id": "python-cpp-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "python-cpp",
"Code1": "def Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n",
"Code2": "string Dragon_Curve_Sequence ( int n ) {\n string s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n string temp = \"1\" ;\n char prev = '1' , zero = '0' , one = '1' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s [ j ] ;\n if ( prev == '0' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n\n"
},
{
"id": "python-cpp-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "python-cpp",
"Code1": "def minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n",
"Code2": "int minInitialPoints ( int points [ ] [ C ] ) {\n int dp [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n\n"
},
{
"id": "python-cpp-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "python-cpp",
"Code1": "def findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n",
"Code2": "int findRepeating ( int arr [ ] , int n ) {\n return accumulate ( arr , arr + n , 0 ) - ( ( n - 1 ) * n / 2 ) ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n\n"
},
{
"id": "python-cpp-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "python-cpp",
"Code1": "def getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n",
"Code2": "char getSecondMostFreq ( string str ) {\n int count [ NO_OF_CHARS ] = {\n 0 }\n , i ;\n for ( i = 0 ;\n str [ i ] ;\n i ++ ) ( count [ str [ i ] ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return second ;\n }\n ",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n\n"
},
{
"id": "python-cpp-SUM_TWO_LARGE_NUMBERS",
"pair": "python-cpp",
"Code1": "def findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n",
"Code2": "string findSum ( string str1 , string str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) swap ( str1 , str2 ) ;\n string str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n reverse ( str1 . begin ( ) , str1 . end ( ) ) ;\n reverse ( str2 . begin ( ) , str2 . end ( ) ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( str1 [ i ] - '0' ) + ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( str2 [ i ] - '0' ) + carry ) ;\n str . push_back ( sum % 10 + '0' ) ;\n carry = sum / 10 ;\n }\n if ( carry ) str . push_back ( carry + '0' ) ;\n reverse ( str . begin ( ) , str . end ( ) ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n\n"
},
{
"id": "python-cpp-NEXT_GREATER_ELEMENT",
"pair": "python-cpp",
"Code1": "def printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n",
"Code2": "void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n cout << arr [ i ] << \" -- \" << next << endl ;\n }\n}\n",
"instruction": "Translate the given code from python to cpp. The input Code is marked with and .",
"input": "\ndef printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n\n"
},
{
"id": "python-java-PAIRS_OF_POSITIVE_NEGATIVE_VALUES_IN_AN_ARRAY",
"pair": "python-java",
"Code1": "def printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n",
"Code2": "public static void printPairs ( int arr [ ] , int n ) {\n Vector < Integer > v = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( arr [ i ] ) == Math . abs ( arr [ j ] ) ) v . add ( Math . abs ( arr [ i ] ) ) ;\n if ( v . size ( ) == 0 ) return ;\n Collections . sort ( v ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) System . out . print ( - v . get ( i ) + \" \" + v . get ( i ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printPairs ( arr , n ) :\n v = [ ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :\n v.append ( abs ( arr [ i ] ) )\n if ( len ( v ) == 0 ) :\n return ;\n v.sort ( )\n for i in range ( len ( v ) ) :\n print ( - v [ i ] , \"\" , v [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-C_PROGRAM_FIND_AREA_TRIANGLE",
"pair": "python-java",
"Code1": "def findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n",
"Code2": "static float findArea ( float a , float b , float c ) {\n if ( a < 0 || b < 0 || c < 0 || ( a + b <= c ) || a + c <= b || b + c <= a ) {\n System . out . println ( \"Not a valid triangle\" ) ;\n System . exit ( 0 ) ;\n }\n float s = ( a + b + c ) / 2 ;\n return ( float ) Math . sqrt ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findArea ( a , b , c ) :\n if ( a < 0 or b < 0 or c < 0 or ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) ) :\n print ( 'Not a valid trianglen' )\n return\n s = ( a + b + c ) / 2\n area = ( s * ( s - a ) * ( s - b ) * ( s - c ) ) ** 0.5\n print ( 'Area of a traingle is %f' % area )\n\n"
},
{
"id": "python-java-CHECK_ARRAY_MAJORITY_ELEMENT",
"pair": "python-java",
"Code1": "def isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n",
"Code2": "static boolean isMajority ( int a [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( a [ i ] ) ) mp . put ( a [ i ] , mp . get ( a [ i ] ) + 1 ) ;\n else mp . put ( a [ i ] , 1 ) ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) if ( x . getValue ( ) >= n / 2 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isMajority ( a ) :\n mp = { }\n for i in a :\n if i in mp : mp [ i ] += 1\n else : mp [ i ] = 1\n for x in mp :\n if mp [ x ] >= len ( a ) // 2 :\n return True\n return False\n\n"
},
{
"id": "python-java-NUMBER_N_DIGITS_NON_DECREASING_INTEGERS",
"pair": "python-java",
"Code1": "def nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n",
"Code2": "static int nonDecNums ( int n ) {\n int [ ] [ ] a = new int [ n + 1 ] [ 10 ] ;\n for ( int i = 0 ;\n i <= 9 ;\n i ++ ) a [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) a [ i ] [ 9 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 8 ;\n j >= 0 ;\n j -- ) a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ] ;\n return a [ n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nonDecNums ( n ) :\n a = np.zeros ( ( n + 1 , 10 ) )\n for i in range ( 10 ) :\n a [ 0 ] [ i ] = 1\n for i in range ( 1 , n + 1 ) :\n a [ i ] [ 9 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( 8 , - 1 , - 1 ) :\n a [ i ] [ j ] = a [ i - 1 ] [ j ] + a [ i ] [ j + 1 ]\n return int ( a [ n ] [ 0 ] )\n\n"
},
{
"id": "python-java-PROGRAM_FIRST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-java",
"Code1": "def firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "static void firstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n print ( \" Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( \" \" , i + 1 , \" \" , processSize [ i ] , \" \" , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-java-NON_REPEATING_ELEMENT_1",
"pair": "python-java",
"Code1": "def firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n",
"Code2": "static int firstNonRepeating ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstNonRepeating ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for i in range ( n ) :\n if mp [ arr [ i ] ] == 1 :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-java-DISTRIBUTING_ALL_BALLS_WITHOUT_REPETITION",
"pair": "python-java",
"Code1": "def distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n",
"Code2": "static boolean distributingBalls ( long k , long n , String str ) {\n int [ ] a = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( a [ i ] > k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef distributingBalls ( k , n , string ) :\n a = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n a [ ord ( string [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n if ( a [ i ] > k ) :\n return False\n return True\n\n"
},
{
"id": "python-java-BREAK_NUMBER_THREE_PARTS_1",
"pair": "python-java",
"Code1": "def count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n",
"Code2": "static long count_of_ways ( long n ) {\n long count = 0 ;\n count = ( n + 1 ) * ( n + 2 ) / 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count_of_ways ( n ) :\n count = 0\n count = ( n + 1 ) * ( n + 2 ) // 2\n return count\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY_1",
"pair": "python-java",
"Code1": "def maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n",
"Code2": "static int maxSum ( int arr [ ] , int n ) {\n int cum_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) cum_sum += arr [ i ] ;\n int curr_val = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) curr_val += i * arr [ i ] ;\n int res = curr_val ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ;\n curr_val = next_val ;\n res = Math . max ( res , next_val ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , n ) :\n cum_sum = 0\n for i in range ( 0 , n ) :\n cum_sum += arr [ i ]\n curr_val = 0\n for i in range ( 0 , n ) :\n curr_val += i * arr [ i ]\n res = curr_val\n for i in range ( 1 , n ) :\n next_val = ( curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) )\n curr_val = next_val\n res = max ( res , next_val )\n return res\n\n"
},
{
"id": "python-java-CALCULATE_ANGLE_HOUR_HAND_MINUTE_HAND",
"pair": "python-java",
"Code1": "def calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n",
"Code2": "static int calcAngle ( double h , double m ) {\n if ( h < 0 || m < 0 || h > 12 || m > 60 ) System . out . println ( \"Wrong input\" ) ;\n if ( h == 12 ) h = 0 ;\n if ( m == 60 ) m = 0 ;\n int hour_angle = ( int ) ( 0.5 * ( h * 60 + m ) ) ;\n int minute_angle = ( int ) ( 6 * m ) ;\n int angle = Math . abs ( hour_angle - minute_angle ) ;\n angle = Math . min ( 360 - angle , angle ) ;\n return angle ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calcAngle ( h , m ) :\n if ( h < 0 or m < 0 or h > 12 or m > 60 ) :\n print ( 'Wrong input' )\n if ( h == 12 ) :\n h = 0\n if ( m == 60 ) :\n m = 0\n hour_angle = 0.5 * ( h * 60 + m )\n minute_angle = 6 * m\n angle = abs ( hour_angle - minute_angle )\n angle = min ( 360 - angle , angle )\n return angle\n\n"
},
{
"id": "python-java-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS_1",
"pair": "python-java",
"Code1": "def smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n",
"Code2": "static int smallest ( int x , int y , int z ) {\n if ( ( y / x ) != 1 ) return ( ( y / z ) != 1 ) ? y : z ;\n return ( ( x / z ) != 1 ) ? x : z ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef smallest ( x , y , z ) :\n if ( not ( y / x ) ) :\n return y if ( not ( y / z ) ) else z\n return x if ( not ( x / z ) ) else z\n\n"
},
{
"id": "python-java-FIND_ONE_EXTRA_CHARACTER_STRING_1",
"pair": "python-java",
"Code1": "def findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n",
"Code2": "static char findExtraCharcter ( String strA , String strB ) {\n int res = 0 , i ;\n for ( i = 0 ;\n i < strA . length ( ) ;\n i ++ ) {\n res ^= strA . charAt ( i ) ;\n }\n for ( i = 0 ;\n i < strB . length ( ) ;\n i ++ ) {\n res ^= strB . charAt ( i ) ;\n }\n return ( ( char ) ( res ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findExtraCharcter ( strA , strB ) :\n res = 0\n for i in range ( 0 , len ( strA ) ) :\n res = res ^ ( ord ) ( strA [ i ] )\n for i in range ( 0 , len ( strB ) ) :\n res = res ^ ( ord ) ( strB [ i ] )\n return ( ( chr ) ( res ) ) ;\n\n"
},
{
"id": "python-java-RECAMANS_SEQUENCE_1",
"pair": "python-java",
"Code1": "def recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n",
"Code2": "static void recaman ( int n ) {\n if ( n <= 0 ) return ;\n System . out . printf ( \"%d, \" , 0 ) ;\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n s . add ( 0 ) ;\n int prev = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = prev - i ;\n if ( curr < 0 || s . contains ( curr ) ) curr = prev + i ;\n s . add ( curr ) ;\n System . out . printf ( \"%d, \" , curr ) ;\n prev = curr ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef recaman ( n ) :\n if ( n <= 0 ) :\n return\n print ( 0 , \",\" , end = '' )\n s = set ( [ ] )\n s.add ( 0 )\n prev = 0\n for i in range ( 1 , n ) :\n curr = prev - i\n if ( curr < 0 or curr in s ) :\n curr = prev + i\n s.add ( curr )\n print ( curr , \",\" , end = '' )\n prev = curr\n\n"
},
{
"id": "python-java-PROGRAM_FIND_SMALLEST_DIFFERENCE_ANGLES_TWO_PARTS_GIVEN_CIRCLE",
"pair": "python-java",
"Code1": "def findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n",
"Code2": "public static int findMinimumAngle ( int arr [ ] , int n ) {\n int l = 0 , sum = 0 , ans = 360 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n while ( sum >= 180 ) {\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n sum -= arr [ l ] ;\n l ++ ;\n }\n ans = Math . min ( ans , 2 * Math . abs ( 180 - sum ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinimumAngle ( arr , n ) :\n l = 0\n _sum = 0\n ans = 360\n for i in range ( n ) :\n _sum += arr [ i ]\n while _sum >= 180 :\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n _sum -= arr [ l ]\n l += 1\n ans = min ( ans , 2 * abs ( 180 - _sum ) )\n return ans\n\n"
},
{
"id": "python-java-COUNT_GFG_SUBSEQUENCES_GIVEN_STRING",
"pair": "python-java",
"Code1": "def countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n",
"Code2": "static void countSubsequence ( String s , int n ) {\n int cntG = 0 , cntF = 0 , result = 0 , C = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n switch ( s . charAt ( i ) ) {\n case ' G ' : cntG ++ ;\n result += C ;\n break ;\n case ' F ' : cntF ++ ;\n C += cntG ;\n break ;\n default : continue ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubsequence ( s , n ) :\n cntG = 0\n cntF = 0\n result = 0\n C = 0\n for i in range ( n ) :\n if ( s [ i ] == 'G' ) :\n cntG += 1\n result += C\n continue\n if ( s [ i ] == 'F' ) :\n cntF += 1\n C += cntG\n continue\n else :\n continue\n print ( result )\n\n"
},
{
"id": "python-java-MAXIMUM_DIFFERENCE_BETWEEN_FREQUENCY_OF_TWO_ELEMENTS_SUCH_THAT_ELEMENT_HAVING_GREATER_FREQUENCY_IS_ALSO_GREATER",
"pair": "python-java",
"Code1": "def maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n",
"Code2": "static int maxdiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > freq = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) == null ? 1 : freq . get ( arr [ i ] ) + 1 ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( freq . get ( arr [ i ] ) > freq . get ( arr [ j ] ) && arr [ i ] > arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ i ] ) - freq . get ( arr [ j ] ) ) ;\n else if ( freq . get ( arr [ i ] ) < freq . get ( arr [ j ] ) && arr [ i ] < arr [ j ] ) ans = Math . max ( ans , freq . get ( arr [ j ] ) - freq . get ( arr [ i ] ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxdiff ( arr , n ) :\n freq = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n freq [ arr [ i ] ] += 1\n ans = 0\n for i in range ( n ) :\n for j in range ( n ) :\n if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :\n ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )\n elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :\n ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )\n return ans\n\n"
},
{
"id": "python-java-CHECK_IF_TWO_ARRAYS_ARE_EQUAL_OR_NOT",
"pair": "python-java",
"Code1": "def areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n",
"Code2": "public static boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) {\n int n = arr1 . length ;\n int m = arr2 . length ;\n if ( n != m ) return false ;\n Arrays . sort ( arr1 ) ;\n Arrays . sort ( arr2 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef areEqual ( arr1 , arr2 , n , m ) :\n if ( n != m ) :\n return False ;\n arr1.sort ( ) ;\n arr2.sort ( ) ;\n for i in range ( 0 , n - 1 ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return False ;\n return True ;\n\n"
},
{
"id": "python-java-FRIENDS_PAIRING_PROBLEM_2",
"pair": "python-java",
"Code1": "def countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n",
"Code2": "static int countFriendsPairings ( int n ) {\n int a = 1 , b = 2 , c = 0 ;\n if ( n <= 2 ) {\n return n ;\n }\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n c = b + ( i - 1 ) * a ;\n a = b ;\n b = c ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n a , b , c = 1 , 2 , 0\n if ( n <= 2 ) :\n return n\n for i in range ( 3 , n + 1 ) :\n c = b + ( i - 1 ) * a\n a = b\n b = c\n return c\n\n"
},
{
"id": "python-java-FINDING_POWER_PRIME_NUMBER_P_N",
"pair": "python-java",
"Code1": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n",
"Code2": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n int count = 0 , temp = i ;\n while ( temp % p == 0 ) {\n count ++ ;\n temp = temp / p ;\n }\n ans += count ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return ans\n\n"
},
{
"id": "python-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF",
"pair": "python-java",
"Code1": "def findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n",
"Code2": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j += 2 ) {\n int length = j - i + 1 ;\n int leftsum = 0 , rightsum = 0 ;\n for ( int k = 0 ;\n k < length / 2 ;\n k ++ ) {\n leftsum += ( str . charAt ( i + k ) - ' 0 ' ) ;\n rightsum += ( str . charAt ( i + k + length / 2 ) - ' 0 ' ) ;\n }\n if ( leftsum == rightsum && maxlen < length ) maxlen = length ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLength ( str ) :\n n = len ( str )\n maxlen = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n , 2 ) :\n length = j - i + 1\n leftsum = 0\n rightsum = 0\n for k in range ( 0 , int ( length / 2 ) ) :\n leftsum += ( int ( str [ i + k ] ) - int ( '0' ) )\n rightsum += ( int ( str [ i + k + int ( length / 2 ) ] ) - int ( '0' ) )\n if ( leftsum == rightsum and maxlen < length ) :\n maxlen = length\n return maxlen\n\n"
},
{
"id": "python-java-ANALYSIS_OF_ALGORITHMS_SET_2_ASYMPTOTIC_ANALYSIS",
"pair": "python-java",
"Code1": "def search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) {\n return i ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n for i in range ( i , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-java-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM",
"pair": "python-java",
"Code1": "def subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "static void subArray ( int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n for ( int k = i ;\n k <= j ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subArray ( arr , n ) :\n for i in range ( 0 , n ) :\n for j in range ( i , n ) :\n for k in range ( i , j + 1 ) :\n print ( arr [ k ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-java-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8_1",
"pair": "python-java",
"Code1": "def isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n",
"Code2": "static boolean isSubSeqDivisible ( String str ) {\n int n = str . length ( ) ;\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n int arr [ ] = new int [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) arr [ i ] = ( int ) ( str . charAt ( i - 1 ) - ' 0 ' ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ arr [ i ] % 8 ] = 1 ;\n for ( int j = 0 ;\n j < 8 ;\n j ++ ) {\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ] ;\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n if ( dp [ i ] [ 0 ] == 1 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubSeqDivisible ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( 10 ) ] for i in range ( n + 1 ) ]\n arr = [ 0 for i in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n arr [ i ] = int ( str [ i - 1 ] )\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ arr [ i ] % 8 ] = 1\n for j in range ( 8 ) :\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] ) :\n dp [ i ] [ ( j * 10 + arr [ i ] ) % 8 ] = dp [ i - 1 ] [ j ]\n if ( dp [ i - 1 ] [ j ] > dp [ i ] [ j ] ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n for i in range ( 1 , n + 1 ) :\n if ( dp [ i ] [ 0 ] == 1 ) :\n return True\n return False\n\n"
},
{
"id": "python-java-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM",
"pair": "python-java",
"Code1": "def solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n",
"Code2": "static void solve ( int i , int par , int a [ ] , int n , int k , int current_ans ) {\n if ( par > k ) return ;\n if ( par == k && i == n - 1 ) {\n ans = Math . min ( ans , current_ans ) ;\n return ;\n }\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solve ( i , par , a , n , k , current_ans ) :\n if ( par > k ) :\n return 0\n global ans\n if ( par == k and i == n - 1 ) :\n ans = min ( ans , current_ans )\n return 0\n for j in range ( i + 1 , n ) :\n solve ( j , par + 1 , a , n , k , current_ans + ( a [ j ] - a [ i + 1 ] ) * ( a [ j ] - a [ i + 1 ] ) )\n\n"
},
{
"id": "python-java-SQUARE_ROOT_OF_A_PERFECT_SQUARE",
"pair": "python-java",
"Code1": "def squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n",
"Code2": "static float squareRoot ( float n ) {\n float x = n ;\n float y = 1 ;\n double e = 0.000001 ;\n while ( x - y > e ) {\n x = ( x + y ) / 2 ;\n y = n / x ;\n }\n return x ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef squareRoot ( n ) :\n x = n\n y = 1\n e = 0.000001\n while ( x - y > e ) :\n x = ( x + y ) / 2\n y = n / x\n return x\n\n"
},
{
"id": "python-java-COUNT_NUMBER_PAIRS_N_B_N_GCD_B_B",
"pair": "python-java",
"Code1": "def CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n",
"Code2": "static int CountPairs ( int n ) {\n int k = n ;\n int imin = 1 ;\n int ans = 0 ;\n while ( imin <= n ) {\n int imax = n / k ;\n ans += k * ( imax - imin + 1 ) ;\n imin = imax + 1 ;\n k = n / imin ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountPairs ( n ) :\n k = n\n imin = 1\n ans = 0\n while ( imin <= n ) :\n imax = n / k\n ans += k * ( imax - imin + 1 )\n imin = imax + 1\n k = n / imin\n return ans\n\n"
},
{
"id": "python-java-MULTIPLY_AN_INTEGER_WITH_3_5",
"pair": "python-java",
"Code1": "def multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n",
"Code2": "static int multiplyWith3Point5 ( int x ) {\n return ( x << 1 ) + x + ( x >> 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef multiplyWith3Point5 ( x ) :\n return ( x << 1 ) + x + ( x >> 1 )\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_PREVIOUS_PERMUTATION_IN_C",
"pair": "python-java",
"Code1": "def prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n",
"Code2": "static boolean prevPermutation ( char [ ] str ) {\n int n = str . length - 1 ;\n int i = n ;\n while ( i > 0 && str [ i - 1 ] <= str [ i ] ) {\n i -- ;\n }\n if ( i <= 0 ) {\n return false ;\n }\n int j = i - 1 ;\n while ( j + 1 <= n && str [ j + 1 ] <= str [ i - 1 ] ) {\n j ++ ;\n }\n swap ( str , i - 1 , j ) ;\n StringBuilder sb = new StringBuilder ( String . valueOf ( str ) ) ;\n sb . reverse ( ) ;\n str = sb . toString ( ) . toCharArray ( ) ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef prevPermutation ( str ) :\n n = len ( str ) - 1\n i = n\n while ( i > 0 and str [ i - 1 ] <= str [ i ] ) :\n i -= 1\n if ( i <= 0 ) :\n return False\n j = i - 1\n while ( j + 1 <= n and str [ j + 1 ] <= str [ i - 1 ] ) :\n j += 1\n str = list ( str )\n temp = str [ i - 1 ]\n str [ i - 1 ] = str [ j ]\n str [ j ] = temp\n str = ''.join ( str )\n str [ : : - 1 ]\n return True , str\n\n"
},
{
"id": "python-java-AREA_OF_A_POLYGON_WITH_GIVEN_N_ORDERED_VERTICES",
"pair": "python-java",
"Code1": "def polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n",
"Code2": "public static double polygonArea ( double X [ ] , double Y [ ] , int n ) {\n double area = 0.0 ;\n int j = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ;\n j = i ;\n }\n return Math . abs ( area / 2.0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef polygonArea ( X , Y , n ) :\n area = 0.0\n j = n - 1\n for i in range ( 0 , n ) :\n area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] )\n j = i\n return int ( abs ( area / 2.0 ) )\n\n"
},
{
"id": "python-java-EQUILIBRIUM_INDEX_OF_AN_ARRAY",
"pair": "python-java",
"Code1": "def equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int i , j ;\n int leftsum , rightsum ;\n for ( i = 0 ;\n i < n ;\n ++ i ) {\n leftsum = 0 ;\n for ( j = 0 ;\n j < i ;\n j ++ ) leftsum += arr [ j ] ;\n rightsum = 0 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) rightsum += arr [ j ] ;\n if ( leftsum == rightsum ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef equilibrium ( arr ) :\n leftsum = 0\n rightsum = 0\n n = len ( arr )\n for i in range ( n ) :\n leftsum = 0\n rightsum = 0\n for j in range ( i ) :\n leftsum += arr [ j ]\n for j in range ( i + 1 , n ) :\n rightsum += arr [ j ]\n if leftsum == rightsum :\n return i\n return - 1\n\n"
},
{
"id": "python-java-COUNT_WAYS_DIVIDE_CIRCLE_USING_N_NON_INTERSECTING_CHORDS",
"pair": "python-java",
"Code1": "def chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n",
"Code2": "static int chordCnt ( int A ) {\n int n = 2 * A ;\n int [ ] dpArray = new int [ n + 1 ] ;\n dpArray [ 0 ] = 1 ;\n dpArray [ 2 ] = 1 ;\n for ( int i = 4 ;\n i <= n ;\n i += 2 ) {\n for ( int j = 0 ;\n j < i - 1 ;\n j += 2 ) {\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] ) ;\n }\n }\n return dpArray [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef chordCnt ( A ) :\n n = 2 * A\n dpArray = [ 0 ] * ( n + 1 )\n dpArray [ 0 ] = 1\n dpArray [ 2 ] = 1\n for i in range ( 4 , n + 1 , 2 ) :\n for j in range ( 0 , i - 1 , 2 ) :\n dpArray [ i ] += ( dpArray [ j ] * dpArray [ i - 2 - j ] )\n return int ( dpArray [ n ] )\n\n"
},
{
"id": "python-java-FIND_HARMONIC_MEAN_USING_ARITHMETIC_MEAN_GEOMETRIC_MEAN",
"pair": "python-java",
"Code1": "def compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n",
"Code2": "static double compute ( int a , int b ) {\n double AM , GM , HM ;\n AM = ( a + b ) / 2 ;\n GM = Math . sqrt ( a * b ) ;\n HM = ( GM * GM ) / AM ;\n return HM ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef compute ( a , b ) :\n AM = ( a + b ) / 2\n GM = math.sqrt ( a * b )\n HM = ( GM * GM ) / AM\n return HM\n\n"
},
{
"id": "python-java-MAJORITY_ELEMENT",
"pair": "python-java",
"Code1": "def findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n",
"Code2": "static void findMajority ( int arr [ ] , int n ) {\n int maxCount = 0 ;\n int index = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count > maxCount ) {\n maxCount = count ;\n index = i ;\n }\n }\n if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ;\n else System . out . println ( \"No Majority Element\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMajority ( arr , n ) :\n maxCount = 0 ;\n index = - 1\n for i in range ( n ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ i ] == arr [ j ] ) :\n count += 1\n if ( count > maxCount ) :\n maxCount = count\n index = i\n if ( maxCount > n // 2 ) :\n print ( arr [ index ] )\n else :\n print ( \"No Majority Element\" )\n\n"
},
{
"id": "python-java-CHECK_NUMBER_IS_PERFECT_SQUARE_USING_ADDITIONSUBTRACTION",
"pair": "python-java",
"Code1": "def isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n",
"Code2": "static boolean isPerfectSquare ( int n ) {\n for ( int sum = 0 , i = 1 ;\n sum < n ;\n i += 2 ) {\n sum += i ;\n if ( sum == n ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPerfectSquare ( n ) :\n i = 1\n the_sum = 0\n while the_sum < n :\n the_sum += i\n if the_sum == n :\n return True\n i += 2\n return False\n\n"
},
{
"id": "python-java-FIND_THE_SMALLEST_WINDOW_IN_A_STRING_CONTAINING_ALL_CHARACTERS_OF_ANOTHER_STRING",
"pair": "python-java",
"Code1": "def findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n",
"Code2": "static String findSubString ( String str , String pat ) {\n int len1 = str . length ( ) ;\n int len2 = pat . length ( ) ;\n if ( len1 < len2 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n int hash_pat [ ] = new int [ no_of_chars ] ;\n int hash_str [ ] = new int [ no_of_chars ] ;\n for ( int i = 0 ;\n i < len2 ;\n i ++ ) hash_pat [ pat . charAt ( i ) ] ++ ;\n int start = 0 , start_index = - 1 , min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int j = 0 ;\n j < len1 ;\n j ++ ) {\n hash_str [ str . charAt ( j ) ] ++ ;\n if ( hash_pat [ str . charAt ( j ) ] != 0 && hash_str [ str . charAt ( j ) ] <= hash_pat [ str . charAt ( j ) ] ) count ++ ;\n if ( count == len2 ) {\n while ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] || hash_pat [ str . charAt ( start ) ] == 0 ) {\n if ( hash_str [ str . charAt ( start ) ] > hash_pat [ str . charAt ( start ) ] ) hash_str [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n if ( start_index == - 1 ) {\n System . out . println ( \"No such window exists\" ) ;\n return \"\" ;\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSubString ( string , pat ) :\n len1 = len ( string )\n len2 = len ( pat )\n if len1 < len2 :\n print ( \"No such window exists\" )\n return \"\"\n hash_pat = [ 0 ] * no_of_chars\n hash_str = [ 0 ] * no_of_chars\n for i in range ( 0 , len2 ) :\n hash_pat [ ord ( pat [ i ] ) ] += 1\n start , start_index , min_len = 0 , - 1 , float ( 'inf' )\n count = 0\n for j in range ( 0 , len1 ) :\n hash_str [ ord ( string [ j ] ) ] += 1\n if ( hash_pat [ ord ( string [ j ] ) ] != 0 and hash_str [ ord ( string [ j ] ) ] <= hash_pat [ ord ( string [ j ] ) ] ) :\n count += 1\n if count == len2 :\n while ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] or hash_pat [ ord ( string [ start ] ) ] == 0 ) :\n if ( hash_str [ ord ( string [ start ] ) ] > hash_pat [ ord ( string [ start ] ) ] ) :\n hash_str [ ord ( string [ start ] ) ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n if start_index == - 1 :\n print ( \"No such window exists\" )\n return \"\"\n return string [ start_index : start_index + min_len ]\n\n"
},
{
"id": "python-java-NUMBER_SUBSEQUENCES_STRING_DIVISIBLE_N",
"pair": "python-java",
"Code1": "def countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n",
"Code2": "static int countDivisibleSubseq ( String str , int n ) {\n int len = str . length ( ) ;\n int dp [ ] [ ] = new int [ len ] [ n ] ;\n dp [ 0 ] [ ( str . charAt ( 0 ) - ' 0 ' ) % n ] ++ ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) {\n dp [ i ] [ ( str . charAt ( i ) - ' 0 ' ) % n ] ++ ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ] ;\n dp [ i ] [ ( j * 10 + ( str . charAt ( i ) - ' 0 ' ) ) % n ] += dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ len - 1 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDivisibleSubseq ( str , n ) :\n l = len ( str )\n dp = [ [ 0 for x in range ( l ) ] for y in range ( n ) ]\n dp [ 0 ] [ ( ord ( str [ 0 ] ) - ord ( '0' ) ) % n ] += 1\n for i in range ( 1 , l ) :\n dp [ i ] [ ( ord ( str [ i ] ) - ord ( '0' ) ) % n ] += 1\n for j in range ( n ) :\n dp [ i ] [ j ] += dp [ i - 1 ] [ j ]\n dp [ i ] [ ( j * 10 + ( ord ( str [ i ] ) - ord ( '0' ) ) ) % n ] += dp [ i - 1 ] [ j ]\n return dp [ l - 1 ] [ 0 ]\n\n"
},
{
"id": "python-java-MINIMUM_POSSIBLE_VALUE_AI_AJ_K_GIVEN_ARRAY_K",
"pair": "python-java",
"Code1": "def pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n",
"Code2": "static void pairs ( int arr [ ] , int n , int k ) {\n int smallest = Integer . MAX_VALUE ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( Math . abs ( arr [ i ] + arr [ j ] - k ) < smallest ) {\n smallest = Math . abs ( arr [ i ] + arr [ j ] - k ) ;\n count = 1 ;\n }\n else if ( Math . abs ( arr [ i ] + arr [ j ] - k ) == smallest ) count ++ ;\n }\n System . out . println ( \"Minimal Value = \" + smallest ) ;\n System . out . println ( \"Total Pairs = \" + count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pairs ( arr , n , k ) :\n smallest = 999999999999\n count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] + arr [ j ] - k ) < smallest :\n smallest = abs ( arr [ i ] + arr [ j ] - k )\n count = 1\n elif abs ( arr [ i ] + arr [ j ] - k ) == smallest :\n count += 1\n print ( \"Minimal Value = \" , smallest )\n print ( \"Total Pairs = \" , count )\n\n"
},
{
"id": "python-java-ZECKENDORFS_THEOREM_NON_NEIGHBOURING_FIBONACCI_REPRESENTATION",
"pair": "python-java",
"Code1": "def nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n",
"Code2": "public static int nearestSmallerEqFib ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n int f1 = 0 , f2 = 1 , f3 = 1 ;\n while ( f3 <= n ) {\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n }\n return f2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nearestSmallerEqFib ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n f1 , f2 , f3 = 0 , 1 , 1\n while ( f3 <= n ) :\n f1 = f2 ;\n f2 = f3 ;\n f3 = f1 + f2 ;\n return f2 ;\n\n"
},
{
"id": "python-java-SHUFFLE_A_DECK_OF_CARDS_3",
"pair": "python-java",
"Code1": "def shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n",
"Code2": "public static void shuffle ( int card [ ] , int n ) {\n Random rand = new Random ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int r = i + rand . nextInt ( 52 - i ) ;\n int temp = card [ r ] ;\n card [ r ] = card [ i ] ;\n card [ i ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef shuffle ( card , n ) :\n for i in range ( n ) :\n r = i + ( random.randint ( 0 , 55 ) % ( 52 - i ) )\n tmp = card [ i ]\n card [ i ] = card [ r ]\n card [ r ] = tmp\n\n"
},
{
"id": "python-java-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM_1",
"pair": "python-java",
"Code1": "def maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n",
"Code2": "static int maxLen ( int arr [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( arr [ i ] == 0 && max_len == 0 ) max_len = 1 ;\n if ( sum == 0 ) max_len = i + 1 ;\n Integer prev_i = hM . get ( sum ) ;\n if ( prev_i != null ) max_len = Math . max ( max_len , i - prev_i ) ;\n else hM . put ( sum , i ) ;\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLen ( arr ) :\n hash_map = { }\n max_len = 0\n curr_sum = 0\n for i in range ( len ( arr ) ) :\n curr_sum += arr [ i ]\n if arr [ i ] is 0 and max_len is 0 :\n max_len = 1\n if curr_sum is 0 :\n max_len = i + 1\n if curr_sum in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum ] )\n else :\n hash_map [ curr_sum ] = i\n return max_len\n\n"
},
{
"id": "python-java-LENGTH_LONGEST_BALANCED_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n",
"Code2": "static int maxLength ( String s , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( s . charAt ( i ) == ' ( ' && s . charAt ( i + 1 ) == ' ) ' ) dp [ i ] [ i + 1 ] = 2 ;\n for ( int l = 2 ;\n l < n ;\n l ++ ) {\n for ( int i = 0 , j = l ;\n j < n ;\n i ++ , j ++ ) {\n if ( s . charAt ( i ) == ' ( ' && s . charAt ( j ) == ' ) ' ) dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ] ;\n for ( int k = i ;\n k < j ;\n k ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] ) ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLength ( s , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n - 1 ) :\n if ( s [ i ] == '(' and s [ i + 1 ] == ')' ) :\n dp [ i ] [ i + 1 ] = 2\n for l in range ( 2 , n ) :\n i = - 1\n for j in range ( l , n ) :\n i += 1\n if ( s [ i ] == '(' and s [ j ] == ')' ) :\n dp [ i ] [ j ] = 2 + dp [ i + 1 ] [ j - 1 ]\n for k in range ( i , j ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i ] [ k ] + dp [ k + 1 ] [ j ] )\n return dp [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-PROGRAM_PRINT_SUM_GIVEN_NTH_TERM_1",
"pair": "python-java",
"Code1": "def summingSeries ( n ) :\n return math.pow ( n , 2 )\n",
"Code2": "static int summingSeries ( long n ) {\n return ( int ) Math . pow ( n , 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef summingSeries ( n ) :\n return math.pow ( n , 2 )\n\n"
},
{
"id": "python-java-SUBSET_SUM_PROBLEM_OSUM_SPACE",
"pair": "python-java",
"Code1": "def isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n",
"Code2": "static boolean isSubsetSum ( int arr [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ 2 ] [ sum + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= sum ;\n j ++ ) {\n if ( j == 0 ) subset [ i % 2 ] [ j ] = true ;\n else if ( i == 0 ) subset [ i % 2 ] [ j ] = false ;\n else if ( arr [ i - 1 ] <= j ) subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] || subset [ ( i + 1 ) % 2 ] [ j ] ;\n else subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ] ;\n }\n }\n return subset [ n % 2 ] [ sum ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( arr , n , sum ) :\n subset = [ [ False for j in range ( sum + 1 ) ] for i in range ( 3 ) ]\n for i in range ( n + 1 ) :\n for j in range ( sum + 1 ) :\n if ( j == 0 ) :\n subset [ i % 2 ] [ j ] = True\n elif ( i == 0 ) :\n subset [ i % 2 ] [ j ] = False\n elif ( arr [ i - 1 ] <= j ) :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j - arr [ i - 1 ] ] or subset [ ( i + 1 ) % 2 ] [ j ]\n else :\n subset [ i % 2 ] [ j ] = subset [ ( i + 1 ) % 2 ] [ j ]\n return subset [ n % 2 ] [ sum ]\n\n"
},
{
"id": "python-java-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n",
"Code2": "static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findExtra ( arr1 , arr2 , n ) :\n for i in range ( 0 , n ) :\n if ( arr1 [ i ] != arr2 [ i ] ) :\n return i\n return n\n\n"
},
{
"id": "python-java-NUMBER_OF_PERMUTATION_WITH_K_INVERSIONS",
"pair": "python-java",
"Code1": "def numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n",
"Code2": "static int numberOfPermWithKInversion ( int N , int K ) {\n if ( N == 0 ) return 0 ;\n if ( K == 0 ) return 1 ;\n if ( memo [ N ] [ K ] != 0 ) return memo [ N ] [ K ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= K ;\n i ++ ) {\n if ( i <= N - 1 ) sum += numberOfPermWithKInversion ( N - 1 , K - i ) ;\n }\n memo [ N ] [ K ] = sum ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfPermWithKInversion ( N , K ) :\n if ( N == 0 ) : return 0\n if ( K == 0 ) : return 1\n if ( memo [ N ] [ K ] != 0 ) :\n return memo [ N ] [ K ]\n sum = 0\n for i in range ( K + 1 ) :\n if ( i <= N - 1 ) :\n sum += numberOfPermWithKInversion ( N - 1 , K - i )\n memo [ N ] [ K ] = sum\n return sum\n\n"
},
{
"id": "python-java-DELETE_CONSECUTIVE_WORDS_SEQUENCE_1",
"pair": "python-java",
"Code1": "def removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n",
"Code2": "static int removeConsecutiveSame ( Vector < String > v ) {\n Stack < String > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n if ( st . empty ( ) ) st . push ( v . get ( i ) ) ;\n else {\n String str = st . peek ( ) ;\n if ( str . equals ( v . get ( i ) ) ) st . pop ( ) ;\n else st . push ( v . get ( i ) ) ;\n }\n }\n return st . size ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef removeConsecutiveSame ( v ) :\n st = [ ]\n for i in range ( len ( v ) ) :\n if ( len ( st ) == 0 ) :\n st.append ( v [ i ] )\n else :\n Str = st [ - 1 ]\n if ( Str == v [ i ] ) :\n st.pop ( )\n else :\n st.append ( v [ i ] )\n return len ( st )\n\n"
},
{
"id": "python-java-MINIMUM_INDEX_SUM_COMMON_ELEMENTS_TWO_LISTS",
"pair": "python-java",
"Code1": "def find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n",
"Code2": "static void find ( Vector < String > list1 , Vector < String > list2 ) {\n Vector < String > res = new Vector < > ( ) ;\n int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ;\n for ( int sum = 0 ;\n sum <= max_possible_sum ;\n sum ++ ) {\n for ( int i = 0 ;\n i <= sum ;\n i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ;\n if ( res . size ( ) > 0 ) break ;\n }\n for ( int i = 0 ;\n i < res . size ( ) ;\n i ++ ) System . out . print ( res . get ( i ) + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find ( list1 , list2 ) :\n res = [ ]\n max_possible_sum = len ( list1 ) + len ( list2 ) - 2\n for sum in range ( max_possible_sum + 1 ) :\n for i in range ( sum + 1 ) :\n if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :\n res.append ( list1 [ i ] )\n if ( len ( res ) > 0 ) :\n break\n for i in range ( len ( res ) ) :\n print ( res [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-NON_REPEATING_ELEMENT",
"pair": "python-java",
"Code1": "def firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n",
"Code2": "static int firstNonRepeating ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < n ;\n j ++ ) if ( i != j && arr [ i ] == arr [ j ] ) break ;\n if ( j == n ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstNonRepeating ( arr , n ) :\n for i in range ( n ) :\n j = 0\n while ( j < n ) :\n if ( i != j and arr [ i ] == arr [ j ] ) :\n break\n j += 1\n if ( j == n ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-java-HOW_TO_BEGIN_WITH_COMPETITIVE_PROGRAMMING",
"pair": "python-java",
"Code1": "def search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , x ) :\n n = len ( arr )\n for j in range ( 0 , n ) :\n if ( x == arr [ j ] ) :\n return j\n return - 1\n\n"
},
{
"id": "python-java-SUM_MIDDLE_ROW_COLUMN_MATRIX",
"pair": "python-java",
"Code1": "def middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n",
"Code2": "static void middlesum ( int mat [ ] [ ] , int n ) {\n int row_sum = 0 , col_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) row_sum += mat [ n / 2 ] [ i ] ;\n System . out . println ( \"Sum of middle row = \" + row_sum ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) col_sum += mat [ i ] [ n / 2 ] ;\n System . out . println ( \"Sum of middle column = \" + col_sum ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef middlesum ( mat , n ) :\n row_sum = 0\n col_sum = 0\n for i in range ( n ) :\n row_sum += mat [ n // 2 ] [ i ]\n print ( \"Sum of middle row = \" , row_sum )\n for i in range ( n ) :\n col_sum += mat [ i ] [ n // 2 ]\n print ( \"Sum of middle column = \" , col_sum )\n\n"
},
{
"id": "python-java-MULTIPLY_LARGE_INTEGERS_UNDER_LARGE_MODULO",
"pair": "python-java",
"Code1": "def moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n",
"Code2": "static long moduloMultiplication ( long a , long b , long mod ) {\n long res = 0 ;\n a %= mod ;\n while ( b > 0 ) {\n if ( ( b & 1 ) > 0 ) {\n res = ( res + a ) % mod ;\n }\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef moduloMultiplication ( a , b , mod ) :\n res = 0 ;\n a = a % mod ;\n while ( b ) :\n if ( b & 1 ) :\n res = ( res + a ) % mod ;\n a = ( 2 * a ) % mod ;\n b >>= 1 ;\n return res ;\n\n"
},
{
"id": "python-java-GENERATE_PYTHAGOREAN_TRIPLETS",
"pair": "python-java",
"Code1": "def pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n",
"Code2": "static void pythagoreanTriplets ( int limit ) {\n int a , b , c = 0 ;\n int m = 2 ;\n while ( c < limit ) {\n for ( int n = 1 ;\n n < m ;\n ++ n ) {\n a = m * m - n * n ;\n b = 2 * m * n ;\n c = m * m + n * n ;\n if ( c > limit ) break ;\n System . out . println ( a + \" \" + b + \" \" + c ) ;\n }\n m ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pythagoreanTriplets ( limits ) :\n c , m = 0 , 2\n while c < limits :\n for n in range ( 1 , m ) :\n a = m * m - n * n\n b = 2 * m * n\n c = m * m + n * n\n if c > limits :\n break\n print ( a , b , c )\n m = m + 1\n\n"
},
{
"id": "python-java-SUM_PAIRWISE_PRODUCTS_2",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n",
"Code2": "static int findSum ( int n ) {\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n return n * ( n + 1 ) * ( n + 2 ) * ( 3 * n + 1 ) / 24\n\n"
},
{
"id": "python-java-PROGRAM_FOR_NTH_FIBONACCI_NUMBER_2",
"pair": "python-java",
"Code1": "def fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n",
"Code2": "public static int fib ( int n ) {\n if ( n == 0 ) return 0 ;\n if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ;\n if ( f [ n ] != 0 ) return f [ n ] ;\n int k = ( n & 1 ) == 1 ? ( n + 1 ) / 2 : n / 2 ;\n f [ n ] = ( n & 1 ) == 1 ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if ( n == 0 ) :\n return 0\n if ( n == 1 or n == 2 ) :\n f [ n ] = 1\n return ( f [ n ] )\n if ( f [ n ] ) :\n return f [ n ]\n if ( n & 1 ) :\n k = ( n + 1 ) // 2\n else :\n k = n // 2\n if ( ( n & 1 ) ) :\n f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )\n else :\n f [ n ] = ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k )\n return f [ n ]\n\n"
},
{
"id": "python-java-GIVEN_P_AND_N_FIND_THE_LARGEST_X_SUCH_THAT_PX_DIVIDES_N_2",
"pair": "python-java",
"Code1": "def largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n",
"Code2": "static int Largestpower ( int n , int p ) {\n int ans = 0 ;\n while ( n > 0 ) {\n n /= p ;\n ans += n ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largestPower ( n , p ) :\n x = 0\n while n :\n n /= p\n x += n\n return x\n\n"
},
{
"id": "python-java-PROGRAM_PRINT_IDENTITY_MATRIX_1",
"pair": "python-java",
"Code1": "def isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n",
"Code2": "static boolean isIdentity ( int mat [ ] [ ] , int N ) {\n for ( int row = 0 ;\n row < N ;\n row ++ ) {\n for ( int col = 0 ;\n col < N ;\n col ++ ) {\n if ( row == col && mat [ row ] [ col ] != 1 ) return false ;\n else if ( row != col && mat [ row ] [ col ] != 0 ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isIdentity ( mat , N ) :\n for row in range ( N ) :\n for col in range ( N ) :\n if ( row == col and mat [ row ] [ col ] != 1 ) :\n return False\n elif ( row != col and mat [ row ] [ col ] != 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-MINIMUM_CELLS_REQUIRED_REACH_DESTINATION_JUMPS_EQUAL_CELL_VALUES",
"pair": "python-java",
"Code1": "def minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n",
"Code2": "static int minCells ( int mat [ ] [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ i ] [ j ] = Integer . MAX_VALUE ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( j + mat [ i ] [ j ] ) < n && ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1 ;\n if ( dp [ i ] [ j ] != Integer . MAX_VALUE && ( i + mat [ i ] [ j ] ) < m && ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1 ;\n }\n }\n if ( dp [ m - 1 ] [ n - 1 ] != Integer . MAX_VALUE ) return dp [ m - 1 ] [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCells ( mat , m , n ) :\n dp = [ [ MAX for i in range ( n ) ] for i in range ( m ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( m ) :\n for j in range ( n ) :\n if ( dp [ i ] [ j ] != MAX and ( j + mat [ i ] [ j ] ) < n and ( dp [ i ] [ j ] + 1 ) < dp [ i ] [ j + mat [ i ] [ j ] ] ) :\n dp [ i ] [ j + mat [ i ] [ j ] ] = dp [ i ] [ j ] + 1\n if ( dp [ i ] [ j ] != MAX and ( i + mat [ i ] [ j ] ) < m and ( dp [ i ] [ j ] + 1 ) < dp [ i + mat [ i ] [ j ] ] [ j ] ) :\n dp [ i + mat [ i ] [ j ] ] [ j ] = dp [ i ] [ j ] + 1\n if ( dp [ m - 1 ] [ n - 1 ] != MAX ) :\n return dp [ m - 1 ] [ n - 1 ]\n return - 1\n\n"
},
{
"id": "python-java-REARRANGE_BINARY_STRING_ALTERNATE_X_Y_OCCURRENCES",
"pair": "python-java",
"Code1": "def arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n",
"Code2": "static void arrangeString ( String str , int x , int y ) {\n int count_0 = 0 ;\n int count_1 = 0 ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' ) count_0 ++ ;\n else count_1 ++ ;\n }\n while ( count_0 > 0 || count_1 > 0 ) {\n for ( int j = 0 ;\n j < x && count_0 > 0 ;\n j ++ ) {\n if ( count_0 > 0 ) {\n System . out . print ( \"0\" ) ;\n count_0 -- ;\n }\n }\n for ( int j = 0 ;\n j < y && count_1 > 0 ;\n j ++ ) {\n if ( count_1 > 0 ) {\n System . out . print ( \"1\" ) ;\n count_1 -- ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arrangeString ( str1 , x , y ) :\n count_0 = 0\n count_1 = 0\n n = len ( str1 )\n for i in range ( n ) :\n if str1 [ i ] == '0' :\n count_0 += 1\n else :\n count_1 += 1\n while count_0 > 0 or count_1 > 0 :\n for i in range ( 0 , x ) :\n if count_0 > 0 :\n print ( \"0\" , end = \"\" )\n count_0 -= 1\n for j in range ( 0 , y ) :\n if count_1 > 0 :\n print ( \"1\" , end = \"\" )\n count_1 -= 1\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_DELETIONS_MAKE_STRING_PALINDROME_SET_2",
"pair": "python-java",
"Code1": "def getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n",
"Code2": "static int getLevenstein ( StringBuilder input ) {\n StringBuilder revInput = new StringBuilder ( input ) ;\n revInput = revInput . reverse ( ) ;\n int n = input . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) {\n dp [ 0 ] [ i ] = i ;\n dp [ i ] [ 0 ] = i ;\n }\n for ( int i = 1 ;\n i <= n ;\n ++ i ) {\n for ( int j = 1 ;\n j <= n ;\n ++ j ) {\n if ( input . charAt ( i - 1 ) == revInput . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int i = n , j = 0 ;\n i >= 0 ;\n i -- , j ++ ) {\n res = Math . min ( res , dp [ i ] [ j ] ) ;\n if ( i < n ) res = Math . min ( res , dp [ i + 1 ] [ j ] ) ;\n if ( i > 0 ) res = Math . min ( res , dp [ i - 1 ] [ j ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getLevenstein ( inpt ) :\n revInput = inpt [ : : - 1 ]\n n = len ( inpt )\n dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ 0 ] [ i ] = i\n dp [ i ] [ 0 ] = i\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if inpt [ i - 1 ] == revInput [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n res = INT_MAX\n i , j = n , 0\n while i >= 0 :\n res = min ( res , dp [ i ] [ j ] )\n if i < n :\n res = min ( res , dp [ i + 1 ] [ j ] )\n if i > 0 :\n res = min ( res , dp [ i - 1 ] [ j ] )\n i -= 1\n j += 1\n return res\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_34_ASSEMBLY_LINE_SCHEDULING",
"pair": "python-java",
"Code1": "def carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n",
"Code2": "static int carAssembly ( int a [ ] [ ] , int t [ ] [ ] , int e [ ] , int x [ ] ) {\n int T1 [ ] = new int [ NUM_STATION ] ;\n int T2 [ ] = new int [ NUM_STATION ] ;\n int i ;\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ] ;\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ] ;\n for ( i = 1 ;\n i < NUM_STATION ;\n ++ i ) {\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] ) ;\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] ) ;\n }\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef carAssembly ( a , t , e , x ) :\n NUM_STATION = len ( a [ 0 ] )\n T1 = [ 0 for i in range ( NUM_STATION ) ]\n T2 = [ 0 for i in range ( NUM_STATION ) ]\n T1 [ 0 ] = e [ 0 ] + a [ 0 ] [ 0 ]\n T2 [ 0 ] = e [ 1 ] + a [ 1 ] [ 0 ]\n for i in range ( 1 , NUM_STATION ) :\n T1 [ i ] = min ( T1 [ i - 1 ] + a [ 0 ] [ i ] , T2 [ i - 1 ] + t [ 1 ] [ i ] + a [ 0 ] [ i ] )\n T2 [ i ] = min ( T2 [ i - 1 ] + a [ 1 ] [ i ] , T1 [ i - 1 ] + t [ 0 ] [ i ] + a [ 1 ] [ i ] )\n return min ( T1 [ NUM_STATION - 1 ] + x [ 0 ] , T2 [ NUM_STATION - 1 ] + x [ 1 ] )\n\n"
},
{
"id": "python-java-BASIC_AND_EXTENDED_EUCLIDEAN_ALGORITHMS",
"pair": "python-java",
"Code1": "def gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n",
"Code2": "public static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n return gcd ( b % a , a ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if a == 0 :\n return b\n return gcd ( b % a , a )\n\n"
},
{
"id": "python-java-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_2",
"pair": "python-java",
"Code1": "def findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n",
"Code2": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int l = i + 1 ;\n int r = n - 1 ;\n int x = arr [ i ] ;\n while ( l < r ) {\n if ( x + arr [ l ] + arr [ r ] == 0 ) {\n System . out . print ( x + \" \" ) ;\n System . out . print ( arr [ l ] + \" \" ) ;\n System . out . println ( arr [ r ] + \" \" ) ;\n l ++ ;\n r -- ;\n found = true ;\n }\n else if ( x + arr [ l ] + arr [ r ] < 0 ) l ++ ;\n else r -- ;\n }\n }\n if ( found == false ) System . out . println ( \" No Triplet Found\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findTriplets ( arr , n ) :\n found = False\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n l = i + 1\n r = n - 1\n x = arr [ i ]\n while ( l < r ) :\n if ( x + arr [ l ] + arr [ r ] == 0 ) :\n print ( x , arr [ l ] , arr [ r ] )\n l += 1\n r -= 1\n found = True\n elif ( x + arr [ l ] + arr [ r ] < 0 ) :\n l += 1\n else :\n r -= 1\n if ( found == False ) :\n print ( \" No Triplet Found\" )\n\n"
},
{
"id": "python-java-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES_2",
"pair": "python-java",
"Code1": "def getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n",
"Code2": "int getOddOccurrence ( int ar [ ] , int ar_size ) {\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < ar_size ;\n i ++ ) {\n res = res ^ ar [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getOddOccurrence ( arr ) :\n res = 0\n for element in arr :\n res = res ^ element\n return res\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_HIGH_EFFORT_VS_LOW_EFFORT_TASKS_PROBLEM",
"pair": "python-java",
"Code1": "def maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n",
"Code2": "static int maxTasks ( int high [ ] , int low [ ] , int n ) {\n if ( n <= 0 ) return 0 ;\n return Math . max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxTasks ( high , low , n ) :\n if ( n <= 0 ) :\n return 0\n return max ( high [ n - 1 ] + maxTasks ( high , low , ( n - 2 ) ) , low [ n - 1 ] + maxTasks ( high , low , ( n - 1 ) ) )\n\n"
},
{
"id": "python-java-FIND_TWO_SIDES_RIGHT_ANGLE_TRIANGLE",
"pair": "python-java",
"Code1": "def printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n",
"Code2": "static void printOtherSides ( int n ) {\n if ( n % 2 != 0 ) {\n if ( n == 1 ) System . out . println ( \"-1\" ) ;\n else {\n int b = ( n * n - 1 ) / 2 ;\n int c = ( n * n + 1 ) / 2 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n else {\n if ( n == 2 ) System . out . println ( \"-1\" ) ;\n else {\n int b = n * n / 4 - 1 ;\n int c = n * n / 4 + 1 ;\n System . out . println ( \"b = \" + b + \", c = \" + c ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printOtherSides ( n ) :\n if ( n & 1 ) :\n if ( n == 1 ) :\n print ( - 1 )\n else :\n b = ( n * n - 1 ) // 2\n c = ( n * n + 1 ) // 2\n print ( \"b =\" , b , \", c =\" , c )\n else :\n if ( n == 2 ) :\n print ( - 1 )\n else :\n b = n * n // 4 - 1\n c = n * n // 4 + 1\n print ( \"b =\" , b\", c =\" , c )\n\n"
},
{
"id": "python-java-MINIMUM_LENGTH_UNSORTED_SUBARRAY_SORTING_WHICH_MAKES_THE_COMPLETE_ARRAY_SORTED",
"pair": "python-java",
"Code1": "def printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n",
"Code2": "static void printUnsorted ( int arr [ ] , int n ) {\n int s = 0 , e = n - 1 , i , max , min ;\n for ( s = 0 ;\n s < n - 1 ;\n s ++ ) {\n if ( arr [ s ] > arr [ s + 1 ] ) break ;\n }\n if ( s == n - 1 ) {\n System . out . println ( \"The complete array is sorted\" ) ;\n return ;\n }\n for ( e = n - 1 ;\n e > 0 ;\n e -- ) {\n if ( arr [ e ] < arr [ e - 1 ] ) break ;\n }\n max = arr [ s ] ;\n min = arr [ s ] ;\n for ( i = s + 1 ;\n i <= e ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n if ( arr [ i ] < min ) min = arr [ i ] ;\n }\n for ( i = 0 ;\n i < s ;\n i ++ ) {\n if ( arr [ i ] > min ) {\n s = i ;\n break ;\n }\n }\n for ( i = n - 1 ;\n i >= e + 1 ;\n i -- ) {\n if ( arr [ i ] < max ) {\n e = i ;\n break ;\n }\n }\n System . out . println ( \" The unsorted subarray which\" + \" makes the given array sorted lies\" + \" between the indices \" + s + \" and \" + e ) ;\n return ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printUnsorted ( arr , n ) :\n e = n - 1\n for s in range ( 0 , n - 1 ) :\n if arr [ s ] > arr [ s + 1 ] :\n break\n if s == n - 1 :\n print ( \"The complete array is sorted\" )\n exit ( )\n e = n - 1\n while e > 0 :\n if arr [ e ] < arr [ e - 1 ] :\n break\n e -= 1\n max = arr [ s ]\n min = arr [ s ]\n for i in range ( s + 1 , e + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n if arr [ i ] < min :\n min = arr [ i ]\n for i in range ( s ) :\n if arr [ i ] > min :\n s = i\n break\n i = n - 1\n while i >= e + 1 :\n if arr [ i ] < max :\n e = i\n break\n i -= 1\n print ( \"The unsorted subarray which makes the given array\" )\n print ( \"sorted lies between the indexes %d and %d\" % ( s , e ) )\n\n"
},
{
"id": "python-java-CHECK_TWO_GIVEN_CIRCLES_TOUCH_INTERSECT",
"pair": "python-java",
"Code1": "def circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n",
"Code2": "static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) {\n int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ;\n int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ;\n if ( distSq == radSumSq ) return 1 ;\n else if ( distSq > radSumSq ) return - 1 ;\n else return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef circle ( x1 , y1 , x2 , y2 , r1 , r2 ) :\n distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 )\n radSumSq = ( r1 + r2 ) * ( r1 + r2 )\n if ( distSq == radSumSq ) :\n return 1\n elif ( distSq > radSumSq ) :\n return - 1\n else :\n return 0\n\n"
},
{
"id": "python-java-COUNT_DISTINCT_ELEMENTS_IN_EVERY_WINDOW_OF_SIZE_K",
"pair": "python-java",
"Code1": "def countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n",
"Code2": "static void countDistinct ( int arr [ ] , int k ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int dist_count = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n }\n System . out . println ( dist_count ) ;\n for ( int i = k ;\n i < arr . length ;\n i ++ ) {\n if ( hM . get ( arr [ i - k ] ) == 1 ) {\n hM . remove ( arr [ i - k ] ) ;\n dist_count -- ;\n }\n else {\n int count = hM . get ( arr [ i - k ] ) ;\n hM . put ( arr [ i - k ] , count - 1 ) ;\n }\n if ( hM . get ( arr [ i ] ) == null ) {\n hM . put ( arr [ i ] , 1 ) ;\n dist_count ++ ;\n }\n else {\n int count = hM . get ( arr [ i ] ) ;\n hM . put ( arr [ i ] , count + 1 ) ;\n }\n System . out . println ( dist_count ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDistinct ( arr , k , n ) :\n mp = defaultdict ( lambda : 0 )\n dist_count = 0\n for i in range ( k ) :\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n for i in range ( k , n ) :\n if mp [ arr [ i - k ] ] == 1 :\n dist_count -= 1\n mp [ arr [ i - k ] ] -= 1\n if mp [ arr [ i ] ] == 0 :\n dist_count += 1\n mp [ arr [ i ] ] += 1\n print ( dist_count )\n\n"
},
{
"id": "python-java-PROGRAM_TO_FIND_THE_AREA_OF_PENTAGON",
"pair": "python-java",
"Code1": "def findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n",
"Code2": "static float findArea ( float a ) {\n float area ;\n area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findArea ( a ) :\n area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4\n return area\n\n"
},
{
"id": "python-java-COUNT_ROTATIONS_DIVISIBLE_8",
"pair": "python-java",
"Code1": "def countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n",
"Code2": "static int countRotationsDivBy8 ( String n ) {\n int len = n . length ( ) ;\n int count = 0 ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 8 == 0 ) return 1 ;\n return 0 ;\n }\n if ( len == 2 ) {\n int first = ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n int second = ( n . charAt ( 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( first % 8 == 0 ) count ++ ;\n if ( second % 8 == 0 ) count ++ ;\n return count ;\n }\n int threeDigit ;\n for ( int i = 0 ;\n i < ( len - 2 ) ;\n i ++ ) {\n threeDigit = ( n . charAt ( i ) - ' 0 ' ) * 100 + ( n . charAt ( i + 1 ) - ' 0 ' ) * 10 + ( n . charAt ( i + 2 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n }\n threeDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 100 + ( n . charAt ( 0 ) - ' 0 ' ) * 10 + ( n . charAt ( 1 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n threeDigit = ( n . charAt ( len - 2 ) - ' 0 ' ) * 100 + ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( threeDigit % 8 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countRotationsDivBy8 ( n ) :\n l = len ( n )\n count = 0\n if ( l == 1 ) :\n oneDigit = int ( n [ 0 ] )\n if ( oneDigit % 8 == 0 ) :\n return 1\n return 0\n if ( l == 2 ) :\n first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )\n second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )\n if ( first % 8 == 0 ) :\n count += 1\n if ( second % 8 == 0 ) :\n count += 1\n return count\n threeDigit = 0\n for i in range ( 0 , ( l - 2 ) ) :\n threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )\n if ( threeDigit % 8 == 0 ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-LONGEST_COMMON_SUBSEQUENCE_WITH_AT_MOST_K_CHANGES_ALLOWED",
"pair": "python-java",
"Code1": "def lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n",
"Code2": "static int lcs ( int [ ] [ ] [ ] dp , int [ ] arr1 , int n , int [ ] arr2 , int m , int k ) {\n if ( k < 0 ) return - 10000000 ;\n if ( n < 0 || m < 0 ) return 0 ;\n int ans = dp [ n ] [ m ] [ k ] ;\n if ( ans != - 1 ) return ans ;\n try {\n ans = Math . max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) ) ;\n if ( arr1 [ n - 1 ] == arr2 [ m - 1 ] ) ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) ) ;\n ans = Math . max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) ) ;\n }\n catch ( Exception e ) {\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lcs ( dp , arr1 , n , arr2 , m , k ) :\n if k < 0 :\n return - ( 10 ** 7 )\n if n < 0 or m < 0 :\n return 0\n ans = dp [ n ] [ m ] [ k ]\n if ans != - 1 :\n return ans\n ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )\n if arr1 [ n - 1 ] == arr2 [ m - 1 ] :\n ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )\n ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )\n return ans\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_5_EDIT_DISTANCE_1",
"pair": "python-java",
"Code1": "def editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"Code2": "static int editDistDP ( String str1 , String str2 , int m , int n ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef editDistDP ( str1 , str2 , m , n ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 :\n dp [ i ] [ j ] = j\n elif j == 0 :\n dp [ i ] [ j ] = i\n elif str1 [ i - 1 ] == str2 [ j - 1 ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j - 1 ] )\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-java-FIND_NUMBER_TRANSFORMATION_MAKE_TWO_MATRIX_EQUAL",
"pair": "python-java",
"Code1": "def countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n",
"Code2": "static int countOps ( int A [ ] [ ] , int B [ ] [ ] , int m , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) A [ i ] [ j ] -= B [ i ] [ j ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < m ;\n j ++ ) if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) return - 1 ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += Math . abs ( A [ i ] [ 0 ] ) ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) result += Math . abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] ) ;\n return ( result ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOps ( A , B , m , n ) :\n for i in range ( n ) :\n for j in range ( m ) :\n A [ i ] [ j ] -= B [ i ] [ j ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( A [ i ] [ j ] - A [ i ] [ 0 ] - A [ 0 ] [ j ] + A [ 0 ] [ 0 ] != 0 ) :\n return - 1\n result = 0\n for i in range ( n ) :\n result += abs ( A [ i ] [ 0 ] )\n for j in range ( m ) :\n result += abs ( A [ 0 ] [ j ] - A [ 0 ] [ 0 ] )\n return ( result )\n\n"
},
{
"id": "python-java-LONGEST_ALTERNATING_POSITIVE_NEGATIVE_SUBARRAY_STARTING_EVERY_INDEX",
"pair": "python-java",
"Code1": "def longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n",
"Code2": "public static void longestAlternating ( int arr [ ] , int n ) {\n int [ ] count = new int [ n ] ;\n count [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) count [ i ] = count [ i + 1 ] + 1 ;\n else count [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestAlternating ( arr , n ) :\n count = [ None ] * n\n count [ n - 1 ] = 1\n i = n - 2\n while i >= 0 :\n if ( arr [ i ] * arr [ i + 1 ] < 0 ) :\n count [ i ] = count [ i + 1 ] + 1\n else :\n count [ i ] = 1\n i = i - 1\n i = 0\n while i < n :\n print ( count [ i ] , end = \" \" )\n i = i + 1\n\n"
},
{
"id": "python-java-FIND_ALL_DIVISORS_OF_A_NATURAL_NUMBER_SET_2",
"pair": "python-java",
"Code1": "def printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n",
"Code2": "static void printDivisors ( int n ) {\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( n / i == i ) System . out . printf ( \"%d \" , i ) ;\n else {\n System . out . printf ( \"%d \" , i ) ;\n v . add ( n / i ) ;\n }\n }\n }\n for ( int i = v . size ( ) - 1 ;\n i >= 0 ;\n i -- ) System . out . printf ( \"%d \" , v . get ( i ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDivisors ( n ) :\n list = [ ]\n for i in range ( 1 , int ( math.sqrt ( n ) + 1 ) ) :\n if ( n % i == 0 ) :\n if ( n / i == i ) :\n print ( i , end = \" \" )\n else :\n print ( i , end = \" \" )\n list.append ( int ( n / i ) )\n for i in list [ : : - 1 ] :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-java-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER",
"pair": "python-java",
"Code1": "def isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n",
"Code2": "public static boolean isPower ( int x , int y ) {\n if ( x == 1 ) return ( y == 1 ) ;\n int pow = 1 ;\n while ( pow < y ) pow = pow * x ;\n return ( pow == y ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPower ( x , y ) :\n if ( x == 1 ) :\n return ( y == 1 )\n pow = 1\n while ( pow < y ) :\n pow = pow * x\n return ( pow == y )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_SUBSEQUENCE_LEAST_K_DISTANT_ELEMENTS",
"pair": "python-java",
"Code1": "def maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n",
"Code2": "static int maxSum ( int arr [ ] , int N , int k ) {\n int MS [ ] = new int [ N ] ;\n MS [ N - 1 ] = arr [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( i + k + 1 >= N ) MS [ i ] = Math . max ( arr [ i ] , MS [ i + 1 ] ) ;\n else MS [ i ] = Math . max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] ) ;\n }\n return MS [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , N , k ) :\n MS = [ 0 for i in range ( N ) ]\n MS [ N - 1 ] = arr [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( i + k + 1 >= N ) :\n MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )\n else :\n MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )\n return MS [ 0 ]\n\n"
},
{
"id": "python-java-GROUP_OCCURRENCES_CHARACTERS_ACCORDING_FIRST_APPEARANCE",
"pair": "python-java",
"Code1": "def printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n",
"Code2": "static void printGrouped ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( count [ str . charAt ( i ) - ' a ' ] != 0 ) {\n System . out . print ( str . charAt ( i ) ) ;\n count [ str . charAt ( i ) - ' a ' ] -- ;\n }\n count [ str . charAt ( i ) - ' a ' ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printGrouped ( string ) :\n n = len ( string )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] += 1\n for i in range ( n ) :\n while count [ ord ( string [ i ] ) - ord ( \"a\" ) ] :\n print ( string [ i ] , end = \"\" )\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] -= 1\n count [ ord ( string [ i ] ) - ord ( \"a\" ) ] = 0\n\n"
},
{
"id": "python-java-COUNT_SORTED_ROWS_MATRIX",
"pair": "python-java",
"Code1": "def sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n",
"Code2": "static int sortedCount ( int mat [ ] [ ] , int r , int c ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < c - 1 ;\n j ++ ) if ( mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] ) break ;\n if ( j == c - 1 ) result ++ ;\n }\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n int j ;\n for ( j = c - 1 ;\n j > 0 ;\n j -- ) if ( mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] ) break ;\n if ( c > 1 && j == 0 ) result ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortedCount ( mat , r , c ) :\n result = 0\n for i in range ( r ) :\n j = 0\n for j in range ( c - 1 ) :\n if mat [ i ] [ j + 1 ] <= mat [ i ] [ j ] :\n break\n if j == c - 2 :\n result += 1\n for i in range ( 0 , r ) :\n j = 0\n for j in range ( c - 1 , 0 , - 1 ) :\n if mat [ i ] [ j - 1 ] <= mat [ i ] [ j ] :\n break\n if c > 1 and j == 1 :\n result += 1\n return result\n\n"
},
{
"id": "python-java-COUNT_DISTINCT_SUBSEQUENCES",
"pair": "python-java",
"Code1": "def countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n",
"Code2": "static int countSub ( String str ) {\n int [ ] last = new int [ MAX_CHAR ] ;\n Arrays . fill ( last , - 1 ) ;\n int n = str . length ( ) ;\n int [ ] dp = new int [ n + 1 ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = 2 * dp [ i - 1 ] ;\n if ( last [ ( int ) str . charAt ( i - 1 ) ] != - 1 ) dp [ i ] = dp [ i ] - dp [ last [ ( int ) str . charAt ( i - 1 ) ] ] ;\n last [ ( int ) str . charAt ( i - 1 ) ] = ( i - 1 ) ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSub ( ss ) :\n last = [ - 1 for i in range ( MAX_CHAR + 1 ) ]\n n = len ( ss )\n dp = [ - 2 for i in range ( n + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] = 2 * dp [ i - 1 ]\n if last [ ord ( ss [ i - 1 ] ) ] != - 1 :\n dp [ i ] = dp [ i ] - dp [ last [ ord ( ss [ i - 1 ] ) ] ]\n last [ ord ( ss [ i - 1 ] ) ] = i - 1\n return dp [ n ]\n\n"
},
{
"id": "python-java-LARGEST_INCREASING_SUBSEQUENCE_OF_CONSECUTIVE_INTEGERS",
"pair": "python-java",
"Code1": "def findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n",
"Code2": "static void findLIS ( int A [ ] , int n ) {\n Map < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n int LIS_size = 1 ;\n int LIS_index = 0 ;\n hash . put ( A [ 0 ] , 1 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n hash . put ( A [ i ] , hash . get ( A [ i ] - 1 ) == null ? 1 : hash . get ( A [ i ] - 1 ) + 1 ) ;\n if ( LIS_size < hash . get ( A [ i ] ) ) {\n LIS_size = hash . get ( A [ i ] ) ;\n LIS_index = A [ i ] ;\n }\n }\n System . out . println ( \"LIS_size = \" + LIS_size ) ;\n System . out . print ( \"LIS : \" ) ;\n int start = LIS_index - LIS_size + 1 ;\n while ( start <= LIS_index ) {\n System . out . print ( start + \" \" ) ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLIS ( A , n ) :\n hash = dict ( )\n LIS_size , LIS_index = 1 , 0\n hash [ A [ 0 ] ] = 1\n for i in range ( 1 , n ) :\n if A [ i ] - 1 not in hash :\n hash [ A [ i ] - 1 ] = 0\n hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1\n if LIS_size < hash [ A [ i ] ] :\n LIS_size = hash [ A [ i ] ]\n LIS_index = A [ i ]\n print ( \"LIS_size =\" , LIS_size )\n print ( \"LIS : \" , end = \"\" )\n start = LIS_index - LIS_size + 1\n while start <= LIS_index :\n print ( start , end = \" \" )\n start += 1\n\n"
},
{
"id": "python-java-FIND_THE_MAXIMUM_OF_MINIMUMS_FOR_EVERY_WINDOW_SIZE_IN_A_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n",
"Code2": "static void printMaxOfMin ( int n ) {\n for ( int k = 1 ;\n k <= n ;\n k ++ ) {\n int maxOfMin = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i <= n - k ;\n i ++ ) {\n int min = arr [ i ] ;\n for ( int j = 1 ;\n j < k ;\n j ++ ) {\n if ( arr [ i + j ] < min ) min = arr [ i + j ] ;\n }\n if ( min > maxOfMin ) maxOfMin = min ;\n }\n System . out . print ( maxOfMin + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printMaxOfMin ( arr , n ) :\n for k in range ( 1 , n + 1 ) :\n maxOfMin = INT_MIN\n for i in range ( n - k + 1 ) :\n min = arr [ i ]\n for j in range ( k ) :\n if ( arr [ i + j ] < min ) :\n min = arr [ i + j ]\n if ( min > maxOfMin ) :\n maxOfMin = min\n print ( maxOfMin , end = \" \" )\n\n"
},
{
"id": "python-java-MAXIMUM_NUMBER_OF_TRAILING_ZEROS_IN_THE_PRODUCT_OF_THE_SUBSETS_OF_SIZE_K",
"pair": "python-java",
"Code1": "def maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n",
"Code2": "static int maximumZeros ( int arr [ ] , int n , int k ) {\n int subset [ ] [ ] = new int [ k + 1 ] [ MAX5 + 5 ] ;\n for ( int [ ] row : subset ) {\n Arrays . fill ( row , - 1 ) ;\n }\n subset [ 0 ] [ 0 ] = 0 ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) {\n int pw2 = 0 , pw5 = 0 ;\n while ( arr [ p ] % 2 == 0 ) {\n pw2 ++ ;\n arr [ p ] /= 2 ;\n }\n while ( arr [ p ] % 5 == 0 ) {\n pw5 ++ ;\n arr [ p ] /= 5 ;\n }\n for ( int i = k - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < MAX5 ;\n j ++ ) {\n if ( subset [ i ] [ j ] != - 1 ) {\n subset [ i + 1 ] [ j + pw5 ] = Math . max ( subset [ i + 1 ] [ j + pw5 ] , subset [ i ] [ j ] + pw2 ) ;\n }\n }\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < MAX5 ;\n i ++ ) {\n ans = Math . max ( ans , Math . min ( i , subset [ k ] [ i ] ) ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumZeros ( arr , n , k ) :\n global MAX5\n subset = [ [ - 1 ] * ( MAX5 + 5 ) for _ in range ( k + 1 ) ]\n subset [ 0 ] [ 0 ] = 0\n for p in arr :\n pw2 , pw5 = 0 , 0\n while not p % 2 :\n pw2 += 1\n p //= 2\n while not p % 5 :\n pw5 += 1\n p //= 5\n for i in range ( k - 1 , - 1 , - 1 ) :\n for j in range ( MAX5 ) :\n if subset [ i ] [ j ] != - 1 :\n subset [ i + 1 ] [ j + pw5 ] = ( max ( subset [ i + 1 ] [ j + pw5 ] , ( subset [ i ] [ j ] + pw2 ) ) )\n ans = 0\n for i in range ( MAX5 ) :\n ans = max ( ans , min ( i , subset [ k ] [ i ] ) )\n return ans\n\n"
},
{
"id": "python-java-LARGEST_DIVISIBLE_PAIRS_SUBSET",
"pair": "python-java",
"Code1": "def largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n",
"Code2": "static int largestSubset ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int [ ] dp = new int [ n ] ;\n dp [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n int mxm = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] % a [ i ] == 0 ) {\n mxm = Math . max ( mxm , dp [ j ] ) ;\n }\n }\n dp [ i ] = 1 + mxm ;\n }\n return Arrays . stream ( dp ) . max ( ) . getAsInt ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largestSubset ( a , n ) :\n a.sort ( )\n dp = [ 0 for i in range ( n ) ]\n dp [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n mxm = 0\n for j in range ( i + 1 , n ) :\n if a [ j ] % a [ i ] == 0 :\n mxm = max ( mxm , dp [ j ] )\n dp [ i ] = 1 + mxm\n return max ( dp )\n\n"
},
{
"id": "python-java-FIND_KTH_CHARACTER_OF_DECRYPTED_STRING",
"pair": "python-java",
"Code1": "def encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n",
"Code2": "static char encodedChar ( String str , int k ) {\n String expand = \"\" ;\n String temp = \"\" ;\n int freq = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ) {\n temp = \"\" ;\n freq = 0 ;\n while ( i < str . length ( ) && str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n temp += str . charAt ( i ) ;\n i ++ ;\n }\n while ( i < str . length ( ) && str . charAt ( i ) >= ' 1 ' && str . charAt ( i ) <= ' 9 ' ) {\n freq = freq * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n for ( int j = 1 ;\n j <= freq ;\n j ++ ) expand += temp ;\n }\n if ( freq == 0 ) expand += temp ;\n return expand . charAt ( k - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef encodedChar ( str , k ) :\n expand = \"\"\n freq = 0\n i = 0\n while ( i < len ( str ) ) :\n temp = \"\"\n freq = 0\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( 'a' ) and ord ( str [ i ] ) <= ord ( 'z' ) ) :\n temp += str [ i ]\n i += 1\n while ( i < len ( str ) and ord ( str [ i ] ) >= ord ( '1' ) and ord ( str [ i ] ) <= ord ( '9' ) ) :\n freq = freq * 10 + ord ( str [ i ] ) - ord ( '0' )\n i += 1\n for j in range ( 1 , freq + 1 , 1 ) :\n expand += temp\n if ( freq == 0 ) :\n expand += temp\n return expand [ k - 1 ]\n\n"
},
{
"id": "python-java-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY_1",
"pair": "python-java",
"Code1": "def countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n",
"Code2": "static int countNum ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr [ i ] ) ;\n if ( arr [ i ] < minm ) minm = arr [ i ] ;\n if ( arr [ i ] > maxm ) maxm = arr [ i ] ;\n }\n for ( int i = minm ;\n i <= maxm ;\n i ++ ) if ( ! s . contains ( i ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNum ( arr , n ) :\n s = dict ( )\n count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n if ( arr [ i ] < minm ) :\n minm = arr [ i ]\n if ( arr [ i ] > maxm ) :\n maxm = arr [ i ]\n for i in range ( minm , maxm + 1 ) :\n if i not in s.keys ( ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY_1",
"pair": "python-java",
"Code1": "def countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n",
"Code2": "public static int countPairs ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n else hm . put ( arr [ i ] , 1 ) ;\n }\n int ans = 0 ;\n for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) {\n int count = it . getValue ( ) ;\n ans += ( count * ( count - 1 ) ) / 2 ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if arr [ i ] in mp.keys ( ) :\n mp [ arr [ i ] ] += 1\n else :\n mp [ arr [ i ] ] = 1\n ans = 0\n for it in mp :\n count = mp [ it ]\n ans += ( count * ( count - 1 ) ) // 2\n return ans\n\n"
},
{
"id": "python-java-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY_1",
"pair": "python-java",
"Code1": "def maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n",
"Code2": "static int maxDiff ( int [ ] arr , int n ) {\n int result = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] != arr [ i + 1 ] ) result += Math . abs ( arr [ i ] ) ;\n else i ++ ;\n }\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += Math . abs ( arr [ n - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDiff ( arr , n ) :\n result = 0\n arr.sort ( )\n for i in range ( n - 1 ) :\n if ( abs ( arr [ i ] ) != abs ( arr [ i + 1 ] ) ) :\n result += abs ( arr [ i ] )\n else :\n pass\n if ( arr [ n - 2 ] != arr [ n - 1 ] ) :\n result += abs ( arr [ n - 1 ] )\n return result\n\n"
},
{
"id": "python-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS",
"pair": "python-java",
"Code1": "def middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n if ( ( a < b && b < c ) || ( c < b && b < a ) ) return b ;\n else if ( ( b < a && a < c ) || ( c < a && a < b ) ) return a ;\n else return c ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n if ( ( a < b and b < c ) or ( c < b and b < a ) ) :\n return b\n if ( ( b < a and a < c ) or ( c < a and a < b ) ) :\n return a\n else :\n return c\n\n"
},
{
"id": "python-java-COUNT_ARRAYS_CONSECUTIVE_ELEMENT_DIFFERENT_VALUES",
"pair": "python-java",
"Code1": "def countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n",
"Code2": "public static int countarray ( int n , int k , int x ) {\n int [ ] dp = new int [ 109 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ;\n return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countarray ( n , k , x ) :\n dp = list ( )\n dp.append ( 0 )\n dp.append ( 1 )\n i = 2\n while i < n :\n dp.append ( ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] )\n i = i + 1\n return ( ( k - 1 ) * dp [ n - 2 ] if x == 1 else dp [ n - 1 ] )\n\n"
},
{
"id": "python-java-NEWMAN_SHANKS_WILLIAMS_PRIME",
"pair": "python-java",
"Code1": "def nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n",
"Code2": "static int nswp ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nswp ( n ) :\n if n == 0 or n == 1 :\n return 1\n return 2 * nswp ( n - 1 ) + nswp ( n - 2 )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_1",
"pair": "python-java",
"Code1": "def fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n",
"Code2": "int fib ( int n ) {\n if ( lookup [ n ] == NIL ) {\n if ( n <= 1 ) lookup [ n ] = n ;\n else lookup [ n ] = fib ( n - 1 ) + fib ( n - 2 ) ;\n }\n return lookup [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n , lookup ) :\n if n == 0 or n == 1 :\n lookup [ n ] = n\n if lookup [ n ] is None :\n lookup [ n ] = fib ( n - 1 , lookup ) + fib ( n - 2 , lookup )\n return lookup [ n ]\n\n"
},
{
"id": "python-java-COUNT_NUMBERS_CAN_CONSTRUCTED_USING_TWO_NUMBERS",
"pair": "python-java",
"Code1": "def countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n",
"Code2": "static int countNums ( int n , int x , int y ) {\n boolean [ ] arr = new boolean [ n + 1 ] ;\n if ( x <= n ) arr [ x ] = true ;\n if ( y <= n ) arr [ y ] = true ;\n int result = 0 ;\n for ( int i = Math . min ( x , y ) ;\n i <= n ;\n i ++ ) {\n if ( arr [ i ] ) {\n if ( i + x <= n ) arr [ i + x ] = true ;\n if ( i + y <= n ) arr [ i + y ] = true ;\n result ++ ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNums ( n , x , y ) :\n arr = [ False for i in range ( n + 2 ) ]\n if ( x <= n ) :\n arr [ x ] = True\n if ( y <= n ) :\n arr [ y ] = True\n result = 0\n for i in range ( min ( x , y ) , n + 1 ) :\n if ( arr [ i ] ) :\n if ( i + x <= n ) :\n arr [ i + x ] = True\n if ( i + y <= n ) :\n arr [ i + y ] = True\n result = result + 1\n return result\n\n"
},
{
"id": "python-java-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING",
"pair": "python-java",
"Code1": "def countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n",
"Code2": "static int countPS ( String str ) {\n int N = str . length ( ) ;\n int [ ] [ ] cps = new int [ N + 1 ] [ N + 1 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) cps [ i ] [ i ] = 1 ;\n for ( int L = 2 ;\n L <= N ;\n L ++ ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int k = L + i - 1 ;\n if ( k < N ) {\n if ( str . charAt ( i ) == str . charAt ( k ) ) cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 ;\n else cps [ i ] [ k ] = cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] ;\n }\n }\n }\n return cps [ 0 ] [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPS ( str ) :\n N = len ( str )\n cps = [ [ 0 for i in range ( N + 2 ) ] for j in range ( N + 2 ) ]\n for i in range ( N ) :\n cps [ i ] [ i ] = 1\n for L in range ( 2 , N + 1 ) :\n for i in range ( N ) :\n k = L + i - 1\n if ( k < N ) :\n if ( str [ i ] == str [ k ] ) :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] + 1 )\n else :\n cps [ i ] [ k ] = ( cps [ i ] [ k - 1 ] + cps [ i + 1 ] [ k ] - cps [ i + 1 ] [ k - 1 ] )\n return cps [ 0 ] [ N - 1 ]\n\n"
},
{
"id": "python-java-CONVERT_DECIMAL_FRACTION_BINARY_NUMBER",
"pair": "python-java",
"Code1": "def decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n",
"Code2": "static String decimalToBinary ( double num , int k_prec ) {\n String binary = \"\" ;\n int Integral = ( int ) num ;\n double fractional = num - Integral ;\n while ( Integral > 0 ) {\n int rem = Integral % 2 ;\n binary += ( ( char ) ( rem + ' 0 ' ) ) ;\n Integral /= 2 ;\n }\n binary = reverse ( binary ) ;\n binary += ( ' . ' ) ;\n while ( k_prec -- > 0 ) {\n fractional *= 2 ;\n int fract_bit = ( int ) fractional ;\n if ( fract_bit == 1 ) {\n fractional -= fract_bit ;\n binary += ( char ) ( 1 + ' 0 ' ) ;\n }\n else {\n binary += ( char ) ( 0 + ' 0 ' ) ;\n }\n }\n return binary ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decimalToBinary ( num , k_prec ) :\n binary = \"\"\n Integral = int ( num )\n fractional = num - Integral\n while ( Integral ) :\n rem = Integral % 2\n binary += str ( rem )\n Integral //= 2\n binary = binary [ : : - 1 ]\n binary += '.'\n while ( k_prec ) :\n fractional *= 2\n fract_bit = int ( fractional )\n if ( fract_bit == 1 ) :\n fractional -= fract_bit\n binary += '1'\n else :\n binary += '0'\n k_prec -= 1\n return binary\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_37_BOOLEAN_PARENTHESIZATION_PROBLEM",
"pair": "python-java",
"Code1": "def countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '",
"Code2": "static int countParenth ( char symb [ ] , char oper [ ] , int n ) {\n int F [ ] [ ] = new int [ n ] [ n ] ;\n int T [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n F [ i ] [ i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ;\n T [ i ] [ i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ;\n }\n for ( int gap = 1 ;\n gap < n ;\n ++ gap ) {\n for ( int i = 0 , j = gap ;\n j < n ;\n ++ i , ++ j ) {\n T [ i ] [ j ] = F [ i ] [ j ] = 0 ;\n for ( int g = 0 ;\n g < gap ;\n g ++ ) {\n int k = i + g ;\n int tik = T [ i ] [ k ] + F [ i ] [ k ] ;\n int tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ] ;\n if ( oper [ k ] == ' & ' ) {\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ] ;\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] ) ;\n }\n if ( oper [ k ] == '",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countParenth ( symb , oper , n ) :\n F = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n ) :\n if symb [ i ] == 'F' :\n F [ i ] [ i ] = 1\n else :\n F [ i ] [ i ] = 0\n if symb [ i ] == 'T' :\n T [ i ] [ i ] = 1\n else :\n T [ i ] [ i ] = 0\n for gap in range ( 1 , n ) :\n i = 0\n for j in range ( gap , n ) :\n T [ i ] [ j ] = F [ i ] [ j ] = 0\n for g in range ( gap ) :\n k = i + g\n tik = T [ i ] [ k ] + F [ i ] [ k ]\n tkj = T [ k + 1 ] [ j ] + F [ k + 1 ] [ j ]\n if oper [ k ] == '&' :\n T [ i ] [ j ] += T [ i ] [ k ] * T [ k + 1 ] [ j ]\n F [ i ] [ j ] += ( tik * tkj - T [ i ] [ k ] * T [ k + 1 ] [ j ] )\n if oper [ k ] == '\n"
},
{
"id": "python-java-COUNT_SET_BITS_IN_AN_INTEGER_1",
"pair": "python-java",
"Code1": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n",
"Code2": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return ( n & 1 ) + countSetBits ( n >> 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return ( n & 1 ) + countSetBits ( n >> 1 )\n\n"
},
{
"id": "python-java-LONGEST_SPAN_SUM_TWO_BINARY_ARRAYS",
"pair": "python-java",
"Code1": "def longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n",
"Code2": "static int longestCommonSum ( int n ) {\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum1 += arr1 [ j ] ;\n sum2 += arr2 [ j ] ;\n if ( sum1 == sum2 ) {\n int len = j - i + 1 ;\n if ( len > maxLen ) maxLen = len ;\n }\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestCommonSum ( arr1 , arr2 , n ) :\n maxLen = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( i , n ) :\n sum1 += arr1 [ j ]\n sum2 += arr2 [ j ]\n if ( sum1 == sum2 ) :\n len = j - i + 1\n if ( len > maxLen ) :\n maxLen = len\n return maxLen\n\n"
},
{
"id": "python-java-MAXIMUM_TRIPLET_SUM_ARRAY",
"pair": "python-java",
"Code1": "def maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n",
"Code2": "static int maxTripletSum ( int arr [ ] , int n ) {\n int sum = - 1000000 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxTripletSum ( arr , n ) :\n sm = - 1000000\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( j + 1 , n ) :\n if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :\n sm = arr [ i ] + arr [ j ] + arr [ k ]\n return sm\n\n"
},
{
"id": "python-java-EVALUATE_A_BOOLEAN_EXPRESSION_REPRESENTED_AS_STRING",
"pair": "python-java",
"Code1": "def evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n",
"Code2": "static int evaluateBoolExpr ( StringBuffer s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i + 1 < n && i + 2 < n ) {\n if ( s . charAt ( i + 1 ) == ' A ' ) {\n if ( s . charAt ( i + 2 ) == ' 0 ' || s . charAt ( i ) == 0 ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n else if ( ( i + 1 ) < n && s . charAt ( i + 1 ) == ' B ' ) {\n if ( s . charAt ( i + 2 ) == ' 1 ' || s . charAt ( i ) == ' 1 ' ) s . setCharAt ( i + 2 , ' 1 ' ) ;\n else s . setCharAt ( i + 2 , ' 0 ' ) ;\n }\n else {\n if ( s . charAt ( i + 2 ) == s . charAt ( i ) ) s . setCharAt ( i + 2 , ' 0 ' ) ;\n else s . setCharAt ( i + 2 , ' 1 ' ) ;\n }\n }\n }\n return s . charAt ( n - 1 ) - ' 0 ' ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evaluateBoolExpr ( s ) :\n n = len ( s )\n for i in range ( 0 , n - 2 , 2 ) :\n if ( s [ i + 1 ] == \"A\" ) :\n if ( s [ i + 2 ] == \"0\" or s [ i ] == \"0\" ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n elif ( s [ i + 1 ] == \"B\" ) :\n if ( s [ i + 2 ] == \"1\" or s [ i ] == \"1\" ) :\n s [ i + 2 ] = \"1\"\n else :\n s [ i + 2 ] = \"0\"\n else :\n if ( s [ i + 2 ] == s [ i ] ) :\n s [ i + 2 ] = \"0\"\n else :\n s [ i + 2 ] = \"1\"\n return ord ( s [ n - 1 ] ) - ord ( \"0\" )\n\n"
},
{
"id": "python-java-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN_2",
"pair": "python-java",
"Code1": "def findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n",
"Code2": "public static int findNth ( int n ) {\n int nthElement = 19 + ( n - 1 ) * 9 ;\n int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ;\n nthElement += 9 * outliersCount ;\n return nthElement ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findNth ( n ) :\n nthElement = 19 + ( n - 1 ) * 9\n outliersCount = int ( math.log10 ( nthElement ) ) - 1\n nthElement += 9 * outliersCount\n return nthElement\n\n"
},
{
"id": "python-java-COUNT_ARITHMETIC_PROGRESSION_SUBSEQUENCES_ARRAY",
"pair": "python-java",
"Code1": "def numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n",
"Code2": "static int numofAP ( int a [ ] , int n ) {\n int minarr = + 2147483647 ;\n int maxarr = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n minarr = Math . min ( minarr , a [ i ] ) ;\n maxarr = Math . max ( maxarr , a [ i ] ) ;\n }\n int dp [ ] = new int [ n ] ;\n int sum [ ] = new int [ MAX ] ;\n int ans = n + 1 ;\n for ( int d = ( minarr - maxarr ) ;\n d <= ( maxarr - minarr ) ;\n d ++ ) {\n Arrays . fill ( sum , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = 1 ;\n if ( a [ i ] - d >= 1 && a [ i ] - d <= 1000000 ) dp [ i ] += sum [ a [ i ] - d ] ;\n ans += dp [ i ] - 1 ;\n sum [ a [ i ] ] += dp [ i ] ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numofAP ( a , n ) :\n minarr = + 2147483647\n maxarr = - 2147483648\n for i in range ( n ) :\n minarr = min ( minarr , a [ i ] )\n maxarr = max ( maxarr , a [ i ] )\n dp = [ 0 for i in range ( n + 1 ) ]\n ans = n + 1\n for d in range ( ( minarr - maxarr ) , ( maxarr - minarr ) + 1 ) :\n sum = [ 0 for i in range ( MAX + 1 ) ]\n for i in range ( n ) :\n dp [ i ] = 1\n if ( a [ i ] - d >= 1 and a [ i ] - d <= 1000000 ) :\n dp [ i ] += sum [ a [ i ] - d ]\n ans += dp [ i ] - 1\n sum [ a [ i ] ] += dp [ i ]\n return ans\n\n"
},
{
"id": "python-java-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES",
"pair": "python-java",
"Code1": "def countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n",
"Code2": "static int countSol ( int coeff [ ] , int start , int end , int rhs ) {\n if ( rhs == 0 ) return 1 ;\n int result = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) if ( coeff [ i ] <= rhs ) result += countSol ( coeff , i , end , rhs - coeff [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSol ( coeff , start , end , rhs ) :\n if ( rhs == 0 ) :\n return 1\n result = 0\n for i in range ( start , end + 1 ) :\n if ( coeff [ i ] <= rhs ) :\n result += countSol ( coeff , i , end , rhs - coeff [ i ] )\n return result\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_SWAPS_REQUIRED_SORT_ARRAY",
"pair": "python-java",
"Code1": "def minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n",
"Code2": "public static int minSwaps ( int [ ] arr ) {\n int n = arr . length ;\n ArrayList < Pair < Integer , Integer >> arrpos = new ArrayList < Pair < Integer , Integer >> ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arrpos . add ( new Pair < Integer , Integer > ( arr [ i ] , i ) ) ;\n arrpos . sort ( new Comparator < Pair < Integer , Integer >> ( ) {\n @ Override public int compare ( Pair < Integer , Integer > o1 , Pair < Integer , Integer > o2 ) {\n if ( o1 . getKey ( ) > o2 . getKey ( ) ) return - 1 ;\n else if ( o1 . getKey ( ) . equals ( o2 . getKey ( ) ) ) return 0 ;\n else return 1 ;\n }\n }\n ) ;\n Boolean [ ] vis = new Boolean [ n ] ;\n Arrays . fill ( vis , false ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( vis [ i ] || arrpos . get ( i ) . getValue ( ) == i ) continue ;\n int cycle_size = 0 ;\n int j = i ;\n while ( ! vis [ j ] ) {\n vis [ j ] = true ;\n j = arrpos . get ( j ) . getValue ( ) ;\n cycle_size ++ ;\n }\n if ( cycle_size > 0 ) {\n ans += ( cycle_size - 1 ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSwaps ( arr ) :\n n = len ( arr )\n arrpos = [ * enumerate ( arr ) ]\n arrpos.sort ( key = lambda it : it [ 1 ] )\n vis = { k : False for k in range ( n ) }\n ans = 0\n for i in range ( n ) :\n if vis [ i ] or arrpos [ i ] [ 0 ] == i :\n continue\n cycle_size = 0\n j = i\n while not vis [ j ] :\n vis [ j ] = True\n j = arrpos [ j ] [ 0 ]\n cycle_size += 1\n if cycle_size > 0 :\n ans += ( cycle_size - 1 )\n return ans\n\n"
},
{
"id": "python-java-CIRCULAR_MATRIX_CONSTRUCT_A_MATRIX_WITH_NUMBERS_1_TO_MN_IN_SPIRAL_WAY",
"pair": "python-java",
"Code1": "def spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n",
"Code2": "static void spiralFill ( int m , int n , int a [ ] [ ] ) {\n int val = 1 ;\n int k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( int i = l ;\n i < n ;\n ++ i ) {\n a [ k ] [ i ] = val ++ ;\n }\n k ++ ;\n for ( int i = k ;\n i < m ;\n ++ i ) {\n a [ i ] [ n - 1 ] = val ++ ;\n }\n n -- ;\n if ( k < m ) {\n for ( int i = n - 1 ;\n i >= l ;\n -- i ) {\n a [ m - 1 ] [ i ] = val ++ ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( int i = m - 1 ;\n i >= k ;\n -- i ) {\n a [ i ] [ l ] = val ++ ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef spiralFill ( m , n , a ) :\n val = 1\n k , l = 0 , 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n a [ k ] [ i ] = val\n val += 1\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = val\n val += 1\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = val\n val += 1\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = val\n val += 1\n l += 1\n\n"
},
{
"id": "python-java-GIVEN_TWO_SORTED_ARRAYS_NUMBER_X_FIND_PAIR_WHOSE_SUM_CLOSEST_X",
"pair": "python-java",
"Code1": "def printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n",
"Code2": "void printClosest ( int ar1 [ ] , int ar2 [ ] , int m , int n , int x ) {\n int diff = Integer . MAX_VALUE ;\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 ;\n while ( l < m && r >= 0 ) {\n if ( Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( ar1 [ l ] + ar2 [ r ] - x ) ;\n }\n if ( ar1 [ l ] + ar2 [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . print ( \"The closest pair is [\" + ar1 [ res_l ] + \", \" + ar2 [ res_r ] + \"]\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printClosest ( ar1 , ar2 , m , n , x ) :\n diff = sys.maxsize\n l = 0\n r = n - 1\n while ( l < m and r >= 0 ) :\n if abs ( ar1 [ l ] + ar2 [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( ar1 [ l ] + ar2 [ r ] - x )\n if ar1 [ l ] + ar2 [ r ] > x :\n r = r - 1\n else :\n l = l + 1\n print ( \"The closest pair is [\" , ar1 [ res_l ] , \",\" , ar2 [ res_r ] , \"]\" )\n\n"
},
{
"id": "python-java-NUMBER_VISIBLE_BOXES_PUTTING_ONE_INSIDE_ANOTHER",
"pair": "python-java",
"Code1": "def minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n",
"Code2": "static int minimumBox ( int [ ] arr , int n ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n Arrays . sort ( arr ) ;\n q . add ( arr [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int now = q . element ( ) ;\n if ( arr [ i ] >= 2 * now ) q . remove ( ) ;\n q . add ( arr [ i ] ) ;\n }\n return q . size ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimumBox ( arr , n ) :\n q = collections.deque ( [ ] )\n arr.sort ( )\n q.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n now = q [ 0 ]\n if ( arr [ i ] >= 2 * now ) :\n q.popleft ( )\n q.append ( arr [ i ] )\n return len ( q )\n\n"
},
{
"id": "python-java-INTEGER_POSITIVE_VALUE_POSITIVE_NEGATIVE_VALUE_ARRAY",
"pair": "python-java",
"Code1": "def findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n",
"Code2": "static int findInteger ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n int maximum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] < 0 ) hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) - 1 ) ;\n else hash . put ( Math . abs ( arr [ i ] ) , ( hash . get ( Math . abs ( arr [ i ] ) ) == null ? 0 : hash . get ( Math . abs ( arr [ i ] ) ) ) + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . get ( arr [ i ] ) > 0 ) return arr [ i ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findInteger ( arr , n ) :\n hash = dict ( )\n maximum = 0\n for i in arr :\n if ( i < 0 ) :\n if abs ( i ) not in hash.keys ( ) :\n hash [ abs ( i ) ] = - 1\n else :\n hash [ abs ( i ) ] -= 1\n else :\n hash [ i ] = hash.get ( i , 0 ) + 1\n for i in arr :\n if i in hash.keys ( ) and hash [ i ] > 0 :\n return i\n return - 1\n\n"
},
{
"id": "python-java-CONVERT_ALTERNATE_CHARACTERS_STRING_UPPER_CASE",
"pair": "python-java",
"Code1": "def convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n",
"Code2": "static void convertOpposite ( StringBuffer str ) {\n int ln = str . length ( ) ;\n for ( int i = 0 ;\n i < ln ;\n i ++ ) {\n Character c = str . charAt ( i ) ;\n if ( Character . isLowerCase ( c ) ) str . replace ( i , i + 1 , Character . toUpperCase ( c ) + \"\" ) ;\n else str . replace ( i , i + 1 , Character . toLowerCase ( c ) + \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef convertOpposite ( str ) :\n ln = len ( str )\n for i in range ( ln ) :\n if str [ i ] >= 'a' and str [ i ] <= 'z' :\n str [ i ] = chr ( ord ( str [ i ] ) - 32 )\n elif str [ i ] >= 'A' and str [ i ] <= 'Z' :\n str [ i ] = chr ( ord ( str [ i ] ) + 32 )\n\n"
},
{
"id": "python-java-PROGRAM_DECIMAL_BINARY_CONVERSION_2",
"pair": "python-java",
"Code1": "def decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n",
"Code2": "static int decimalToBinary ( int N ) {\n int B_Number = 0 ;\n int cnt = 0 ;\n while ( N != 0 ) {\n int rem = N % 2 ;\n double c = Math . pow ( 10 , cnt ) ;\n B_Number += rem * c ;\n N /= 2 ;\n cnt ++ ;\n }\n return B_Number ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decimalToBinary ( N ) :\n B_Number = 0\n cnt = 0\n while ( N != 0 ) :\n rem = N % 2\n c = pow ( 10 , cnt )\n B_Number += rem * c\n N //= 2\n cnt += 1\n return B_Number\n\n"
},
{
"id": "python-java-FIND_REPETITIVE_ELEMENT_1_N_1_1",
"pair": "python-java",
"Code1": "def findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n",
"Code2": "static int findRepeating ( int arr [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . contains ( arr [ i ] ) ) return arr [ i ] ;\n s . add ( arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n if arr [ i ] in s :\n return arr [ i ]\n s.add ( arr [ i ] )\n rteurn - 1\n\n"
},
{
"id": "python-java-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX_2",
"pair": "python-java",
"Code1": "def transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n",
"Code2": "static void transpose ( int A [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n int temp = A [ i ] [ j ] ;\n A [ i ] [ j ] = A [ j ] [ i ] ;\n A [ j ] [ i ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef transpose ( A ) :\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n A [ i ] [ j ] , A [ j ] [ i ] = A [ j ] [ i ] , A [ i ] [ j ]\n\n"
},
{
"id": "python-java-PRINT_POSSIBLE_SUMS_CONSECUTIVE_NUMBERS_SUM_N",
"pair": "python-java",
"Code1": "def findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n",
"Code2": "static void findConsecutive ( int N ) {\n int start = 1 ;\n int end = ( N + 1 ) / 2 ;\n while ( start < end ) {\n int sum = 0 ;\n for ( int i = start ;\n i <= end ;\n i ++ ) {\n sum = sum + i ;\n if ( sum == N ) {\n for ( int j = start ;\n j <= i ;\n j ++ ) System . out . print ( j + \" \" ) ;\n System . out . println ( ) ;\n break ;\n }\n if ( sum > N ) break ;\n }\n sum = 0 ;\n start ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findConsecutive ( N ) :\n start = 1\n end = ( N + 1 ) // 2\n while ( start < end ) :\n Sum = 0\n for i in range ( start , end + 1 ) :\n Sum = Sum + i\n if ( Sum == N ) :\n for j in range ( start , i + 1 ) :\n print ( j , end = \" \" )\n print ( )\n break\n if ( Sum > N ) :\n break\n Sum = 0\n start += 1\n\n"
},
{
"id": "python-java-PRINT_POSSIBLE_STRINGS_CAN_MADE_PLACING_SPACES_2",
"pair": "python-java",
"Code1": "def printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "static void printSubsequences ( String s ) {\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n int opsize = ( int ) ( Math . pow ( 2 , n - 1 ) ) ;\n for ( int counter = 0 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( str [ j ] ) ;\n if ( ( counter & ( 1 << j ) ) > 0 ) System . out . print ( \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSubsequences ( str ) :\n n = len ( str )\n opsize = int ( pow ( 2 , n - 1 ) )\n for counter in range ( opsize ) :\n for j in range ( n ) :\n print ( str [ j ] , end = \"\" )\n if ( counter & ( 1 << j ) ) :\n print ( \"\" , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-java-MAXIMUM_AREA_QUADRILATERAL",
"pair": "python-java",
"Code1": "def maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n",
"Code2": "static double maxArea ( double a , double b , double c , double d ) {\n double semiperimeter = ( a + b + c + d ) / 2 ;\n return Math . sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxArea ( a , b , c , d ) :\n semiperimeter = ( a + b + c + d ) / 2\n return math.sqrt ( ( semiperimeter - a ) * ( semiperimeter - b ) * ( semiperimeter - c ) * ( semiperimeter - d ) )\n\n"
},
{
"id": "python-java-POSITION_OF_RIGHTMOST_SET_BIT_2",
"pair": "python-java",
"Code1": "def Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n",
"Code2": "static int Right_most_setbit ( int num ) {\n int pos = 1 ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ;\n else break ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef Right_most_setbit ( num ) :\n pos = 1\n for i in range ( INT_SIZE ) :\n if not ( num & ( 1 << i ) ) :\n pos += 1\n else :\n break\n return pos\n\n"
},
{
"id": "python-java-CONVERTING_DECIMAL_NUMBER_LYING_BETWEEN_1_TO_3999_TO_ROMAN_NUMERALS",
"pair": "python-java",
"Code1": "def printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n",
"Code2": "static void printRoman ( int number ) {\n char c [ ] = new char [ 10001 ] ;\n int i = 0 ;\n if ( number <= 0 ) {\n System . out . printf ( \"Invalid number\" ) ;\n return ;\n }\n while ( number != 0 ) {\n if ( number >= 1000 ) {\n i = digit ( ' M ' , number / 1000 , i , c ) ;\n number = number % 1000 ;\n }\n else if ( number >= 500 ) {\n if ( number < 900 ) {\n i = digit ( ' D ' , number / 500 , i , c ) ;\n number = number % 500 ;\n }\n else {\n i = sub_digit ( ' C ' , ' M ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 100 ) {\n if ( number < 400 ) {\n i = digit ( ' C ' , number / 100 , i , c ) ;\n number = number % 100 ;\n }\n else {\n i = sub_digit ( ' C ' , ' D ' , i , c ) ;\n number = number % 100 ;\n }\n }\n else if ( number >= 50 ) {\n if ( number < 90 ) {\n i = digit ( ' L ' , number / 50 , i , c ) ;\n number = number % 50 ;\n }\n else {\n i = sub_digit ( ' X ' , ' C ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 10 ) {\n if ( number < 40 ) {\n i = digit ( ' X ' , number / 10 , i , c ) ;\n number = number % 10 ;\n }\n else {\n i = sub_digit ( ' X ' , ' L ' , i , c ) ;\n number = number % 10 ;\n }\n }\n else if ( number >= 5 ) {\n if ( number < 9 ) {\n i = digit ( ' V ' , number / 5 , i , c ) ;\n number = number % 5 ;\n }\n else {\n i = sub_digit ( ' I ' , ' X ' , i , c ) ;\n number = 0 ;\n }\n }\n else if ( number >= 1 ) {\n if ( number < 4 ) {\n i = digit ( ' I ' , number , i , c ) ;\n number = 0 ;\n }\n else {\n i = sub_digit ( ' I ' , ' V ' , i , c ) ;\n number = 0 ;\n }\n }\n }\n System . out . printf ( \"Roman numeral is: \" ) ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n System . out . printf ( \"%c\" , c [ j ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRoman ( number ) :\n num = [ 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 ]\n sym = [ \"I\" , \"IV\" , \"V\" , \"IX\" , \"X\" , \"XL\" , \"L\" , \"XC\" , \"C\" , \"CD\" , \"D\" , \"CM\" , \"M\" ]\n i = 12\n while number :\n div = number // num [ i ]\n number %= num [ i ]\n while div :\n print ( sym [ i ] , end = \"\" )\n div -= 1\n i -= 1\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM",
"pair": "python-java",
"Code1": "def isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n",
"Code2": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n if ( sum == 0 ) return true ;\n if ( n == 0 && sum != 0 ) return false ;\n if ( set [ n - 1 ] > sum ) return isSubsetSum ( set , n - 1 , sum ) ;\n return isSubsetSum ( set , n - 1 , sum ) || isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( set , n , sum ) :\n if ( sum == 0 ) :\n return True\n if ( n == 0 and sum != 0 ) :\n return False\n if ( set [ n - 1 ] > sum ) :\n return isSubsetSum ( set , n - 1 , sum )\n return isSubsetSum ( set , n - 1 , sum ) or isSubsetSum ( set , n - 1 , sum - set [ n - 1 ] )\n\n"
},
{
"id": "python-java-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS_1",
"pair": "python-java",
"Code1": "def countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n",
"Code2": "public static int countDigits ( int a , int b ) {\n if ( a == 0 || b == 0 ) return 1 ;\n return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDigits ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return 1\n return math.floor ( math.log10 ( abs ( a ) ) + math.log10 ( abs ( b ) ) ) + 1\n\n"
},
{
"id": "python-java-WAYS_TO_WRITE_N_AS_SUM_OF_TWO_OR_MORE_POSITIVE_INTEGERS",
"pair": "python-java",
"Code1": "def CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n",
"Code2": "static int countWays ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) table [ j ] += table [ j - i ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountWays ( n ) :\n table = [ 0 ] * ( n + 1 )\n table [ 0 ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i , n + 1 ) :\n table [ j ] += table [ j - i ]\n return table [ n ]\n\n"
},
{
"id": "python-java-SORT_EVEN_NUMBERS_ASCENDING_ORDER_SORT_ODD_NUMBERS_DESCENDING_ORDER_1",
"pair": "python-java",
"Code1": "def twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n",
"Code2": "static void twoWaySort ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef twoWaySort ( arr , n ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n arr.sort ( )\n for i in range ( 0 , n ) :\n if ( arr [ i ] & 1 ) :\n arr [ i ] *= - 1\n\n"
},
{
"id": "python-java-FINDING_POWER_PRIME_NUMBER_P_N_1",
"pair": "python-java",
"Code1": "def PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n",
"Code2": "static int PowerOFPINnfactorial ( int n , int p ) {\n int ans = 0 ;\n int temp = p ;\n while ( temp <= n ) {\n ans += n / temp ;\n temp = temp * p ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef PowerOFPINnfactorial ( n , p ) :\n ans = 0\n temp = p\n while ( temp <= n ) :\n ans += n / temp\n temp = temp * p\n return int ( ans )\n\n"
},
{
"id": "python-java-FIND_A_SPECIFIC_PAIR_IN_MATRIX",
"pair": "python-java",
"Code1": "def findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n",
"Code2": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n for ( int a = 0 ;\n a < N - 1 ;\n a ++ ) for ( int b = 0 ;\n b < N - 1 ;\n b ++ ) for ( int d = a + 1 ;\n d < N ;\n d ++ ) for ( int e = b + 1 ;\n e < N ;\n e ++ ) if ( maxValue < ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ) maxValue = mat [ d ] [ e ] - mat [ a ] [ b ] ;\n return maxValue ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxValue ( mat ) :\n maxValue = 0\n for a in range ( N - 1 ) :\n for b in range ( N - 1 ) :\n for d in range ( a + 1 , N ) :\n for e in range ( b + 1 , N ) :\n if maxValue < int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) :\n maxValue = int ( mat [ d ] [ e ] - mat [ a ] [ b ] ) ;\n return maxValue ;\n\n"
},
{
"id": "python-java-FIND_THREE_ELEMENT_FROM_DIFFERENT_THREE_ARRAYS_SUCH_THAT_THAT_A_B_C_K_1",
"pair": "python-java",
"Code1": "def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n",
"Code2": "static boolean findTriplet ( int a1 [ ] , int a2 [ ] , int a3 [ ] , int n1 , int n2 , int n3 , int sum ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n s . add ( a1 [ i ] ) ;\n }\n ArrayList < Integer > al = new ArrayList < > ( s ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n3 ;\n j ++ ) {\n if ( al . contains ( sum - a2 [ i ] - a3 [ j ] ) & al . indexOf ( sum - a2 [ i ] - a3 [ j ] ) != al . get ( al . size ( ) - 1 ) ) {\n return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :\n s = set ( )\n for i in range ( n1 ) :\n s.add ( a1 [ i ] )\n for i in range ( n2 ) :\n for j in range ( n3 ) :\n if sum - a2 [ i ] - a3 [ j ] in s :\n return True\n return False\n\n"
},
{
"id": "python-java-FIND_THE_NUMBER_OCCURRING_ODD_NUMBER_OF_TIMES",
"pair": "python-java",
"Code1": "def getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n",
"Code2": "static int getOddOccurrence ( int arr [ ] , int arr_size ) {\n int i ;\n for ( i = 0 ;\n i < arr_size ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < arr_size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) count ++ ;\n }\n if ( count % 2 != 0 ) return arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getOddOccurrence ( arr , arr_size ) :\n for i in range ( 0 , arr_size ) :\n count = 0\n for j in range ( 0 , arr_size ) :\n if arr [ i ] == arr [ j ] :\n count += 1\n if ( count % 2 != 0 ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-java-PRIME_FACTORS_BIG_NUMBER",
"pair": "python-java",
"Code1": "def factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n",
"Code2": "static void factorize ( long n ) {\n int count = 0 ;\n while ( ! ( n % 2 > 0 ) ) {\n n >>= 1 ;\n count ++ ;\n }\n if ( count > 0 ) {\n System . out . println ( \"2\" + \" \" + count ) ;\n }\n for ( long i = 3 ;\n i <= ( long ) Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n }\n if ( count > 0 ) {\n System . out . println ( i + \" \" + count ) ;\n }\n }\n if ( n > 2 ) {\n System . out . println ( n + \" \" + \"1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef factorize ( n ) :\n count = 0\n while ( ( n % 2 > 0 ) == False ) :\n n >>= 1\n count += 1\n if ( count > 0 ) :\n print ( 2 , count )\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n while ( n % i == 0 ) :\n count += 1\n n = int ( n / i )\n if ( count > 0 ) :\n print ( i , count )\n i += 2\n if ( n > 2 ) :\n print ( n , 1 )\n\n"
},
{
"id": "python-java-SMALLEST_DIFFERENCE_PAIR_VALUES_TWO_UNSORTED_ARRAYS",
"pair": "python-java",
"Code1": "def findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n",
"Code2": "static int findSmallestDifference ( int A [ ] , int B [ ] , int m , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int a = 0 , b = 0 ;\n int result = Integer . MAX_VALUE ;\n while ( a < m && b < n ) {\n if ( Math . abs ( A [ a ] - B [ b ] ) < result ) result = Math . abs ( A [ a ] - B [ b ] ) ;\n if ( A [ a ] < B [ b ] ) a ++ ;\n else b ++ ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSmallestDifference ( A , B , m , n ) :\n A.sort ( )\n B.sort ( )\n a = 0\n b = 0\n result = sys.maxsize\n while ( a < m and b < n ) :\n if ( abs ( A [ a ] - B [ b ] ) < result ) :\n result = abs ( A [ a ] - B [ b ] )\n if ( A [ a ] < B [ b ] ) :\n a += 1\n else :\n b += 1\n return result\n\n"
},
{
"id": "python-java-CHECK_GIVEN_STRING_CAN_SPLIT_FOUR_DISTINCT_STRINGS",
"pair": "python-java",
"Code1": "def check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n",
"Code2": "public static boolean check ( String s ) {\n if ( s . length ( ) >= 10 ) return true ;\n for ( int i = 1 ;\n i < s . length ( ) ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < s . length ( ) ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < s . length ( ) ;\n k ++ ) {\n String s1 = \"\" , s2 = \"\" , s3 = \"\" , s4 = \"\" ;\n try {\n s1 = s . substring ( 0 , i ) ;\n s2 = s . substring ( i , j - i ) ;\n s3 = s . substring ( j , k - j ) ;\n s4 = s . substring ( k , s . length ( ) - k ) ;\n }\n catch ( StringIndexOutOfBoundsException e ) {\n }\n if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( s ) :\n if ( len ( s ) >= 10 ) :\n return True\n for i in range ( 1 , len ( s ) ) :\n for j in range ( i + 1 , len ( s ) ) :\n for k in range ( j + 1 , len ( s ) ) :\n s1 = s [ 0 : i ]\n s2 = s [ i : j - i ]\n s3 = s [ j : k - j ]\n s4 = s [ k : len ( s ) - k ]\n if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) :\n return True\n return False\n\n"
},
{
"id": "python-java-CHECK_POSSIBLE_PATH_2D_MATRIX",
"pair": "python-java",
"Code1": "def isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n",
"Code2": "static boolean isPath ( int arr [ ] [ ] ) {\n arr [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) if ( arr [ 0 ] [ i ] != - 1 ) arr [ 0 ] [ i ] = arr [ 0 ] [ i - 1 ] ;\n for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ j ] [ 0 ] != - 1 ) arr [ j ] [ 0 ] = arr [ j - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < 5 ;\n i ++ ) for ( int j = 1 ;\n j < 5 ;\n j ++ ) if ( arr [ i ] [ j ] != - 1 ) arr [ i ] [ j ] = Math . max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] ) ;\n return ( arr [ 5 - 1 ] [ 5 - 1 ] == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPath ( arr ) :\n arr [ 0 ] [ 0 ] = 1\n for i in range ( 1 , row ) :\n if ( arr [ i ] [ 0 ] != - 1 ) :\n arr [ i ] [ 0 ] = arr [ i - 1 ] [ 0 ]\n for j in range ( 1 , col ) :\n if ( arr [ 0 ] [ j ] != - 1 ) :\n arr [ 0 ] [ j ] = arr [ 0 ] [ j - 1 ]\n for i in range ( 1 , row ) :\n for j in range ( 1 , col ) :\n if ( arr [ i ] [ j ] != - 1 ) :\n arr [ i ] [ j ] = max ( arr [ i ] [ j - 1 ] , arr [ i - 1 ] [ j ] )\n return ( arr [ row - 1 ] [ col - 1 ] == 1 )\n\n"
},
{
"id": "python-java-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER_1",
"pair": "python-java",
"Code1": "def bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n",
"Code2": "static void bitonicGenerator ( int arr [ ] , int n ) {\n int i = 1 ;\n int j = n - 1 ;\n if ( j % 2 != 0 ) j -- ;\n while ( i < j ) {\n arr = swap ( arr , i , j ) ;\n i += 2 ;\n j -= 2 ;\n }\n Arrays . sort ( arr , 0 , ( n + 1 ) / 2 ) ;\n Arrays . sort ( arr , ( n + 1 ) / 2 , n ) ;\n int low = ( n + 1 ) / 2 , high = n - 1 ;\n while ( low < high ) {\n Integer temp = arr [ low ] ;\n arr [ low ] = arr [ high ] ;\n arr [ high ] = temp ;\n low ++ ;\n high -- ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bitonicGenerator ( arr , n ) :\n i = 1\n j = n - 1\n if ( j % 2 != 0 ) :\n j = j - 1\n while ( i < j ) :\n arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]\n i = i + 2\n j = j - 2\n arr_f = [ ]\n arr_s = [ ]\n for i in range ( int ( ( n + 1 ) / 2 ) ) :\n arr_f.append ( arr [ i ] )\n i = int ( ( n + 1 ) / 2 )\n while ( i < n ) :\n arr_s.append ( arr [ i ] )\n i = i + 1\n arr_f.sort ( )\n arr_s.sort ( reverse = True )\n for i in arr_s :\n arr_f.append ( i )\n return arr_f\n\n"
},
{
"id": "python-java-REMOVE_ARRAY_END_ELEMENT_MAXIMIZE_SUM_PRODUCT",
"pair": "python-java",
"Code1": "def solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n",
"Code2": "static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) {\n if ( low == high ) {\n return a [ low ] * turn ;\n }\n if ( dp [ low ] [ high ] != 0 ) {\n return dp [ low ] [ high ] ;\n }\n dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solve ( dp , a , low , high , turn ) :\n if ( low == high ) :\n return a [ low ] * turn\n if ( dp [ low ] [ high ] != 0 ) :\n return dp [ low ] [ high ]\n dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ;\n return dp [ low ] [ high ]\n\n"
},
{
"id": "python-java-DIRECTION_LAST_SQUARE_BLOCK",
"pair": "python-java",
"Code1": "def direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n",
"Code2": "static void direction ( int R , int C ) {\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R == C && R % 2 != 0 && C % 2 != 0 ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R == C && R % 2 == 0 && C % 2 == 0 ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Left\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 == 0 && R > C ) {\n System . out . println ( \"Up\" ) ;\n return ;\n }\n if ( R != C && R % 2 == 0 && C % 2 != 0 && R > C ) {\n System . out . println ( \"Down\" ) ;\n return ;\n }\n if ( R != C && R % 2 != 0 && C % 2 == 0 && R < C ) {\n System . out . println ( \"Right\" ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef direction ( R , C ) :\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if R == C and R % 2 != 0 and C % 2 != 0 :\n print ( \"Right\" )\n return\n if R == C and R % 2 == 0 and C % 2 == 0 :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 != 0 and R < C ) :\n print ( \"Left\" )\n return\n if ( R != C and R % 2 == 0 and C % 2 == 0 and R > C ) :\n print ( \"Up\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R > C ) :\n print ( \"Down\" )\n return\n if ( R != C and R % 2 != 0 and C % 2 != 0 and R < C ) :\n print ( \"Right\" )\n return\n\n"
},
{
"id": "python-java-SPLIT_NUMERIC_ALPHABETIC_AND_SPECIAL_SYMBOLS_FROM_A_STRING",
"pair": "python-java",
"Code1": "def splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n",
"Code2": "static void splitString ( String str ) {\n StringBuffer alpha = new StringBuffer ( ) , num = new StringBuffer ( ) , special = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isDigit ( str . charAt ( i ) ) ) num . append ( str . charAt ( i ) ) ;\n else if ( Character . isAlphabetic ( str . charAt ( i ) ) ) alpha . append ( str . charAt ( i ) ) ;\n else special . append ( str . charAt ( i ) ) ;\n }\n System . out . println ( alpha ) ;\n System . out . println ( num ) ;\n System . out . println ( special ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef splitString ( str ) :\n alpha = \"\"\n num = \"\"\n special = \"\"\n for i in range ( len ( str ) ) :\n if ( str [ i ].isdigit ( ) ) :\n num = num + str [ i ]\n elif ( ( str [ i ] >= 'A' and str [ i ] <= 'Z' ) or ( str [ i ] >= 'a' and str [ i ] <= 'z' ) ) :\n alpha += str [ i ]\n else :\n special += str [ i ]\n print ( alpha )\n print ( num )\n print ( special )\n\n"
},
{
"id": "python-java-FIND_MEDIAN_ROW_WISE_SORTED_MATRIX",
"pair": "python-java",
"Code1": "def binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n",
"Code2": "static int binaryMedian ( int m [ ] [ ] , int r , int c ) {\n int max = Integer . MIN_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < r ;\n i ++ ) {\n if ( m [ i ] [ 0 ] < min ) min = m [ i ] [ 0 ] ;\n if ( m [ i ] [ c - 1 ] > max ) max = m [ i ] [ c - 1 ] ;\n }\n int desired = ( r * c + 1 ) / 2 ;\n while ( min < max ) {\n int mid = min + ( max - min ) / 2 ;\n int place = 0 ;\n int get = 0 ;\n for ( int i = 0 ;\n i < r ;\n ++ i ) {\n get = Arrays . binarySearch ( m [ i ] , mid ) ;\n if ( get < 0 ) get = Math . abs ( get ) - 1 ;\n else {\n while ( get < m [ i ] . length && m [ i ] [ get ] == mid ) get += 1 ;\n }\n place = place + get ;\n }\n if ( place < desired ) min = mid + 1 ;\n else max = mid ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binaryMedian ( m , r , d ) :\n mi = m [ 0 ] [ 0 ]\n mx = 0\n for i in range ( r ) :\n if m [ i ] [ 0 ] < mi :\n mi = m [ i ] [ 0 ]\n if m [ i ] [ d - 1 ] > mx :\n mx = m [ i ] [ d - 1 ]\n desired = ( r * d + 1 ) // 2\n while ( mi < mx ) :\n mid = mi + ( mx - mi ) // 2\n place = [ 0 ]\n for i in range ( r ) :\n j = upper_bound ( m [ i ] , mid )\n place [ 0 ] = place [ 0 ] + j\n if place [ 0 ] < desired :\n mi = mid + 1\n else :\n mx = mid\n print ( \"Median is\" , mi )\n return\n\n"
},
{
"id": "python-java-FIND_DUPLICATES_GIVEN_ARRAY_ELEMENTS_NOT_LIMITED_RANGE",
"pair": "python-java",
"Code1": "def printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n",
"Code2": "private static void printDuplicates ( int [ ] arr , int n ) {\n Map < Integer , Integer > map = new HashMap < > ( ) ;\n int count = 0 ;\n boolean dup = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n count = map . get ( arr [ i ] ) ;\n map . put ( arr [ i ] , count + 1 ) ;\n }\n else {\n map . put ( arr [ i ] , 1 ) ;\n }\n }\n for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) {\n if ( entry . getValue ( ) > 1 ) {\n System . out . print ( entry . getKey ( ) + \" \" ) ;\n dup = true ;\n }\n }\n if ( ! dup ) {\n System . out . println ( \"-1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDuplicates ( arr ) :\n dict = { }\n for ele in arr :\n try :\n dict [ ele ] += 1\n except :\n dict [ ele ] = 1\n for item in dict :\n if ( dict [ item ] > 1 ) :\n print ( item , end = \" \" )\n print ( \"\\n\" )\n\n"
},
{
"id": "python-java-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES",
"pair": "python-java",
"Code1": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n",
"Code2": "static void fib ( int n ) {\n int a = 0 , b = 1 , c ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n c = a + b ;\n System . out . print ( c + \" \" ) ;\n a = b ;\n b = c ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n c = a + b\n print ( c , end = ' ' )\n a = b\n b = c\n\n"
},
{
"id": "python-java-SWAP_TWO_NIBBLES_BYTE",
"pair": "python-java",
"Code1": "def swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4",
"Code2": "static int swapNibbles ( int x ) {\n return ( ( x & 0x0F ) << 4",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef swapNibbles ( x ) :\n return ( ( x & 0x0F ) << 4\n"
},
{
"id": "python-java-COUNT_PALINDROMIC_SUBSEQUENCE_GIVEN_STRING_1",
"pair": "python-java",
"Code1": "def countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n",
"Code2": "static int countPS ( int i , int j ) {\n if ( i >= n || j < 0 ) return 0 ;\n if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ;\n if ( ( i - j == 1 ) || ( i - j == - 1 ) ) {\n if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ;\n else return dp [ i ] [ j ] = 2 ;\n }\n if ( i == j ) return dp [ 1 ] [ j ] = 1 ;\n else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ;\n else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPS ( i , j ) :\n if ( i >= n or j < 0 ) :\n return 0\n if ( dp [ i ] [ j ] != - 1 ) :\n return dp [ i ] [ j ]\n if ( abs ( i - j ) == 1 ) :\n if ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = 3\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = 2\n return dp [ i ] [ j ]\n if ( i == j ) :\n dp [ 1 ] [ j ] = 1\n return dp [ 1 ] [ j ]\n elif ( str [ i ] == str [ j ] ) :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 )\n return dp [ i ] [ j ]\n else :\n dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) )\n return dp [ i ] [ j ]\n\n"
},
{
"id": "python-java-SUM_DIVISORS_1_N_1",
"pair": "python-java",
"Code1": "def divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n",
"Code2": "static int divisorSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n ++ i ) sum += ( n / i ) * i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef divisorSum ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum += int ( n / i ) * i\n return int ( sum )\n\n"
},
{
"id": "python-java-ADD_1_TO_A_GIVEN_NUMBER",
"pair": "python-java",
"Code1": "def addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n",
"Code2": "static int addOne ( int x ) {\n int m = 1 ;\n while ( ( int ) ( x & m ) >= 1 ) {\n x = x ^ m ;\n m <<= 1 ;\n }\n x = x ^ m ;\n return x ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef addOne ( x ) :\n m = 1\n while ( x & m ) :\n x = x ^ m\n m <<= 1\n x = x ^ m\n return x\n\n"
},
{
"id": "python-java-CHECK_LARGE_NUMBER_DIVISIBLE_9_NOT",
"pair": "python-java",
"Code1": "def check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int digitSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) digitSum += ( str . charAt ( i ) - ' 0 ' ) ;\n return ( digitSum % 9 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n digitSum = 0\n for i in range ( 0 , n ) :\n digitSum = digitSum + ( int ) ( st [ i ] )\n return ( digitSum % 9 == 0 )\n\n"
},
{
"id": "python-java-FIND_PAIR_MAXIMUM_GCD_ARRAY",
"pair": "python-java",
"Code1": "def findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n",
"Code2": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int divisors [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % j == 0 ) {\n divisors [ j ] ++ ;\n if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ;\n }\n }\n }\n for ( int i = high ;\n i >= 1 ;\n i -- ) if ( divisors [ i ] > 1 ) return i ;\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxGCD ( arr , n ) :\n high = 0\n i = 0\n while i < n :\n high = max ( high , arr [ i ] )\n i = i + 1\n divisors = [ 0 ] * ( high + 1 )\n i = 0\n while i < n :\n j = 1\n while j <= math.sqrt ( arr [ i ] ) :\n if ( arr [ i ] % j == 0 ) :\n divisors [ j ] = divisors [ j ] + 1\n if ( j != arr [ i ] / j ) :\n divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ]\n + 1\n j = j + 1\n i = i + 1\n i = high\n while i >= 1 :\n if ( divisors [ i ] > 1 ) :\n return i\n i = i - 1\n return 1\n\n"
},
{
"id": "python-java-CONVERT_STRICTLY_INCREASING_ARRAY_MINIMUM_CHANGES",
"pair": "python-java",
"Code1": "def minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n",
"Code2": "static int minRemove ( int arr [ ] , int n ) {\n int LIS [ ] = new int [ n ] ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) LIS [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ i ] > arr [ j ] && ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) LIS [ i ] = Math . max ( LIS [ i ] , LIS [ j ] + 1 ) ;\n }\n len = Math . max ( len , LIS [ i ] ) ;\n }\n return n - len ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRemove ( arr , n ) :\n LIS = [ 0 for i in range ( n ) ]\n len = 0\n for i in range ( n ) :\n LIS [ i ] = 1\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :\n LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )\n len = max ( len , LIS [ i ] )\n return ( n - len )\n\n"
},
{
"id": "python-java-SEARCHING_FOR_PATTERNS_SET_2_KMP_ALGORITHM",
"pair": "python-java",
"Code1": "def computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n",
"Code2": "void computeLPSArray ( String pat , int M , int lps [ ] ) {\n int len = 0 ;\n int i = 1 ;\n lps [ 0 ] = 0 ;\n while ( i < M ) {\n if ( pat . charAt ( i ) == pat . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = len ;\n i ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef computeLPSArray ( pat , M , lps ) :\n len = 0\n lps [ 0 ]\n i = 1\n while i < M :\n if pat [ i ] == pat [ len ] :\n len += 1\n lps [ i ] = len\n i += 1\n else :\n if len != 0 :\n len = lps [ len - 1 ]\n else :\n lps [ i ] = 0\n i += 1\n\n"
},
{
"id": "python-java-COUNT_MINIMUM_NUMBER_SUBSETS_SUBSEQUENCES_CONSECUTIVE_NUMBERS",
"pair": "python-java",
"Code1": "def numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n",
"Code2": "static int numofsubset ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 1 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] + 1 != arr [ i + 1 ] ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numofsubset ( arr , n ) :\n x = sorted ( arr )\n count = 1\n for i in range ( 0 , n - 1 ) :\n if ( x [ i ] + 1 != x [ i + 1 ] ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-STOOGE_SORT",
"pair": "python-java",
"Code1": "def stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n",
"Code2": "static void stoogesort ( int arr [ ] , int l , int h ) {\n if ( l >= h ) return ;\n if ( arr [ l ] > arr [ h ] ) {\n int t = arr [ l ] ;\n arr [ l ] = arr [ h ] ;\n arr [ h ] = t ;\n }\n if ( h - l + 1 > 2 ) {\n int t = ( h - l + 1 ) / 3 ;\n stoogesort ( arr , l , h - t ) ;\n stoogesort ( arr , l + t , h ) ;\n stoogesort ( arr , l , h - t ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef stoogesort ( arr , l , h ) :\n if l >= h :\n return\n if arr [ l ] > arr [ h ] :\n t = arr [ l ]\n arr [ l ] = arr [ h ]\n arr [ h ] = t\n if h - l + 1 > 2 :\n t = ( int ) ( ( h - l + 1 ) / 3 )\n stoogesort ( arr , l , ( h - t ) )\n stoogesort ( arr , l + t , ( h ) )\n stoogesort ( arr , l , ( h - t ) )\n\n"
},
{
"id": "python-java-FIND_ARRANGEMENT_QUEUE_GIVEN_TIME",
"pair": "python-java",
"Code1": "def solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n",
"Code2": "static void solve ( int n , int t , char s [ ] ) {\n for ( int i = 0 ;\n i < t ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) {\n char temp = s [ j ] ;\n s [ j ] = s [ j + 1 ] ;\n s [ j + 1 ] = temp ;\n j ++ ;\n }\n System . out . print ( s ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solve ( n , t , p ) :\n s = list ( p )\n for i in range ( 0 , t ) :\n for j in range ( 0 , n - 1 ) :\n if ( s [ j ] == 'B' and s [ j + 1 ] == 'G' ) :\n temp = s [ j ]\n s [ j ] = s [ j + 1 ]\n s [ j + 1 ] = temp\n j = j + 1\n print ( ''.join ( s ) )\n\n"
},
{
"id": "python-java-HOW_TO_TURN_OFF_A_PARTICULAR_BIT_IN_A_NUMBER",
"pair": "python-java",
"Code1": "def turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n",
"Code2": "static int turnOffK ( int n , int k ) {\n if ( k <= 0 ) return n ;\n return ( n & ~ ( 1 << ( k - 1 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef turnOffK ( n , k ) :\n if ( k <= 0 ) :\n return n\n return ( n & ~ ( 1 << ( k - 1 ) ) )\n\n"
},
{
"id": "python-java-FINDING_K_MODULUS_ARRAY_ELEMENT",
"pair": "python-java",
"Code1": "def printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n",
"Code2": "static void printEqualModNumbers ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int d = arr [ n - 1 ] - arr [ 0 ] ;\n Vector < Integer > v = new Vector < > ( ) ;\n for ( int i = 1 ;\n i * i <= d ;\n i ++ ) {\n if ( d % i == 0 ) {\n v . add ( i ) ;\n if ( i != d / i ) v . add ( d / i ) ;\n }\n }\n for ( int i = 0 ;\n i < v . size ( ) ;\n i ++ ) {\n int temp = arr [ 0 ] % v . get ( i ) ;\n int j ;\n for ( j = 1 ;\n j < n ;\n j ++ ) if ( arr [ j ] % v . get ( i ) != temp ) break ;\n if ( j == n ) System . out . print ( v . get ( i ) + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printEqualModNumbers ( arr , n ) :\n arr.sort ( )\n d = arr [ n - 1 ] - arr [ 0 ]\n v = [ ]\n i = 1\n while ( i * i <= d ) :\n if ( d % i == 0 ) :\n v.append ( i )\n if ( i != d / i ) :\n v.append ( d / i )\n i += 1\n for i in range ( len ( v ) ) :\n temp = arr [ 0 ] % v [ i ]\n j = 1\n while ( j < n ) :\n if ( arr [ j ] % v [ i ] != temp ) :\n break\n j += 1\n if ( j == n ) :\n print ( v [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING_1",
"pair": "python-java",
"Code1": "def findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n",
"Code2": "static int findMaximum ( int arr [ ] , int low , int high ) {\n if ( low == high ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] >= arr [ high ] ) return arr [ low ] ;\n if ( ( high == low + 1 ) && arr [ low ] < arr [ high ] ) return arr [ high ] ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] > arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ mid ] > arr [ mid + 1 ] && arr [ mid ] < arr [ mid - 1 ] ) return findMaximum ( arr , low , mid - 1 ) ;\n else return findMaximum ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaximum ( arr , low , high ) :\n if low == high :\n return arr [ low ]\n if high == low + 1 and arr [ low ] >= arr [ high ] :\n return arr [ low ]\n if high == low + 1 and arr [ low ] < arr [ high ] :\n return arr [ high ]\n mid = ( low + high ) // 2\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :\n return findMaximum ( arr , low , mid - 1 )\n else :\n return findMaximum ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-java-SMALLEST_LENGTH_STRING_WITH_REPEATED_REPLACEMENT_OF_TWO_DISTINCT_ADJACENT",
"pair": "python-java",
"Code1": "def stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n",
"Code2": "static int stringReduction ( String str ) {\n int n = str . length ( ) ;\n int count [ ] = new int [ 3 ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n if ( count [ 0 ] == n || count [ 1 ] == n || count [ 2 ] == n ) {\n return n ;\n }\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) && ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) {\n return 2 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef stringReduction ( str ) :\n n = len ( str )\n count = [ 0 ] * 3\n for i in range ( n ) :\n count [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n if ( count [ 0 ] == n or count [ 1 ] == n or count [ 2 ] == n ) :\n return n\n if ( ( count [ 0 ] % 2 ) == ( count [ 1 ] % 2 ) and ( count [ 1 ] % 2 ) == ( count [ 2 ] % 2 ) ) :\n return 2\n return 1\n\n"
},
{
"id": "python-java-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM_1",
"pair": "python-java",
"Code1": "def KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n",
"Code2": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int [ ] dp = new int [ W + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = W ;\n j >= wt [ i ] ;\n j -- ) dp [ j ] = Math . max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;\n return dp [ W ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef KnapSack ( val , wt , n , W ) :\n dp = [ 0 ] * ( W + 1 )\n for i in range ( n ) :\n for j in range ( W , wt [ i ] , - 1 ) :\n dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] )\n return dp [ W ]\n\n"
},
{
"id": "python-java-SUM_PAIRWISE_PRODUCTS_1",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n",
"Code2": "static int findSum ( int n ) {\n int multiTerms = n * ( n + 1 ) / 2 ;\n int sum = multiTerms ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n multiTerms = multiTerms - ( i - 1 ) ;\n sum = sum + multiTerms * i ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n multiTerms = n * ( n + 1 ) // 2\n sm = multiTerms\n for i in range ( 2 , n + 1 ) :\n multiTerms = multiTerms - ( i - 1 )\n sm = sm + multiTerms * i\n return sm\n\n"
},
{
"id": "python-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE",
"pair": "python-java",
"Code1": "def recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n",
"Code2": "public static String recursiveReverse ( char [ ] str ) {\n Stack < Character > st = new Stack < > ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) st . push ( str [ i ] ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n str [ i ] = st . peek ( ) ;\n st . pop ( ) ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef recursiveReverse ( str ) :\n stack = [ ]\n for i in range ( len ( str ) ) :\n stack.append ( str [ i ] )\n for i in range ( len ( str ) ) :\n str [ i ] = stack.pop ( )\n\n"
},
{
"id": "python-java-FIND_SUBARRAY_WITH_GIVEN_SUM",
"pair": "python-java",
"Code1": "def subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum = arr [ i ] ;\n for ( j = i + 1 ;\n j <= n ;\n j ++ ) {\n if ( curr_sum == sum ) {\n int p = j - 1 ;\n System . out . println ( \"Sum found between indexes \" + i + \" and \" + p ) ;\n return 1 ;\n }\n if ( curr_sum > sum || j == n ) break ;\n curr_sum = curr_sum + arr [ j ] ;\n }\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subArraySum ( arr , n , sum ) :\n for i in range ( n ) :\n curr_sum = arr [ i ]\n j = i + 1\n while j <= n :\n if curr_sum == sum :\n print ( \"Sum found between\" )\n print ( \"indexes %d and %d\" % ( i , j - 1 ) )\n return 1\n if curr_sum > sum or j == n :\n break\n curr_sum = curr_sum + arr [ j ]\n j += 1\n print ( \"No subarray found\" )\n return 0\n\n"
},
{
"id": "python-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_1",
"pair": "python-java",
"Code1": "def getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result",
"Code2": "static int getSingle ( int arr [ ] , int n ) {\n int result = 0 ;\n int x , sum ;\n for ( int i = 0 ;\n i < INT_SIZE ;\n i ++ ) {\n sum = 0 ;\n x = ( 1 << i ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( ( arr [ j ] & x ) == 0 ) sum ++ ;\n }\n if ( ( sum % 3 ) == 0 ) result |= x ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getSingle ( arr , n ) :\n result = 0\n for i in range ( 0 , INT_SIZE ) :\n sm = 0\n x = ( 1 << i )\n for j in range ( 0 , n ) :\n if ( arr [ j ] & x ) :\n sm = sm + 1\n if ( sm % 3 ) :\n result = result\n"
},
{
"id": "python-java-COMPUTE_MODULUS_DIVISION_BY_A_POWER_OF_2_NUMBER",
"pair": "python-java",
"Code1": "def getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n",
"Code2": "static int getModulo ( int n , int d ) {\n return ( n & ( d - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getModulo ( n , d ) :\n return ( n & ( d - 1 ) )\n\n"
},
{
"id": "python-java-QUICK_WAY_CHECK_CHARACTERS_STRING",
"pair": "python-java",
"Code1": "def allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n",
"Code2": "static boolean allCharactersSame ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( s . charAt ( i ) != s . charAt ( 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef allCharactersSame ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if s [ i ] != s [ 0 ] :\n return False\n return True\n\n"
},
{
"id": "python-java-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX",
"pair": "python-java",
"Code1": "def maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n",
"Code2": "static int maxDecimalValue ( int mat [ ] [ ] , int i , int j , int p ) {\n if ( i >= N || j >= N ) {\n return 0 ;\n }\n int result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ;\n if ( mat [ i ] [ j ] == 1 ) {\n return ( int ) ( Math . pow ( 2 , p ) + result ) ;\n }\n else {\n return result ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDecimalValue ( mat , i , j , p ) :\n if i >= N or j >= N :\n return 0\n result = max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) )\n if mat [ i ] [ j ] == 1 :\n return pow ( 2 , p ) + result\n else :\n return result\n\n"
},
{
"id": "python-java-COUNT_BALANCED_BINARY_TREES_HEIGHT_H",
"pair": "python-java",
"Code1": "def countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n",
"Code2": "public static long countBT ( int h ) {\n long [ ] dp = new long [ h + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= h ;\n ++ i ) dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD ;\n return dp [ h ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countBT ( h ) :\n MOD = 1000000007\n dp = [ 0 for i in range ( h + 1 ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 1\n for i in range ( 2 , h + 1 ) :\n dp [ i ] = ( dp [ i - 1 ] * ( ( 2 * dp [ i - 2 ] ) % MOD + dp [ i - 1 ] ) % MOD ) % MOD\n return dp [ h ]\n\n"
},
{
"id": "python-java-COUNTING_INVERSIONS",
"pair": "python-java",
"Code1": "def getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n",
"Code2": "static int getInvCount ( int n ) {\n int inv_count = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) inv_count ++ ;\n return inv_count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getInvCount ( arr , n ) :\n inv_count = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n inv_count += 1\n return inv_count\n\n"
},
{
"id": "python-java-COORDINATES_RECTANGLE_GIVEN_POINTS_LIE_INSIDE",
"pair": "python-java",
"Code1": "def printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n",
"Code2": "static void printRect ( Integer X [ ] , Integer Y [ ] , int n ) {\n int Xmax = Collections . max ( Arrays . asList ( X ) ) ;\n int Xmin = Collections . min ( Arrays . asList ( X ) ) ;\n int Ymax = Collections . max ( Arrays . asList ( Y ) ) ;\n int Ymin = Collections . min ( Arrays . asList ( Y ) ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymin + \"}\" ) ;\n System . out . println ( \"{\" + Xmin + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymax + \"}\" ) ;\n System . out . println ( \"{\" + Xmax + \", \" + Ymin + \"}\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRect ( X , Y , n ) :\n Xmax = max ( X )\n Xmin = min ( X )\n Ymax = max ( Y )\n Ymin = min ( Y )\n print ( \"{\" , Xmin , \", \" , Ymin , \"}\" , sep = \"\" )\n print ( \"{\" , Xmin , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymax , \"}\" , sep = \"\" )\n print ( \"{\" , Xmax , \", \" , Ymin , \"}\" , sep = \"\" )\n\n"
},
{
"id": "python-java-DELANNOY_NUMBER_1",
"pair": "python-java",
"Code1": "def dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n",
"Code2": "static int dealnnoy ( int n , int m ) {\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) dp [ i ] [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) dp [ 0 ] [ i ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef dealnnoy ( n , m ) :\n dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]\n for i in range ( m ) :\n dp [ 0 ] [ i ] = 1\n for i in range ( 1 , m + 1 ) :\n dp [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ]\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-java-MODULAR_EXPONENTIATION_POWER_IN_MODULAR_ARITHMETIC",
"pair": "python-java",
"Code1": "def power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n",
"Code2": "static int power ( int x , int y , int p ) {\n int res = 1 ;\n x = x % p ;\n while ( y > 0 ) {\n if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ;\n y = y >> 1 ;\n x = ( x * x ) % p ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef power ( x , y , p ) :\n res = 1\n x = x % p\n while ( y > 0 ) :\n if ( ( y & 1 ) == 1 ) :\n res = ( res * x ) % p\n y = y >> 1\n x = ( x * x ) % p\n return res\n\n"
},
{
"id": "python-java-PROGRAM_CHECK_ISBN",
"pair": "python-java",
"Code1": "def isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n",
"Code2": "static boolean isValidISBN ( String isbn ) {\n int n = isbn . length ( ) ;\n if ( n != 10 ) return false ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < 9 ;\n i ++ ) {\n int digit = isbn . charAt ( i ) - ' 0 ' ;\n if ( 0 > digit || 9 < digit ) return false ;\n sum += ( digit * ( 10 - i ) ) ;\n }\n char last = isbn . charAt ( 9 ) ;\n if ( last != ' X ' && ( last < ' 0 ' || last > ' 9 ' ) ) return false ;\n sum += ( ( last == ' X ' ) ? 10 : ( last - ' 0 ' ) ) ;\n return ( sum % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isValidISBN ( isbn ) :\n if len ( isbn ) != 10 :\n return False\n _sum = 0\n for i in range ( 9 ) :\n if 0 <= int ( isbn [ i ] ) <= 9 :\n _sum += int ( isbn [ i ] ) * ( 10 - i )\n else :\n return False\n if ( isbn [ 9 ] != 'X' and 0 <= int ( isbn [ 9 ] ) <= 9 ) :\n return False\n _sum += 10 if isbn [ 9 ] == 'X' else int ( isbn [ 9 ] )\n return ( _sum % 11 == 0 )\n\n"
},
{
"id": "python-java-NEXT_GREATER_FREQUENCY_ELEMENT",
"pair": "python-java",
"Code1": "def NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n",
"Code2": "static void NFG ( int a [ ] , int n , int freq [ ] ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n int res [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) res [ i ] = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( freq [ a [ s . peek ( ) ] ] > freq [ a [ i ] ] ) s . push ( i ) ;\n else {\n while ( freq [ a [ s . peek ( ) ] ] < freq [ a [ i ] ] && s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = a [ i ] ;\n s . pop ( ) ;\n }\n s . push ( i ) ;\n }\n }\n while ( s . size ( ) > 0 ) {\n res [ s . peek ( ) ] = - 1 ;\n s . pop ( ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( res [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef NFG ( a , n ) :\n if ( n <= 0 ) :\n print ( \"List empty\" )\n return [ ]\n stack = [ 0 ] * n\n freq = { }\n for i in a :\n freq [ a [ i ] ] = 0\n for i in a :\n freq [ a [ i ] ] += 1\n res = [ 0 ] * n\n top = - 1\n top += 1\n stack [ top ] = 0\n for i in range ( 1 , n ) :\n if ( freq [ a [ stack [ top ] ] ] > freq [ a [ i ] ] ) :\n top += 1\n stack [ top ] = i\n else :\n while ( top > - 1 and freq [ a [ stack [ top ] ] ] < freq [ a [ i ] ] ) :\n res [ stack [ top ] ] = a [ i ]\n top -= 1\n top += 1\n stack [ top ] = i\n while ( top > - 1 ) :\n res [ stack [ top ] ] = - 1\n top -= 1\n return res\n\n"
},
{
"id": "python-java-SWAP_BITS_IN_A_GIVEN_NUMBER",
"pair": "python-java",
"Code1": "def swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )",
"Code2": "static int swapBits ( int x , int p1 , int p2 , int n ) {\n int set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 ) ;\n int set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 ) ;\n int xor = ( set1 ^ set2 ) ;\n xor = ( xor << p1 )",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef swapBits ( x , p1 , p2 , n ) :\n set1 = ( x >> p1 ) & ( ( 1 << n ) - 1 )\n set2 = ( x >> p2 ) & ( ( 1 << n ) - 1 )\n xor = ( set1 ^ set2 )\n xor = ( xor << p1 )\n"
},
{
"id": "python-java-PRINT_EQUAL_SUM_SETS_ARRAY_PARTITION_PROBLEM_SET_2",
"pair": "python-java",
"Code1": "def printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n",
"Code2": "static void printEqualSumSets ( int [ ] arr , int n ) {\n int i , currSum , sum = 0 ;\n for ( i = 0 ;\n i < arr . length ;\n i ++ ) sum += arr [ i ] ;\n if ( ( sum & 1 ) == 1 ) {\n System . out . print ( \"-1\" ) ;\n return ;\n }\n int k = sum >> 1 ;\n boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ;\n for ( i = 1 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ i ] = false ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = true ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n for ( currSum = 1 ;\n currSum <= k ;\n currSum ++ ) {\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ;\n if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ]",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printEqualSumSets ( arr , n ) :\n sum_array = sum ( arr )\n if ( sum_array & 1 ) :\n print ( \"-1\" )\n return\n k = sum_array >> 1\n dp = np.zeros ( ( n + 1 , k + 1 ) )\n for i in range ( 1 , k + 1 ) :\n dp [ 0 ] [ i ] = False\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = True\n for i in range ( 1 , n + 1 ) :\n for currSum in range ( 1 , k + 1 ) :\n dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ]\n if ( arr [ i - 1 ] <= currSum ) :\n dp [ i ] [ currSum ] = ( dp [ i ] [ currSum ] or dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] )\n set1 , set2 = [ ] , [ ]\n if ( not dp [ n ] [ k ] ) :\n print ( \"-1\" )\n return\n i = n\n currSum = k\n while ( i > 0 and currSum >= 0 ) :\n if ( dp [ i - 1 ] [ currSum ] ) :\n i -= 1\n set2.append ( arr [ i ] )\n elif ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) :\n i -= 1\n currSum -= arr [ i ]\n set1.append ( arr [ i ] )\n print ( \"Set 1 elements:\" , end = \" \" )\n for i in range ( len ( set1 ) ) :\n print ( set1 [ i ] , end = \" \" )\n print ( \"\\nSet 2 elements:\" , end = \" \" )\n for i in range ( len ( set2 ) ) :\n print ( set2 [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-HYPERCUBE_GRAPH",
"pair": "python-java",
"Code1": "def power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n",
"Code2": "static int power ( int n ) {\n if ( n == 1 ) return 2 ;\n return 2 * power ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef power ( n ) :\n if n == 1 :\n return 2\n return 2 * power ( n - 1 )\n\n"
},
{
"id": "python-java-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS_2",
"pair": "python-java",
"Code1": "def findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "static void findElements ( int arr [ ] , int n ) {\n int first = Integer . MIN_VALUE ;\n int second = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) second = arr [ i ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < second ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findElements ( arr , n ) :\n first = - sys.maxsize\n second = - sys.maxsize\n for i in range ( 0 , n ) :\n if ( arr [ i ] > first ) :\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n second = arr [ i ]\n for i in range ( 0 , n ) :\n if ( arr [ i ] < second ) :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-DISTRIBUTING_M_ITEMS_CIRCLE_SIZE_N_STARTING_K_TH_POSITION",
"pair": "python-java",
"Code1": "def lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n",
"Code2": "static int lastPosition ( int n , int m , int k ) {\n if ( m <= n - k + 1 ) return m + k - 1 ;\n m = m - ( n - k + 1 ) ;\n return ( m % n == 0 ) ? n : ( m % n ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lastPosition ( n , m , k ) :\n if ( m <= n - k + 1 ) :\n return m + k - 1\n m = m - ( n - k + 1 )\n if ( m % n == 0 ) :\n return n\n else :\n return m % n\n\n"
},
{
"id": "python-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_1",
"pair": "python-java",
"Code1": "def reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n",
"Code2": "static void reverseStr ( String str ) {\n int n = str . length ( ) ;\n char [ ] ch = str . toCharArray ( ) ;\n char temp ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n temp = ch [ i ] ;\n ch [ i ] = ch [ j ] ;\n ch [ j ] = temp ;\n }\n System . out . println ( ch ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef reverseStr ( str ) :\n n = len ( str )\n i , j = 0 , n - 1\n while i < j :\n str [ i ] , str [ j ] = str [ j ] , str [ i ]\n i += 1\n j -= 1\n\n"
},
{
"id": "python-java-FIND_THE_MAXIMUM_ELEMENT_IN_AN_ARRAY_WHICH_IS_FIRST_INCREASING_AND_THEN_DECREASING",
"pair": "python-java",
"Code1": "def findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"Code2": "static int findMaximum ( int arr [ ] , int low , int high ) {\n int max = arr [ low ] ;\n int i ;\n for ( i = low ;\n i <= high ;\n i ++ ) {\n if ( arr [ i ] > max ) max = arr [ i ] ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaximum ( arr , low , high ) :\n max = arr [ low ]\n i = low\n for i in range ( high + 1 ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n\n"
},
{
"id": "python-java-LONGEST_PREFIX_ALSO_SUFFIX_1",
"pair": "python-java",
"Code1": "def longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n",
"Code2": "static int longestPrefixSuffix ( String s ) {\n int n = s . length ( ) ;\n int lps [ ] = new int [ n ] ;\n lps [ 0 ] = 0 ;\n int len = 0 ;\n int i = 1 ;\n while ( i < n ) {\n if ( s . charAt ( i ) == s . charAt ( len ) ) {\n len ++ ;\n lps [ i ] = len ;\n i ++ ;\n }\n else {\n if ( len != 0 ) {\n len = lps [ len - 1 ] ;\n }\n else {\n lps [ i ] = 0 ;\n i ++ ;\n }\n }\n }\n int res = lps [ n - 1 ] ;\n return ( res > n / 2 ) ? n / 2 : res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestPrefixSuffix ( s ) :\n n = len ( s )\n lps = [ 0 ] * n\n l = 0\n i = 1\n while ( i < n ) :\n if ( s [ i ] == s [ l ] ) :\n l = l + 1\n lps [ i ] = l\n i = i + 1\n else :\n if ( l != 0 ) :\n l = lps [ l - 1 ]\n else :\n lps [ i ] = 0\n i = i + 1\n res = lps [ n - 1 ]\n if ( res > n / 2 ) :\n return n // 2\n else :\n return res\n\n"
},
{
"id": "python-java-SUM_AREA_RECTANGLES_POSSIBLE_ARRAY",
"pair": "python-java",
"Code1": "def MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n",
"Code2": "static int MaxTotalRectangleArea ( int [ ] a , int n ) {\n Arrays . sort ( a ) ;\n int sum = 0 ;\n boolean flag = false ;\n int len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ! flag ) {\n flag = true ;\n len = a [ i + 1 ] ;\n i ++ ;\n }\n else if ( ( a [ i ] == a [ i + 1 ] || a [ i ] - a [ i + 1 ] == 1 ) && ( flag ) ) {\n sum = sum + a [ i + 1 ] * len ;\n flag = false ;\n i ++ ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MaxTotalRectangleArea ( a , n ) :\n a.sort ( reverse = True )\n sum = 0\n flag = False\n len = 0\n i = 0\n while ( i < n - 1 ) :\n if ( i != 0 ) :\n i = i + 1\n if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :\n flag = True\n len = a [ i + 1 ]\n i = i + 1\n elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :\n sum = sum + a [ i + 1 ] * len\n flag = False\n i = i + 1\n return sum\n\n"
},
{
"id": "python-java-PROGRAM_TO_PRINT_FIRST_N_FIBONACCI_NUMBERS",
"pair": "python-java",
"Code1": "def printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n",
"Code2": "static void printFibonacciNumbers ( int n ) {\n int f1 = 0 , f2 = 1 , i ;\n if ( n < 1 ) return ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n System . out . print ( f2 + \" \" ) ;\n int next = f1 + f2 ;\n f1 = f2 ;\n f2 = next ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printFibonacciNumbers ( n ) :\n f1 = 0\n f2 = 1\n if ( n < 1 ) :\n return\n for x in range ( 0 , n ) :\n print ( f2 , end = \" \" )\n next = f1 + f2\n f1 = f2\n f2 = next\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_SMALLEST_ARRAY_K_CONSECUTIVE_SWAPS",
"pair": "python-java",
"Code1": "def minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n",
"Code2": "static void minimizeWithKSwaps ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n - 1 && k > 0 ;\n ++ i ) {\n int pos = i ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( j - i > k ) break ;\n if ( arr [ j ] < arr [ pos ] ) pos = j ;\n }\n int temp ;\n for ( int j = pos ;\n j > i ;\n -- j ) {\n temp = arr [ j ] ;\n arr [ j ] = arr [ j - 1 ] ;\n arr [ j - 1 ] = temp ;\n }\n k -= pos - i ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimizeWithKSwaps ( arr , n , k ) :\n for i in range ( n - 1 ) :\n pos = i\n for j in range ( i + 1 , n ) :\n if ( j - i > k ) :\n break\n if ( arr [ j ] < arr [ pos ] ) :\n pos = j\n for j in range ( pos , i , - 1 ) :\n arr [ j ] , arr [ j - 1 ] = arr [ j - 1 ] , arr [ j ]\n k -= pos - i\n\n"
},
{
"id": "python-java-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP",
"pair": "python-java",
"Code1": "def isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n",
"Code2": "static boolean isHeap ( int arr [ ] , int i , int n ) {\n if ( i > ( n - 2 ) / 2 ) {\n return true ;\n }\n 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 ) ) {\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isHeap ( arr , i , n ) :\n if i > int ( ( n - 2 ) / 2 ) :\n return True\n if ( 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 return True\n return False\n\n"
},
{
"id": "python-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_3",
"pair": "python-java",
"Code1": "def findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n",
"Code2": "static int findLength ( String str , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i <= n - 2 ;\n i ++ ) {\n int l = i , r = i + 1 ;\n int lsum = 0 , rsum = 0 ;\n while ( r < n && l >= 0 ) {\n lsum += str . charAt ( l ) - ' 0 ' ;\n rsum += str . charAt ( r ) - ' 0 ' ;\n if ( lsum == rsum ) {\n ans = Math . max ( ans , r - l + 1 ) ;\n }\n l -- ;\n r ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLength ( st , n ) :\n total = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n total [ i ] = ( total [ i - 1 ] + int ( st [ i - 1 ] ) - int ( '0' ) )\n ans = 0\n l = 2\n while ( l <= n ) :\n for i in range ( n - l + 1 ) :\n j = i + l - 1\n if ( total [ i + int ( l / 2 ) ] - total [ i ] == total [ i + l ] - total [ i + int ( l / 2 ) ] ) :\n ans = max ( ans , l )\n l = l + 2\n return ans\n\n"
},
{
"id": "python-java-COUNT_SUBARRAYS_WITH_SAME_EVEN_AND_ODD_ELEMENTS",
"pair": "python-java",
"Code1": "def countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n",
"Code2": "static int countSubarrays ( int [ ] arr , int n ) {\n int difference = 0 ;\n int ans = 0 ;\n int [ ] hash_positive = new int [ n + 1 ] ;\n int [ ] hash_negative = new int [ n + 1 ] ;\n hash_positive [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( arr [ i ] & 1 ) == 1 ) {\n difference ++ ;\n }\n else {\n difference -- ;\n }\n if ( difference < 0 ) {\n ans += hash_negative [ - difference ] ;\n hash_negative [ - difference ] ++ ;\n }\n else {\n ans += hash_positive [ difference ] ;\n hash_positive [ difference ] ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubarrays ( arr , n ) :\n difference = 0\n ans = 0\n hash_positive = [ 0 ] * ( n + 1 )\n hash_negative = [ 0 ] * ( n + 1 )\n hash_positive [ 0 ] = 1\n for i in range ( n ) :\n if ( arr [ i ] & 1 == 1 ) :\n difference = difference + 1\n else :\n difference = difference - 1\n if ( difference < 0 ) :\n ans += hash_negative [ - difference ]\n hash_negative [ - difference ] = hash_negative [ - difference ] + 1\n else :\n ans += hash_positive [ difference ]\n hash_positive [ difference ] = hash_positive [ difference ] + 1\n return ans\n\n"
},
{
"id": "python-java-KNAPSACK_PROBLEM_1",
"pair": "python-java",
"Code1": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n\n"
},
{
"id": "python-java-C_PROGRAM_SUBTRACTION_MATICES",
"pair": "python-java",
"Code1": "def multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n",
"Code2": "static void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef multiply ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]\n\n"
},
{
"id": "python-java-MAXIMUM_VALUE_CHOICE_EITHER_DIVIDING_CONSIDERING",
"pair": "python-java",
"Code1": "def maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n",
"Code2": "static int maxDP ( int n ) {\n int res [ ] = new int [ n + 1 ] ;\n res [ 0 ] = 0 ;\n res [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) res [ i ] = Math . max ( i , ( res [ i / 2 ] + res [ i / 3 ] + res [ i / 4 ] + res [ i / 5 ] ) ) ;\n return res [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDP ( n ) :\n res = list ( )\n res.append ( 0 )\n res.append ( 1 )\n i = 2\n while i < n + 1 :\n res.append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )\n i = i + 1\n return res [ n ]\n\n"
},
{
"id": "python-java-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY",
"pair": "python-java",
"Code1": "def findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n",
"Code2": "static int findDiff ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int count = 0 , max_count = 0 , min_count = n ;\n for ( int i = 0 ;\n i < ( n - 1 ) ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) {\n count += 1 ;\n continue ;\n }\n else {\n max_count = Math . max ( max_count , count ) ;\n min_count = Math . min ( min_count , count ) ;\n count = 0 ;\n }\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDiff ( arr , n ) :\n arr.sort ( )\n count = 0 max_count = 0 min_count = n\n for i in range ( 0 , ( n - 1 ) ) :\n if arr [ i ] == arr [ i + 1 ] :\n count += 1\n continue\n else :\n max_count = max ( max_count , count )\n min_count = min ( min_count , count )\n count = 0\n return max_count - min_count\n\n"
},
{
"id": "python-java-NUMBER_SINK_NODES_GRAPH",
"pair": "python-java",
"Code1": "def countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n",
"Code2": "static int countSink ( int n , int m , int edgeFrom [ ] , int edgeTo [ ] ) {\n int [ ] mark = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) mark [ edgeFrom [ i ] ] = 1 ;\n int count = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) if ( mark [ i ] == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSink ( n , m , edgeFrom , edgeTo ) :\n mark = [ 0 ] * ( n + 1 )\n for i in range ( m ) :\n mark [ edgeFrom [ i ] ] = 1\n count = 0\n for i in range ( 1 , n + 1 ) :\n if ( not mark [ i ] ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX",
"pair": "python-java",
"Code1": "def countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n",
"Code2": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( M [ i ] [ j ] < 0 ) count += 1 ;\n else break ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNegative ( M , n , m ) :\n count = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if M [ i ] [ j ] < 0 :\n count += 1\n else :\n break\n return count\n\n"
},
{
"id": "python-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_1",
"pair": "python-java",
"Code1": "def middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n if ( a > b ) {\n if ( b > c ) return b ;\n else if ( a > c ) return c ;\n else return a ;\n }\n else {\n if ( a > c ) return a ;\n else if ( b > c ) return c ;\n else return b ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n if a > b :\n if ( b > c ) :\n return b\n elif ( a > c ) :\n return c\n else :\n return a\n else :\n if ( a > c ) :\n return a\n elif ( b > c ) :\n return c\n else :\n return b\n\n"
},
{
"id": "python-java-COUNT_SUBSTRINGS_BINARY_STRING_CONTAINING_K_ONES",
"pair": "python-java",
"Code1": "def countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n",
"Code2": "static int countOfSubstringWithKOnes ( String s , int K ) {\n int N = s . length ( ) ;\n int res = 0 ;\n int countOfOne = 0 ;\n int [ ] freq = new int [ N + 1 ] ;\n freq [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n countOfOne += ( s . charAt ( i ) - ' 0 ' ) ;\n if ( countOfOne >= K ) {\n res += freq [ countOfOne - K ] ;\n }\n freq [ countOfOne ] ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOfSubstringWithKOnes ( s , K ) :\n N = len ( s )\n res = 0\n countOfOne = 0\n freq = [ 0 for i in range ( N + 1 ) ]\n freq [ 0 ] = 1\n for i in range ( 0 , N , 1 ) :\n countOfOne += ord ( s [ i ] ) - ord ( '0' )\n if ( countOfOne >= K ) :\n res += freq [ countOfOne - K ]\n freq [ countOfOne ] += 1\n return res\n\n"
},
{
"id": "python-java-FIND_FOUR_ELEMENTS_A_B_C_AND_D_IN_AN_ARRAY_SUCH_THAT_AB_CD",
"pair": "python-java",
"Code1": "def findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n",
"Code2": "boolean findPairs ( int arr [ ] ) {\n HashMap < Integer , pair > map = new HashMap < Integer , pair > ( ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( ! map . containsKey ( sum ) ) map . put ( sum , new pair ( i , j ) ) ;\n else {\n pair p = map . get ( sum ) ;\n System . out . println ( \"(\" + arr [ p . first ] + \", \" + arr [ p . second ] + \") and (\" + arr [ i ] + \", \" + arr [ j ] + \")\" ) ;\n return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findPairs ( arr , n ) :\nHash = { }\nfor i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n sum = arr [ i ] + arr [ j ]\n if sum in Hash.keys ( ) :\n prev = Hash.get ( sum )\n print ( str ( prev ) + \" and (%d, %d)\" % ( arr [ i ] , arr [ j ] ) )\n return True\n else :\n Hash [ sum ] = ( arr [ i ] , arr [ j ] )\n\n"
},
{
"id": "python-java-LINEAR_SEARCH",
"pair": "python-java",
"Code1": "def search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "public static int search ( int arr [ ] , int x ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == x ) return i ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n for i in range ( 0 , n ) :\n if ( arr [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-java-CHECK_POSSIBLE_TRANSFORM_ONE_STRING_ANOTHER",
"pair": "python-java",
"Code1": "def check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n",
"Code2": "static boolean check ( String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n boolean dp [ ] [ ] = new boolean [ n + 1 ] [ m + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = false ;\n }\n }\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) {\n for ( int j = 0 ;\n j <= s2 . length ( ) ;\n j ++ ) {\n if ( dp [ i ] [ j ] ) {\n if ( j < s2 . length ( ) && ( Character . toUpperCase ( s1 . charAt ( i ) ) == s2 . charAt ( j ) ) ) dp [ i + 1 ] [ j + 1 ] = true ;\n if ( ! Character . isUpperCase ( s1 . charAt ( i ) ) ) dp [ i + 1 ] [ j ] = true ;\n }\n }\n }\n return ( dp [ n ] [ m ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )\n dp [ 0 ] [ 0 ] = True\n for i in range ( len ( s1 ) ) :\n for j in range ( len ( s2 ) + 1 ) :\n if ( dp [ i ] [ j ] ) :\n if ( ( j < len ( s2 ) and ( s1 [ i ].upper ( ) == s2 [ j ] ) ) ) :\n dp [ i + 1 ] [ j + 1 ] = True\n if ( s1 [ i ].isupper ( ) == False ) :\n dp [ i + 1 ] [ j ] = True\n return ( dp [ n ] [ m ] )\n\n"
},
{
"id": "python-java-PROGRAM_BINARY_DECIMAL_CONVERSION_1",
"pair": "python-java",
"Code1": "def binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n",
"Code2": "static int binaryToDecimal ( String n ) {\n String num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int len = num . length ( ) ;\n for ( int i = len - 1 ;\n i >= 0 ;\n i -- ) {\n if ( num . charAt ( i ) == ' 1 ' ) dec_value += base ;\n base = base * 2 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binaryToDecimal ( n ) :\n num = n\n dec_value = 0\n base1 = 1\n len1 = len ( num )\n for i in range ( len1 - 1 , - 1 , - 1 ) :\n if ( num [ i ] == '1' ) :\n dec_value += base1\n base1 = base1 * 2\n return dec_value\n\n"
},
{
"id": "python-java-COUNT_WAYS_BUILD_STREET_GIVEN_CONSTRAINTS",
"pair": "python-java",
"Code1": "def countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n",
"Code2": "static long countWays ( int n ) {\n long dp [ ] [ ] = new long [ 2 ] [ n + 1 ] ;\n dp [ 0 ] [ 1 ] = 1 ;\n dp [ 1 ] [ 1 ] = 2 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ] ;\n dp [ 1 ] [ i ] = dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] ;\n }\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWays ( n ) :\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]\n dp [ 0 ] [ 1 ] = 1\n dp [ 1 ] [ 1 ] = 2\n for i in range ( 2 , n + 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]\n dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )\n return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]\n\n"
},
{
"id": "python-java-MIRROR_CHARACTERS_STRING",
"pair": "python-java",
"Code1": "def compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n",
"Code2": "static String compute ( String str , int n ) {\n String reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\" ;\n int l = str . length ( ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer = answer + str . charAt ( i ) ;\n for ( int i = n ;\n i < l ;\n i ++ ) answer = answer + reverseAlphabet . charAt ( str . charAt ( i ) - ' a ' ) ;\n return answer ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef compute ( st , n ) :\n reverseAlphabet = \"zyxwvutsrqponmlkjihgfedcba\"\n l = len ( st )\n answer = \"\"\n for i in range ( 0 , n ) :\n answer = answer + st [ i ]\n for i in range ( n , l ) :\n answer = ( answer + reverseAlphabet [ ord ( st [ i ] ) - ord ( 'a' ) ] )\n return answer\n\n"
},
{
"id": "python-java-MAXIMUM_LENGTH_SUBSEQUENCE_DIFFERENCE_ADJACENT_ELEMENTS_EITHER_0_1",
"pair": "python-java",
"Code1": "def maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n",
"Code2": "public static int maxLenSub ( int arr [ ] , int n ) {\n int mls [ ] = new int [ n ] , max = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mls [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( Math . abs ( arr [ i ] - arr [ j ] ) <= 1 && mls [ i ] < mls [ j ] + 1 ) mls [ i ] = mls [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max < mls [ i ] ) max = mls [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLenSub ( arr , n ) :\n mls = [ ]\n max = 0\n for i in range ( n ) :\n mls.append ( 1 )\n for i in range ( n ) :\n for j in range ( i ) :\n if ( abs ( arr [ i ] - arr [ j ] ) <= 1 and mls [ i ] < mls [ j ] + 1 ) :\n mls [ i ] = mls [ j ] + 1\n for i in range ( n ) :\n if ( max < mls [ i ] ) :\n max = mls [ i ]\n return max\n\n"
},
{
"id": "python-java-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION_1",
"pair": "python-java",
"Code1": "def exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n",
"Code2": "static long exponentiation ( long base , long exp ) {\n long t = 1L ;\n while ( exp > 0 ) {\n if ( exp % 2 != 0 ) t = ( t * base ) % N ;\n base = ( base * base ) % N ;\n exp /= 2 ;\n }\n return t % N ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef exponentiation ( bas , exp ) :\n t = 1\n while ( exp > 0 ) :\n if ( exp % 2 != 0 ) :\n t = ( t * bas ) % N\n bas = ( bas * bas ) % N\n exp = int ( exp / 2 )\n return t % N\n\n"
},
{
"id": "python-java-NEWMAN_CONWAY_SEQUENCE_1",
"pair": "python-java",
"Code1": "def sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n",
"Code2": "static int sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n int i ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n return f [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n f = array.array ( 'i' , [ 0 , 1 , 1 ] )\n for i in range ( 3 , n + 1 ) :\n r = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ]\n f.append ( r ) ;\n return r\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_15_LONGEST_BITONIC_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n",
"Code2": "static int lbs ( int arr [ ] , int n ) {\n int i , j ;\n int [ ] lis = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int [ ] lds = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lds [ i ] = 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) for ( j = n - 1 ;\n j > i ;\n j -- ) if ( arr [ i ] > arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ;\n int max = lis [ 0 ] + lds [ 0 ] - 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) if ( lis [ i ] + lds [ i ] - 1 > max ) max = lis [ i ] + lds [ i ] - 1 ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lbs ( arr ) :\n n = len ( arr )\n lis = [ 1 for i in range ( n + 1 ) ]\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if ( ( arr [ i ] > arr [ j ] ) and ( lis [ i ] < lis [ j ] + 1 ) ) :\n lis [ i ] = lis [ j ] + 1\n lds = [ 1 for i in range ( n + 1 ) ]\n for i in reversed ( range ( n - 1 ) ) :\n for j in reversed ( range ( i - 1 , n ) ) :\n if ( arr [ i ] > arr [ j ] and lds [ i ] < lds [ j ] + 1 ) :\n lds [ i ] = lds [ j ] + 1\n maximum = lis [ 0 ] + lds [ 0 ] - 1\n for i in range ( 1 , n ) :\n maximum = max ( ( lis [ i ] + lds [ i ] - 1 ) , maximum )\n return maximum\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_INCREASING_ORDER_ELEMENTS_N_ARRAYS",
"pair": "python-java",
"Code1": "def maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n",
"Code2": "static int maximumSum ( int a [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) sort ( a , i , n ) ;\n int sum = a [ n - 1 ] [ M - 1 ] ;\n int prev = a [ n - 1 ] [ M - 1 ] ;\n int i , j ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( a [ i ] [ j ] < prev ) {\n prev = a [ i ] [ j ] ;\n sum += prev ;\n break ;\n }\n }\n if ( j == - 1 ) return 0 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumSum ( a , n ) :\n global M\n for i in range ( 0 , n ) :\n a [ i ].sort ( )\n sum = a [ n - 1 ] [ M - 1 ]\n prev = a [ n - 1 ] [ M - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( a [ i ] [ j ] < prev ) :\n prev = a [ i ] [ j ]\n sum += prev\n break\n if ( j == - 1 ) :\n return 0\n return sum\n\n"
},
{
"id": "python-java-MASTER_THEOREM_SUBTRACT_CONQUER_RECURRENCES",
"pair": "python-java",
"Code1": "def fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n",
"Code2": "static int fib ( int n ) {\n if ( n <= 1 ) return n ;\n return fib ( n - 1 ) + fib ( n - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if ( n <= 1 ) :\n return n\n return fib ( n - 1 ) + fib ( n - 2 )\n\n"
},
{
"id": "python-java-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS",
"pair": "python-java",
"Code1": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n",
"Code2": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( str . charAt ( i ) - str . charAt ( j ) ) == Math . abs ( i - j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( abs ( ord ( str1 [ i ] ) - ord ( str1 [ j ] ) ) == abs ( i - j ) ) :\n result += 1 ;\n return result ;\n\n"
},
{
"id": "python-java-CHECK_IF_ALL_THE_ELEMENTS_CAN_BE_MADE_OF_SAME_PARITY_BY_INVERTING_ADJACENT_ELEMENTS",
"pair": "python-java",
"Code1": "def flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n",
"Code2": "static boolean flipsPossible ( int [ ] a , int n ) {\n int count_odd = 0 , count_even = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( a [ i ] & 1 ) == 1 ) count_odd ++ ;\n else count_even ++ ;\n }\n if ( count_odd % 2 == 1 && count_even % 2 == 1 ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef flipsPossible ( a , n ) :\n count_odd = 0 count_even = 0\n for i in range ( n ) :\n if ( a [ i ] & 1 ) :\n count_odd += 1\n else :\n count_even += 1\n if ( count_odd % 2 and count_even % 2 ) :\n return False\n else :\n return True\n\n"
},
{
"id": "python-java-CHECK_GIVEN_ARRAY_CONTAINS_DUPLICATE_ELEMENTS_WITHIN_K_DISTANCE",
"pair": "python-java",
"Code1": "def checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n",
"Code2": "static boolean checkDuplicatesWithinK ( int arr [ ] , int k ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( set . contains ( arr [ i ] ) ) return true ;\n set . add ( arr [ i ] ) ;\n if ( i >= k ) set . remove ( arr [ i - k ] ) ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkDuplicatesWithinK ( arr , n , k ) :\n myset = [ ]\n for i in range ( n ) :\n if arr [ i ] in myset :\n return True\n myset.append ( arr [ i ] )\n if ( i >= k ) :\n myset.remove ( arr [ i - k ] )\n return False\n\n"
},
{
"id": "python-java-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS_1",
"pair": "python-java",
"Code1": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n",
"Code2": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \" Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ i ] * mat [ i ] [ i ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \" Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n System . out . print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ i ] * mat [ i ] [ i ] , end = \"\" )\n print ( \"\\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n print ( mat [ i ] [ row - i - 1 ] * mat [ i ] [ row - i - 1 ] , end = \"\" )\n\n"
},
{
"id": "python-java-FIND_THE_LARGEST_RECTANGLE_OF_1S_WITH_SWAPPING_OF_COLUMNS_ALLOWED",
"pair": "python-java",
"Code1": "def maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n",
"Code2": "static int maxArea ( int mat [ ] [ ] ) {\n int hist [ ] [ ] = new int [ R + 1 ] [ C + 1 ] ;\n for ( int i = 0 ;\n i < C ;\n i ++ ) {\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n for ( int j = 1 ;\n j < R ;\n j ++ ) {\n hist [ j ] [ i ] = ( mat [ j ] [ i ] == 0 ) ? 0 : hist [ j - 1 ] [ i ] + 1 ;\n }\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n int count [ ] = new int [ R + 1 ] ;\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n count [ hist [ i ] [ j ] ] ++ ;\n }\n int col_no = 0 ;\n for ( int j = R ;\n j >= 0 ;\n j -- ) {\n if ( count [ j ] > 0 ) {\n for ( int k = 0 ;\n k < count [ j ] ;\n k ++ ) {\n hist [ i ] [ col_no ] = j ;\n col_no ++ ;\n }\n }\n }\n }\n int curr_area , max_area = 0 ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) {\n curr_area = ( j + 1 ) * hist [ i ] [ j ] ;\n if ( curr_area > max_area ) {\n max_area = curr_area ;\n }\n }\n }\n return max_area ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxArea ( mat ) :\n hist = [ [ 0 for i in range ( C + 1 ) ] for i in range ( R + 1 ) ]\n for i in range ( 0 , C , 1 ) :\n hist [ 0 ] [ i ] = mat [ 0 ] [ i ]\n for j in range ( 1 , R , 1 ) :\n if ( ( mat [ j ] [ i ] == 0 ) ) :\n hist [ j ] [ i ] = 0\n else :\n hist [ j ] [ i ] = hist [ j - 1 ] [ i ] + 1\n for i in range ( 0 , R , 1 ) :\n count = [ 0 for i in range ( R + 1 ) ]\n for j in range ( 0 , C , 1 ) :\n count [ hist [ i ] [ j ] ] += 1\n col_no = 0\n j = R\n while ( j >= 0 ) :\n if ( count [ j ] > 0 ) :\n for k in range ( 0 , count [ j ] , 1 ) :\n hist [ i ] [ col_no ] = j\n col_no += 1\n j -= 1\n max_area = 0\n for i in range ( 0 , R , 1 ) :\n for j in range ( 0 , C , 1 ) :\n curr_area = ( j + 1 ) * hist [ i ] [ j ]\n if ( curr_area > max_area ) :\n max_area = curr_area\n return max_area\n\n"
},
{
"id": "python-java-LONGEST_SUBSEQUENCE_SUCH_THAT_DIFFERENCE_BETWEEN_ADJACENTS_IS_ONE",
"pair": "python-java",
"Code1": "def longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n",
"Code2": "static int longestSubseqWithDiffOne ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ;\n }\n }\n int result = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestSubseqWithDiffOne ( arr , n ) :\n dp = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i ) :\n if ( ( arr [ i ] == arr [ j ] + 1 ) or ( arr [ i ] == arr [ j ] - 1 ) ) :\n dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 )\n result = 1\n for i in range ( n ) :\n if ( result < dp [ i ] ) :\n result = dp [ i ]\n return result\n\n"
},
{
"id": "python-java-MAXIMUM_NUMBER_OF_SQUARES_THAT_CAN_BE_FIT_IN_A_RIGHT_ANGLE_ISOSCELES_TRIANGLE",
"pair": "python-java",
"Code1": "def maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n",
"Code2": "static int maxSquare ( int b , int m ) {\n return ( b / m - 1 ) * ( b / m ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSquare ( b , m ) :\n return ( b / m - 1 ) * ( b / m ) / 2\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE",
"pair": "python-java",
"Code1": "def maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n",
"Code2": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int K ) {\n Arrays . sort ( arr ) ;\n int dp [ ] = new int [ N ] ;\n dp [ 0 ] = 0 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n dp [ i ] = dp [ i - 1 ] ;\n if ( arr [ i ] - arr [ i - 1 ] < K ) {\n if ( i >= 2 ) dp [ i ] = Math . max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] ) ;\n else dp [ i ] = Math . max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] ) ;\n }\n }\n return dp [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumPairWithDifferenceLessThanK ( arr , N , K ) :\n arr.sort ( )\n dp = [ 0 ] * N\n dp [ 0 ] = 0\n for i in range ( 1 , N ) :\n dp [ i ] = dp [ i - 1 ]\n if ( arr [ i ] - arr [ i - 1 ] < K ) :\n if ( i >= 2 ) :\n dp [ i ] = max ( dp [ i ] , dp [ i - 2 ] + arr [ i ] + arr [ i - 1 ] )\n else :\n dp [ i ] = max ( dp [ i ] , arr [ i ] + arr [ i - 1 ] )\n return dp [ N - 1 ]\n\n"
},
{
"id": "python-java-MINIMUM_OPERATION_MAKE_ELEMENTS_EQUAL_ARRAY",
"pair": "python-java",
"Code1": "def minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n",
"Code2": "public static int minOperation ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n else hash . put ( arr [ i ] , 1 ) ;\n int max_count = 0 ;\n Set < Integer > s = hash . keySet ( ) ;\n for ( int i : s ) if ( max_count < hash . get ( i ) ) max_count = hash . get ( i ) ;\n return ( n - max_count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minOperation ( arr , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ arr [ i ] ] += 1\n max_count = 0\n for i in Hash :\n if max_count < Hash [ i ] :\n max_count = Hash [ i ]\n return n - max_count\n\n"
},
{
"id": "python-java-FIND_K_PAIRS_SMALLEST_SUMS_TWO_ARRAYS",
"pair": "python-java",
"Code1": "def kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n",
"Code2": "static void kSmallestPair ( int arr1 [ ] , int n1 , int arr2 [ ] , int n2 , int k ) {\n if ( k > n1 * n2 ) {\n System . out . print ( \"k pairs don't exist\" ) ;\n return ;\n }\n int index2 [ ] = new int [ n1 ] ;\n while ( k > 0 ) {\n int min_sum = Integer . MAX_VALUE ;\n int min_index = 0 ;\n for ( int i1 = 0 ;\n i1 < n1 ;\n i1 ++ ) {\n if ( index2 [ i1 ] < n2 && arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) {\n min_index = i1 ;\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] ;\n }\n }\n System . out . print ( \"(\" + arr1 [ min_index ] + \", \" + arr2 [ index2 [ min_index ] ] + \") \" ) ;\n index2 [ min_index ] ++ ;\n k -- ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kSmallestPair ( arr1 , n1 , arr2 , n2 , k ) :\n if ( k > n1 * n2 ) :\n print ( \"k pairs don't exist\" )\n return\n index2 = [ 0 for i in range ( n1 ) ]\n while ( k > 0 ) :\n min_sum = sys.maxsize\n min_index = 0\n for i1 in range ( 0 , n1 , 1 ) :\n if ( index2 [ i1 ] < n2 and arr1 [ i1 ] + arr2 [ index2 [ i1 ] ] < min_sum ) :\n min_index = i1\n min_sum = arr1 [ i1 ] + arr2 [ index2 [ i1 ] ]\n print ( \"(\" , arr1 [ min_index ] , \",\" , arr2 [ index2 [ min_index ] ] , \")\" , end = \" \" )\n index2 [ min_index ] += 1\n k -= 1\n\n"
},
{
"id": "python-java-PRINT_A_GIVEN_MATRIX_IN_SPIRAL_FORM",
"pair": "python-java",
"Code1": "def spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n",
"Code2": "static void spiralPrint ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) {\n System . out . print ( a [ k ] [ i ] + \" \" ) ;\n }\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) {\n System . out . print ( a [ i ] [ n - 1 ] + \" \" ) ;\n }\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) {\n System . out . print ( a [ m - 1 ] [ i ] + \" \" ) ;\n }\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) {\n System . out . print ( a [ i ] [ l ] + \" \" ) ;\n }\n l ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef spiralPrint ( m , n , a ) :\n k = 0 l = 0\n while ( k < m and l < n ) :\n for i in range ( l , n ) :\n print ( a [ k ] [ i ] , end = \" \" )\n k += 1\n for i in range ( k , m ) :\n print ( a [ i ] [ n - 1 ] , end = \" \" )\n n -= 1\n if ( k < m ) :\n for i in range ( n - 1 , ( l - 1 ) , - 1 ) :\n print ( a [ m - 1 ] [ i ] , end = \" \" )\n m -= 1\n if ( l < n ) :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n print ( a [ i ] [ l ] , end = \" \" )\n l += 1\n\n"
},
{
"id": "python-java-CALCULATE_SUM_OF_ALL_NUMBERS_PRESENT_IN_A_STRING",
"pair": "python-java",
"Code1": "def findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n",
"Code2": "static int findSum ( String str ) {\n String temp = \"\" ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( Character . isDigit ( ch ) ) temp += ch ;\n else {\n sum += Integer . parseInt ( temp ) ;\n temp = \"0\" ;\n }\n }\n return sum + Integer . parseInt ( temp ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( str1 ) :\n temp = \"\"\n Sum = 0\n for ch in str1 :\n if ( ch.isdigit ( ) ) :\n temp += ch\n else :\n Sum += int ( temp )\n temp = \"0\"\n return Sum + int ( temp )\n\n"
},
{
"id": "python-java-NTH_PENTAGONAL_NUMBER",
"pair": "python-java",
"Code1": "def pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n",
"Code2": "int pentagonalNum ( int n ) {\n return ( 3 * n * n - n ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pentagonalNum ( n ) :\n return ( 3 * n * n - n ) / 2\n\n"
},
{
"id": "python-java-TOTAL_NUMBER_OF_NON_DECREASING_NUMBERS_WITH_N_DIGITS_1",
"pair": "python-java",
"Code1": "def countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n",
"Code2": "static long countNonDecreasing ( int n ) {\n int N = 10 ;\n long count = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n count *= ( N + i - 1 ) ;\n count /= i ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNonDecreasing ( n ) :\n N = 10\n count = 1\n for i in range ( 1 , n + 1 ) :\n count = int ( count * ( N + i - 1 ) )\n count = int ( count / i )\n return count\n\n"
},
{
"id": "python-java-FREQUENT_ELEMENT_ARRAY_1",
"pair": "python-java",
"Code1": "def mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n",
"Code2": "static int mostFrequent ( int arr [ ] , int n ) {\n Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int key = arr [ i ] ;\n if ( hp . containsKey ( key ) ) {\n int freq = hp . get ( key ) ;\n freq ++ ;\n hp . put ( key , freq ) ;\n }\n else {\n hp . put ( key , 1 ) ;\n }\n }\n int max_count = 0 , res = - 1 ;\n for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) {\n if ( max_count < val . getValue ( ) ) {\n res = val . getKey ( ) ;\n max_count = val . getValue ( ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef mostFrequent ( arr , n ) :\n Hash = dict ( )\n for i in range ( n ) :\n if arr [ i ] in Hash.keys ( ) :\n Hash [ arr [ i ] ] += 1\n else :\n Hash [ arr [ i ] ] = 1\n max_count = 0\n res = - 1\n for i in Hash :\n if ( max_count < Hash [ i ] ) :\n res = i\n max_count = Hash [ i ]\n return res\n\n"
},
{
"id": "python-java-K_TH_ELEMENT_TWO_SORTED_ARRAYS",
"pair": "python-java",
"Code1": "def kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n",
"Code2": "static int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) {\n int [ ] sorted1 = new int [ m + n ] ;\n int i = 0 , j = 0 , d = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n else sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n }\n while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ;\n while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ;\n return sorted1 [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kth ( arr1 , arr2 , m , n , k ) :\n sorted1 = [ 0 ] * ( m + n )\n i = 0\n j = 0\n d = 0\n while ( i < m and j < n ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n sorted1 [ d ] = arr1 [ i ]\n i += 1\n else :\n sorted1 [ d ] = arr2 [ j ]\n j += 1\n d += 1\n while ( i < m ) :\n sorted1 [ d ] = arr1 [ i ]\n d += 1\n i += 1\n while ( j < n ) :\n sorted1 [ d ] = arr2 [ j ]\n d += 1\n j += 1\n return sorted1 [ k - 1 ]\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_9_BINOMIAL_COEFFICIENT",
"pair": "python-java",
"Code1": "def binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n",
"Code2": "static int binomialCoeff ( int n , int k ) {\n if ( k == 0 || k == n ) return 1 ;\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binomialCoeff ( n , k ) :\n if k == 0 or k == n :\n return 1\n return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k )\n\n"
},
{
"id": "python-java-STRING_CONTAINING_FIRST_LETTER_EVERY_WORD_GIVEN_STRING_SPACES",
"pair": "python-java",
"Code1": "def firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n",
"Code2": "static String firstLetterWord ( String str ) {\n String result = \"\" ;\n boolean v = true ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' ▁ ' ) {\n v = true ;\n }\n else if ( str . charAt ( i ) != ' ▁ ' && v == true ) {\n result += ( str . charAt ( i ) ) ;\n v = false ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstLetterWord ( str ) :\n result = \"\"\n v = True\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ' ' ) :\n v = True\n elif ( str [ i ] != ' ' and v == True ) :\n result += ( str [ i ] )\n v = False\n return result\n\n"
},
{
"id": "python-java-REARRANGE_ARRAY_SUCH_THAT_EVEN_POSITIONED_ARE_GREATER_THAN_ODD",
"pair": "python-java",
"Code1": "def assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n",
"Code2": "static void assign ( int a [ ] , int n ) {\n Arrays . sort ( a ) ;\n int ans [ ] = new int [ n ] ;\n int p = 0 , q = n - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( i + 1 ) % 2 == 0 ) ans [ i ] = a [ q -- ] ;\n else ans [ i ] = a [ p ++ ] ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( ans [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef assign ( a , n ) :\n a.sort ( )\n ans = [ 0 ] * n\n p = 0\n q = n - 1\n for i in range ( n ) :\n if ( i + 1 ) % 2 == 0 :\n ans [ i ] = a [ q ]\n q = q - 1\n else :\n ans [ i ] = a [ p ]\n p = p + 1\n for i in range ( n ) :\n print ( ans [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY",
"pair": "python-java",
"Code1": "def printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n",
"Code2": "static void printDistinct ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) break ;\n if ( i == j ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n for i in range ( 0 , n ) :\n d = 0\n for j in range ( 0 , i ) :\n if ( arr [ i ] == arr [ j ] ) :\n d = 1\n break\n if ( d == 0 ) :\n print ( arr [ i ] )\n\n"
},
{
"id": "python-java-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2",
"pair": "python-java",
"Code1": "def countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n",
"Code2": "static int countSolutions ( int n ) {\n int res = 0 ;\n for ( int x = 0 ;\n x * x < n ;\n x ++ ) for ( int y = 0 ;\n x * x + y * y < n ;\n y ++ ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSolutions ( n ) :\n res = 0\n x = 0\n while ( x * x < n ) :\n y = 0\n while ( x * x + y * y < n ) :\n res = res + 1\n y = y + 1\n x = x + 1\n return res\n\n"
},
{
"id": "python-java-FIND_RELATIVE_COMPLEMENT_TWO_SORTED_ARRAYS",
"pair": "python-java",
"Code1": "def relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n",
"Code2": "static void relativeComplement ( int arr1 [ ] , int arr2 [ ] , int n , int m ) {\n int i = 0 , j = 0 ;\n while ( i < n && j < m ) {\n if ( arr1 [ i ] < arr2 [ j ] ) {\n System . out . print ( arr1 [ i ] + \" \" ) ;\n i ++ ;\n }\n else if ( arr1 [ i ] > arr2 [ j ] ) {\n j ++ ;\n }\n else if ( arr1 [ i ] == arr2 [ j ] ) {\n i ++ ;\n j ++ ;\n }\n }\n while ( i < n ) System . out . print ( arr1 [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef relativeComplement ( arr1 , arr2 , n , m ) :\n i = 0\n j = 0\n while ( i < n and j < m ) :\n if ( arr1 [ i ] < arr2 [ j ] ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n i += 1\n elif ( arr1 [ i ] > arr2 [ j ] ) :\n j += 1\n elif ( arr1 [ i ] == arr2 [ j ] ) :\n i += 1\n j += 1\n while ( i < n ) :\n print ( arr1 [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-java-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D_1",
"pair": "python-java",
"Code1": "def findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n",
"Code2": "static int findFourElements ( int [ ] arr , int n ) {\n HashMap < Integer , Indexes > map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n map . put ( arr [ i ] + arr [ j ] , new Indexes ( i , j ) ) ;\n }\n }\n int d = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int abs_diff = Math . abs ( arr [ i ] - arr [ j ] ) ;\n if ( map . containsKey ( abs_diff ) ) {\n Indexes indexes = map . get ( abs_diff ) ;\n if ( indexes . getI ( ) != i && indexes . getI ( ) != j && indexes . getJ ( ) != i && indexes . getJ ( ) != j ) {\n d = Math . max ( d , Math . max ( arr [ i ] , arr [ j ] ) ) ;\n }\n }\n }\n }\n return d ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findFourElements ( arr , n ) :\n mp = dict ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n mp [ arr [ i ] + arr [ j ] ] = ( i , j )\n d = - 10 ** 9\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n abs_diff = abs ( arr [ i ] - arr [ j ] )\n if abs_diff in mp.keys ( ) :\n p = mp [ abs_diff ]\n if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :\n d = max ( d , max ( arr [ i ] , arr [ j ] ) )\n return d\n\n"
},
{
"id": "python-java-COUNT_TRAILING_ZEROES_FACTORIAL_NUMBER",
"pair": "python-java",
"Code1": "def findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n",
"Code2": "static int findTrailingZeros ( int n ) {\n int count = 0 ;\n for ( int i = 5 ;\n n / i >= 1 ;\n i *= 5 ) count += n / i ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findTrailingZeros ( n ) :\n count = 0\n i = 5\n while ( n / i >= 1 ) :\n count += int ( n / i )\n i *= 5\n return int ( count )\n\n"
},
{
"id": "python-java-PRIMALITY_TEST_SET_5USING_LUCAS_LEHMER_SERIES",
"pair": "python-java",
"Code1": "def isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n",
"Code2": "static boolean isPrime ( int p ) {\n double checkNumber = Math . pow ( 2 , p ) - 1 ;\n double nextval = 4 % checkNumber ;\n for ( int i = 1 ;\n i < p - 1 ;\n i ++ ) nextval = ( nextval * nextval - 2 ) % checkNumber ;\n return ( nextval == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPrime ( p ) :\n checkNumber = 2 ** p - 1\n nextval = 4 % checkNumber\n for i in range ( 1 , p - 1 ) :\n nextval = ( nextval * nextval - 2 ) % checkNumber\n if ( nextval == 0 ) : return True\n else : return False\n\n"
},
{
"id": "python-java-COUNT_OF_SUB_STRINGS_THAT_DO_NOT_CONTAIN_ALL_THE_CHARACTERS_FROM_THE_SET_A_B_C_AT_THE_SAME_TIME",
"pair": "python-java",
"Code1": "def CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n",
"Code2": "static int CountSubstring ( char str [ ] , int n ) {\n int ans = ( n * ( n + 1 ) ) / 2 ;\n int a_index = 0 ;\n int b_index = 0 ;\n int c_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' a ' ) {\n a_index = i + 1 ;\n ans -= Math . min ( b_index , c_index ) ;\n }\n else if ( str [ i ] == ' b ' ) {\n b_index = i + 1 ;\n ans -= Math . min ( a_index , c_index ) ;\n }\n else {\n c_index = i + 1 ;\n ans -= Math . min ( a_index , b_index ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountSubString ( Str , n ) :\n ans = ( n * ( n + 1 ) ) // 2\n a_index = 0\n b_index = 0\n c_index = 0\n for i in range ( n ) :\n if ( Str [ i ] == 'a' ) :\n a_index = i + 1\n ans -= min ( b_index , c_index )\n elif ( Str [ i ] == 'b' ) :\n b_index = i + 1\n ans -= min ( a_index , c_index )\n else :\n c_index = i + 1\n ans -= min ( a_index , b_index )\n return ans\n\n"
},
{
"id": "python-java-CHECK_GIVEN_STRING_ROTATION_PALINDROME",
"pair": "python-java",
"Code1": "def isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n",
"Code2": "static boolean isPalindrome ( String str ) {\n int l = 0 ;\n int h = str . length ( ) - 1 ;\n while ( h > l ) if ( str . charAt ( l ++ ) != str . charAt ( h -- ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPalindrome ( string ) :\n l = 0\n h = len ( string ) - 1\n while h > l :\n l += 1\n h -= 1\n if string [ l - 1 ] != string [ h + 1 ] :\n return False\n return True\n\n"
},
{
"id": "python-java-MAXIMUM_NUMBER_CHOCOLATES_DISTRIBUTED_EQUALLY_AMONG_K_STUDENTS",
"pair": "python-java",
"Code1": "def maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n",
"Code2": "static int maxNumOfChocolates ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int [ ] sum = new int [ n ] ;\n int curr_rem ;\n int maxSum = 0 ;\n sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_rem = sum [ i ] % k ;\n if ( curr_rem == 0 ) {\n if ( maxSum < sum [ i ] ) maxSum = sum [ i ] ;\n }\n else if ( ! um . containsKey ( curr_rem ) ) um . put ( curr_rem , i ) ;\n else if ( maxSum < ( sum [ i ] - sum [ um . get ( curr_rem ) ] ) ) maxSum = sum [ i ] - sum [ um . get ( curr_rem ) ] ;\n }\n return ( maxSum / k ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxNumOfChocolates ( arr , n , k ) :\n um , curr_rem , maxSum = { } , 0 , 0\n sm = [ 0 ] * n\n sm [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n sm [ i ] = sm [ i - 1 ] + arr [ i ]\n for i in range ( n ) :\n curr_rem = sm [ i ] % k\n if ( not curr_rem and maxSum < sm [ i ] ) :\n maxSum = sm [ i ]\n elif ( not curr_rem in um ) :\n um [ curr_rem ] = i\n elif ( maxSum < ( sm [ i ] - sm [ um [ curr_rem ] ] ) ) :\n maxSum = sm [ i ] - sm [ um [ curr_rem ] ]\n return maxSum // k\n\n"
},
{
"id": "python-java-DECODE_STRING_RECURSIVELY_ENCODED_COUNT_FOLLOWED_SUBSTRING",
"pair": "python-java",
"Code1": "def decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n",
"Code2": "static String decode ( String str ) {\n Stack < Integer > integerstack = new Stack < > ( ) ;\n Stack < Character > stringstack = new Stack < > ( ) ;\n String temp = \"\" , result = \"\" ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n int count = 0 ;\n if ( Character . isDigit ( str . charAt ( i ) ) ) {\n while ( Character . isDigit ( str . charAt ( i ) ) ) {\n count = count * 10 + str . charAt ( i ) - ' 0 ' ;\n i ++ ;\n }\n i -- ;\n integerstack . push ( count ) ;\n }\n else if ( str . charAt ( i ) == ' ] ' ) {\n temp = \"\" ;\n count = 0 ;\n if ( ! integerstack . isEmpty ( ) ) {\n count = integerstack . peek ( ) ;\n integerstack . pop ( ) ;\n }\n while ( ! stringstack . isEmpty ( ) && stringstack . peek ( ) != ' [ ' ) {\n temp = stringstack . peek ( ) + temp ;\n stringstack . pop ( ) ;\n }\n if ( ! stringstack . empty ( ) && stringstack . peek ( ) == ' [ ' ) stringstack . pop ( ) ;\n for ( int j = 0 ;\n j < count ;\n j ++ ) result = result + temp ;\n for ( int j = 0 ;\n j < result . length ( ) ;\n j ++ ) stringstack . push ( result . charAt ( j ) ) ;\n result = \"\" ;\n }\n else if ( str . charAt ( i ) == ' [ ' ) {\n if ( Character . isDigit ( str . charAt ( i - 1 ) ) ) stringstack . push ( str . charAt ( i ) ) ;\n else {\n stringstack . push ( str . charAt ( i ) ) ;\n integerstack . push ( 1 ) ;\n }\n }\n else stringstack . push ( str . charAt ( i ) ) ;\n }\n while ( ! stringstack . isEmpty ( ) ) {\n result = stringstack . peek ( ) + result ;\n stringstack . pop ( ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decode ( Str ) :\n integerstack = [ ]\n stringstack = [ ]\n temp = \"\"\n result = \"\"\n for i in range ( len ( Str ) ) :\n count = 0\n if ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n while ( Str [ i ] >= '0' and Str [ i ] <= '9' ) :\n count = count * 10 + ord ( Str [ i ] ) - ord ( '0' )\n i += 1\n i -= 1\n integerstack.append ( count )\n elif ( Str [ i ] == ']' ) :\n temp = \"\"\n count = 0\n if ( len ( integerstack ) != 0 ) :\n count = integerstack [ - 1 ]\n integerstack.pop ( )\n while ( len ( stringstack ) != 0 and stringstack [ - 1 ] != '[' ) :\n temp = stringstack [ - 1 ] + temp\n stringstack.pop ( )\n if ( len ( stringstack ) != 0 and stringstack [ - 1 ] == '[' ) :\n stringstack.pop ( )\n for j in range ( count ) :\n result = result + temp\n for j in range ( len ( result ) ) :\n stringstack.append ( result [ j ] )\n result = \"\"\n elif ( Str [ i ] == '[' ) :\n if ( Str [ i - 1 ] >= '0' and Str [ i - 1 ] <= '9' ) :\n stringstack.append ( Str [ i ] )\n else :\n stringstack.append ( Str [ i ] )\n integerstack.append ( 1 )\n else :\n stringstack.append ( Str [ i ] )\n while len ( stringstack ) != 0 :\n result = stringstack [ - 1 ] + result\n stringstack.pop ( )\n return result\n\n"
},
{
"id": "python-java-MINIMUM_SUM_CHOOSING_MINIMUM_PAIRS_ARRAY",
"pair": "python-java",
"Code1": "def minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n",
"Code2": "static int minSum ( int [ ] A , int n ) {\n int min_val = Arrays . stream ( A ) . min ( ) . getAsInt ( ) ;\n return ( min_val * ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSum ( A ) :\n min_val = min ( A ) ;\n return min_val * ( len ( A ) - 1 )\n\n"
},
{
"id": "python-java-CHECK_IF_A_NUMBER_IS_POWER_OF_ANOTHER_NUMBER_1",
"pair": "python-java",
"Code1": "def isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n",
"Code2": "static boolean isPower ( int x , int y ) {\n int res1 = ( int ) Math . log ( y ) / ( int ) Math . log ( x ) ;\n double res2 = Math . log ( y ) / Math . log ( x ) ;\n return ( res1 == res2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPower ( x , y ) :\n res1 = math.log ( y ) / math.log ( x )\n res2 = math.log ( y ) / math.log ( x )\n return 1 if ( res1 == res2 ) else 0\n\n"
},
{
"id": "python-java-COUNT_WORDS_APPEAR_EXACTLY_TWO_TIMES_ARRAY_WORDS",
"pair": "python-java",
"Code1": "def countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n",
"Code2": "static int countWords ( String str [ ] , int n ) {\n HashMap < String , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( str [ i ] ) ) {\n int get = m . get ( str [ i ] ) ;\n m . put ( str [ i ] , get + 1 ) ;\n }\n else {\n m . put ( str [ i ] , 1 ) ;\n }\n }\n int res = 0 ;\n for ( Map . Entry < String , Integer > it : m . entrySet ( ) ) {\n if ( it . getValue ( ) == 2 ) res ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWords ( stri , n ) :\n m = dict ( )\n for i in range ( n ) :\n m [ stri [ i ] ] = m.get ( stri [ i ] , 0 ) + 1\n res = 0\n for i in m.values ( ) :\n if i == 2 :\n res += 1\n return res\n\n"
},
{
"id": "python-java-FIND_LARGEST_D_IN_ARRAY_SUCH_THAT_A_B_C_D",
"pair": "python-java",
"Code1": "def findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n",
"Code2": "static int findLargestd ( int [ ] S , int n ) {\n boolean found = false ;\n Arrays . sort ( S ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i == j ) continue ;\n for ( int k = j + 1 ;\n k < n ;\n k ++ ) {\n if ( i == k ) continue ;\n for ( int l = k + 1 ;\n l < n ;\n l ++ ) {\n if ( i == l ) continue ;\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) {\n found = true ;\n return S [ i ] ;\n }\n }\n }\n }\n }\n if ( found == false ) return Integer . MAX_VALUE ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLargestd ( S , n ) :\n found = False\n S.sort ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n for j in range ( 0 , n ) :\n if ( i == j ) :\n continue\n for k in range ( j + 1 , n ) :\n if ( i == k ) :\n continue\n for l in range ( k + 1 , n ) :\n if ( i == l ) :\n continue\n if ( S [ i ] == S [ j ] + S [ k ] + S [ l ] ) :\n found = True\n return S [ i ]\n if ( found == False ) :\n return - 1\n\n"
},
{
"id": "python-java-MAXIMUM_MINIMUM_VALUES_ALGEBRAIC_EXPRESSION",
"pair": "python-java",
"Code1": "def minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n",
"Code2": "static void minMaxValues ( int [ ] arr , int n , int m ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n sum += arr [ i ] ;\n arr [ i ] += 50 ;\n }\n boolean dp [ ] [ ] = new boolean [ MAX + 1 ] [ MAX * MAX + 1 ] ;\n dp [ 0 ] [ 0 ] = true ;\n for ( int i = 0 ;\n i < ( n + m ) ;\n i ++ ) {\n for ( int k = Math . min ( n , i + 1 ) ;\n k >= 1 ;\n k -- ) {\n for ( int j = 0 ;\n j < MAX * MAX + 1 ;\n j ++ ) {\n if ( dp [ k - 1 ] [ j ] ) dp [ k ] [ j + arr [ i ] ] = true ;\n }\n }\n }\n double max_value = - 1 * INF , min_value = INF ;\n for ( int i = 0 ;\n i < MAX * MAX + 1 ;\n i ++ ) {\n if ( dp [ n ] [ i ] ) {\n int temp = i - 50 * n ;\n max_value = Math . max ( max_value , temp * ( sum - temp ) ) ;\n min_value = Math . min ( min_value , temp * ( sum - temp ) ) ;\n }\n }\n System . out . print ( \"Maximum Value: \" + ( int ) max_value + \"\\n\" + \"Minimum Value: \" + ( int ) min_value + \"\\n\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minMaxValues ( arr , n , m ) :\n sum = 0\n INF = 1000000000\n MAX = 50\n for i in range ( 0 , ( n + m ) ) :\n sum += arr [ i ]\n arr [ i ] += 50\n dp = [ [ 0 for x in range ( MAX * MAX + 1 ) ] for y in range ( MAX + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 0 , ( n + m ) ) :\n for k in range ( min ( n , i + 1 ) , 0 , - 1 ) :\n for j in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ k - 1 ] [ j ] ) :\n dp [ k ] [ j + arr [ i ] ] = 1\n max_value = - 1 * INF\n min_value = INF\n for i in range ( 0 , MAX * MAX + 1 ) :\n if ( dp [ n ] [ i ] ) :\n temp = i - 50 * n\n max_value = max ( max_value , temp * ( sum - temp ) )\n min_value = min ( min_value , temp * ( sum - temp ) )\n print ( \"Maximum Value: {}\\nMinimum Value: {}\".format ( max_value , min_value ) )\n\n"
},
{
"id": "python-java-PRINT_POSSIBLE_EDGES_TREE_GIVEN_DIAMETER_HEIGHT_VERTICES",
"pair": "python-java",
"Code1": "def constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n",
"Code2": "static void constructTree ( int n , int d , int h ) {\n if ( d == 1 ) {\n if ( n == 2 && h == 1 ) {\n System . out . println ( \"1 2\" ) ;\n return ;\n }\n System . out . println ( \"-1\" ) ;\n return ;\n }\n if ( d > 2 * h ) {\n System . out . println ( \"-1\" ) ;\n return ;\n }\n for ( int i = 1 ;\n i <= h ;\n i ++ ) System . out . println ( i + \" \" + ( i + 1 ) ) ;\n if ( d > h ) {\n System . out . println ( \"1\" + \" \" + ( h + 2 ) ) ;\n for ( int i = h + 2 ;\n i <= d ;\n i ++ ) {\n System . out . println ( i + \" \" + ( i + 1 ) ) ;\n }\n }\n for ( int i = d + 1 ;\n i < n ;\n i ++ ) {\n int k = 1 ;\n if ( d == h ) k = 2 ;\n System . out . println ( k + \" \" + ( i + 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef constructTree ( n , d , h ) :\n if d == 1 :\n if n == 2 and h == 1 :\n print ( \"1 2\" )\n return 0\n print ( \"-1\" )\n return 0\n if d > 2 * h :\n print ( \"-1\" )\n return 0\n for i in range ( 1 , h + 1 ) :\n print ( i , \" \" , i + 1 )\n if d > h :\n print ( 1 , \" \" , h + 2 )\n for i in range ( h + 2 , d + 1 ) :\n print ( i , \" \" , i + 1 )\n for i in range ( d + 1 , n ) :\n k = 1\n if d == h :\n k = 2\n print ( k , \" \" , i + 1 )\n\n"
},
{
"id": "python-java-NUMBER_RECTANGLES_NM_GRID",
"pair": "python-java",
"Code1": "def rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n",
"Code2": "public static long rectCount ( int n , int m ) {\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) / 4 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rectCount ( n , m ) :\n return ( m * n * ( n + 1 ) * ( m + 1 ) ) // 4\n\n"
},
{
"id": "python-java-SORTING_USING_TRIVIAL_HASH_FUNCTION",
"pair": "python-java",
"Code1": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n",
"Code2": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int hash [ ] = new int [ max + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hash [ a [ i ] ] += 1 ;\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hash [ i ] != 0 ) {\n for ( int j = 0 ;\n j < hash [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortUsingHash ( a , n ) :\n Max = max ( a )\n Hash = [ 0 ] * ( Max + 1 )\n for i in range ( 0 , n ) :\n Hash [ a [ i ] ] += 1\n for i in range ( 0 , Max + 1 ) :\n if Hash [ i ] != 0 :\n for j in range ( 0 , Hash [ i ] ) :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-java-SUBARRAY_NO_PAIR_SUM_DIVISIBLE_K",
"pair": "python-java",
"Code1": "def subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n",
"Code2": "static void subarrayDivisibleByK ( int [ ] arr , int n , int k ) {\n int [ ] mp = new int [ 1000 ] ;\n int s = 0 , e = 0 , maxs = 0 , maxe = 0 ;\n mp [ arr [ 0 ] % k ] ++ ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int mod = arr [ i ] % k ;\n while ( mp [ k - mod ] != 0 || ( mod == 0 && mp [ mod ] != 0 ) ) {\n mp [ arr [ s ] % k ] -- ;\n s ++ ;\n }\n mp [ mod ] ++ ;\n e ++ ;\n if ( ( e - s ) > ( maxe - maxs ) ) {\n maxe = e ;\n maxs = s ;\n }\n }\n System . out . print ( \"The maximum size is \" + ( maxe - maxs + 1 ) + \" and the subarray is as follows\\n\" ) ;\n for ( int i = maxs ;\n i <= maxe ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subarrayDivisibleByK ( arr , n , k ) :\n mp = [ 0 ] * 1000\n s = 0 e = 0 maxs = 0 maxe = 0\n mp [ arr [ 0 ] % k ] = mp [ arr [ 0 ] % k ] + 1\n for i in range ( 1 , n ) :\n mod = arr [ i ] % k\n while ( mp [ k - mod ] != 0 or ( mod == 0 and mp [ mod ] != 0 ) ) :\n mp [ arr [ s ] % k ] = mp [ arr [ s ] % k ] - 1\n s = s + 1\n mp [ mod ] = mp [ mod ] + 1\n e = e + 1\n if ( ( e - s ) > ( maxe - maxs ) ) :\n maxe = e\n maxs = s\n print ( \"The maximum size is {} and the \".format ( ( maxe - maxs + 1 ) ) ) for i in range ( maxs , maxe + 1 ) :\n print ( \"{} \".format ( arr [ i ] ) , end = \"\" )\n\n"
},
{
"id": "python-java-CHECK_DIVISIBILITY_BINARY_STRING_2K",
"pair": "python-java",
"Code1": "def isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n",
"Code2": "static boolean isDivisible ( String str , int k ) {\n int n = str . length ( ) ;\n int c = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) if ( str . charAt ( n - i - 1 ) == ' 0 ' ) c ++ ;\n return ( c == k ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDivisible ( str , k ) :\n n = len ( str )\n c = 0\n for i in range ( 0 , k ) :\n if ( str [ n - i - 1 ] == '0' ) :\n c += 1\n return ( c == k )\n\n"
},
{
"id": "python-java-NUMBER_DIGITS_REMOVED_MAKE_NUMBER_DIVISIBLE_3",
"pair": "python-java",
"Code1": "def divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n",
"Code2": "static int divisible ( String num ) {\n int n = num . length ( ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += ( int ) ( num . charAt ( i ) ) ;\n if ( sum % 3 == 0 ) return 0 ;\n if ( n == 1 ) return - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( sum % 3 == ( num . charAt ( i ) - ' 0 ' ) % 3 ) return 1 ;\n if ( n == 2 ) return - 1 ;\n return 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef divisible ( num ) :\n n = len ( num )\n sum = 0\n for i in range ( n ) :\n sum += int ( num [ i ] )\n if ( sum % 3 == 0 ) :\n return 0\n if ( n == 1 ) :\n return - 1\n for i in range ( n ) :\n if ( sum % 3 == int ( num [ i ] ) % 3 ) :\n return 1\n if ( n == 2 ) :\n return - 1\n return 2\n\n"
},
{
"id": "python-java-SHORTEST_COMMON_SUPERSEQUENCE",
"pair": "python-java",
"Code1": "def superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n",
"Code2": "static int superSeq ( String X , String Y , int m , int n ) {\n if ( m == 0 ) return n ;\n if ( n == 0 ) return m ;\n if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ;\n return 1 + Math . min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef superSeq ( X , Y , m , n ) :\n if ( not m ) : return n\n if ( not n ) : return m\n if ( X [ m - 1 ] == Y [ n - 1 ] ) :\n return 1 + superSeq ( X , Y , m - 1 , n - 1 )\n return 1 + min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) )\n\n"
},
{
"id": "python-java-PROGRAM_SWAP_UPPER_DIAGONAL_ELEMENTS_LOWER_DIAGONAL_ELEMENTS_MATRIX",
"pair": "python-java",
"Code1": "def swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n",
"Code2": "static void swapUpperToLower ( int arr [ ] [ ] ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef swapUpperToLower ( arr ) :\n n = 4 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n temp = arr [ i ] [ j ] ;\n arr [ i ] [ j ] = arr [ j ] [ i ] ;\n arr [ j ] [ i ] = temp ;\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( arr [ i ] [ j ] , end = \" \" ) ;\n print ( \" \" ) ;\n\n"
},
{
"id": "python-java-SUM_K_TH_GROUP_ODD_POSITIVE_NUMBERS",
"pair": "python-java",
"Code1": "def kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n",
"Code2": "public static int kthgroupsum ( int k ) {\n int cur = ( k * ( k - 1 ) ) + 1 ;\n int sum = 0 ;\n while ( k -- > 0 ) {\n sum += cur ;\n cur += 2 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kthgroupsum ( k ) :\n cur = int ( ( k * ( k - 1 ) ) + 1 )\n sum = 0\n while k :\n sum += cur\n cur += 2\n k = k - 1\n return sum\n\n"
},
{
"id": "python-java-CHECK_GIVEN_MATRIX_IS_MAGIC_SQUARE_OR_NOT",
"pair": "python-java",
"Code1": "def isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n",
"Code2": "static boolean isMagicSquare ( int mat [ ] [ ] ) {\n int sum = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum = sum + mat [ i ] [ i ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) sum2 = sum2 + mat [ i ] [ N - 1 - i ] ;\n if ( sum != sum2 ) return false ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int rowSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) rowSum += mat [ i ] [ j ] ;\n if ( rowSum != sum ) return false ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int colSum = 0 ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) colSum += mat [ j ] [ i ] ;\n if ( sum != colSum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isMagicSquare ( mat ) :\n s = 0\n for i in range ( 0 , N ) :\n s = s + mat [ i ] [ i ]\n s2 = 0\n for i in range ( 0 , N ) :\n s2 = s2 + mat [ i ] [ N - i - 1 ]\n if ( s != s2 ) :\n return False\n for i in range ( 0 , N ) :\n rowSum = 0\n for j in range ( 0 , N ) :\n rowSum += mat [ i ] [ j ]\n if ( rowSum != s ) :\n return False\n for i in range ( 0 , N ) :\n colSum = 0\n for j in range ( 0 , N ) :\n colSum += mat [ j ] [ i ]\n if ( s != colSum ) :\n return False\n return True\n\n"
},
{
"id": "python-java-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX_1",
"pair": "python-java",
"Code1": "def isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n",
"Code2": "static boolean isScalarMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n for ( int i = 0 ;\n i < N - 1 ;\n i ++ ) if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isScalarMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n for i in range ( 0 , N - 1 ) :\n if ( mat [ i ] [ i ] != mat [ i + 1 ] [ i + 1 ] ) :\n return False\n return True\n\n"
},
{
"id": "python-java-LONGEST_SUBARRAY_SUM_DIVISIBLE_K",
"pair": "python-java",
"Code1": "def longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n",
"Code2": "static int longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int mod_arr [ ] = new int [ n ] ;\n int max = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] ;\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mod_arr [ i ] == 0 ) max = i + 1 ;\n else if ( um . containsKey ( mod_arr [ i ] ) == false ) um . put ( mod_arr [ i ] , i ) ;\n else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) max = i - um . get ( mod_arr [ i ] ) ;\n }\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longSubarrWthSumDivByK ( arr , n , k ) :\n um = { i : 0 for i in range ( 8 ) }\n mod_arr = [ 0 for i in range ( n ) ]\n max = 0\n curr_sum = 0\n for i in range ( n ) :\n curr_sum += arr [ i ]\n mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k\n for i in range ( n ) :\n if ( mod_arr [ i ] == 0 ) :\n max = i + 1\n elif ( mod_arr [ i ] in um ) :\n um [ mod_arr [ i ] ] = i\n else :\n if ( max < ( i - um [ mod_arr [ i ] ] ) ) :\n max = i - um [ mod_arr [ i ] ]\n return max\n\n"
},
{
"id": "python-java-REVERSE_A_STRING_USING_RECURSION",
"pair": "python-java",
"Code1": "def reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n",
"Code2": "void reverse ( String str ) {\n if ( ( str == null ) || ( str . length ( ) <= 1 ) ) System . out . println ( str ) ;\n else {\n System . out . print ( str . charAt ( str . length ( ) - 1 ) ) ;\n reverse ( str . substring ( 0 , str . length ( ) - 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef reverse ( string ) :\n if len ( string ) == 0 :\n return\n temp = string [ 0 ]\n reverse ( string [ 1 : ] )\n print ( temp , end = '' )\n\n"
},
{
"id": "python-java-BALANCED_EXPRESSIONS_SUCH_THAT_GIVEN_POSITIONS_HAVE_OPENING_BRACKETS",
"pair": "python-java",
"Code1": "def arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n",
"Code2": "static long arrangeBraces ( int n , int pos [ ] , int k ) {\n boolean h [ ] = new boolean [ N ] ;\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n h [ pos [ i ] ] = true ;\n }\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= 2 * n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 2 * n ;\n j ++ ) {\n if ( h [ i ] ) {\n if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = 0 ;\n }\n }\n else if ( j != 0 ) {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n }\n return dp [ 2 * n ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arrangeBraces ( n , pos , k ) :\n h = [ False for i in range ( N ) ]\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n for i in range ( k ) :\n h [ pos [ i ] ] = 1\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , 2 * n + 1 ) :\n for j in range ( 2 * n + 1 ) :\n if ( h [ i ] ) :\n if ( j != 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 0\n else :\n if ( j != 0 ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n return dp [ 2 * n ] [ 0 ]\n\n"
},
{
"id": "python-java-DIVISIBILITY_BY_12_FOR_A_LARGE_NUMBER",
"pair": "python-java",
"Code1": "def isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n",
"Code2": "static boolean isDvisibleBy12 ( String num ) {\n if ( num . length ( ) >= 3 ) {\n int d1 = ( int ) num . charAt ( num . length ( ) - 1 ) ;\n if ( d1 % 2 != 0 ) return false ;\n int d2 = ( int ) num . charAt ( num . length ( ) - 2 ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < num . length ( ) ;\n i ++ ) sum += num . charAt ( i ) ;\n return ( sum % 3 == 0 && ( d2 * 10 + d1 ) % 4 == 0 ) ;\n }\n else {\n int number = Integer . parseInt ( num ) ;\n return ( number % 12 == 0 ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDvisibleBy12 ( num ) :\n if ( len ( num ) >= 3 ) :\n d1 = int ( num [ len ( num ) - 1 ] )\n if ( d1 % 2 != 0 ) :\n return False\n d2 = int ( num [ len ( num ) - 2 ] )\n sum = 0\n for i in range ( 0 , len ( num ) ) :\n sum += int ( num [ i ] )\n return ( sum % 3 == 0 and ( d2 * 10 + d1 ) % 4 == 0 )\n else :\n number = int ( num )\n return ( number % 12 == 0 )\n\n"
},
{
"id": "python-java-MAXIMUM_POSSIBLE_DIFFERENCE_TWO_SUBSETS_ARRAY",
"pair": "python-java",
"Code1": "def maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n",
"Code2": "static int maxDiff ( int [ ] arr , int n ) {\n int SubsetSum_1 = 0 , SubsetSum_2 = 0 ;\n for ( int i = 0 ;\n i <= n - 1 ;\n i ++ ) {\n boolean isSingleOccurance = true ;\n for ( int j = i + 1 ;\n j <= n - 1 ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) {\n isSingleOccurance = false ;\n arr [ i ] = arr [ j ] = 0 ;\n break ;\n }\n }\n if ( isSingleOccurance ) {\n if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ;\n else SubsetSum_2 += arr [ i ] ;\n }\n }\n return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDiff ( arr , n ) :\n SubsetSum_1 = 0\n SubsetSum_2 = 0\n for i in range ( 0 , n ) :\n isSingleOccurance = True\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n isSingleOccurance = False\n arr [ i ] = arr [ j ] = 0\n break\n if ( isSingleOccurance == True ) :\n if ( arr [ i ] > 0 ) :\n SubsetSum_1 += arr [ i ]\n else :\n SubsetSum_2 += arr [ i ]\n return abs ( SubsetSum_1 - SubsetSum_2 )\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_SMALLEST_STRING_OBTAINED_CONCATENATING_ARRAY",
"pair": "python-java",
"Code1": "def lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n",
"Code2": "static String lexsmallest ( String a [ ] , int n ) {\n sort ( a , n ) ;\n String answer = \"\" ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) answer += a [ i ] ;\n return answer ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lexSmallest ( a , n ) :\n a.sort ( reverse = True )\n answer = \"\"\n for i in range ( n ) :\n answer += a [ i ]\n return answer\n\n"
},
{
"id": "python-java-MAXIMUM_WEIGHT_PATH_ENDING_ELEMENT_LAST_ROW_MATRIX",
"pair": "python-java",
"Code1": "def maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n",
"Code2": "public static int maxCost ( int mat [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < i + 1 && j < N ;\n j ++ ) dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( result < dp [ N - 1 ] [ i ] ) result = dp [ N - 1 ] [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxCost ( mat , N ) :\n dp = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]\n dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , min ( i + 1 , N ) ) :\n dp [ i ] [ j ] = mat [ i ] [ j ] + \\\n max ( dp [ i - 1 ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n result = 0\n for i in range ( N ) :\n if ( result < dp [ N - 1 ] [ i ] ) :\n result = dp [ N - 1 ] [ i ]\n return result\n\n"
},
{
"id": "python-java-WAYS_REMOVE_ONE_ELEMENT_BINARY_STRING_XOR_BECOMES_ZERO",
"pair": "python-java",
"Code1": "def xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n",
"Code2": "static int xorZero ( String s ) {\n int one_count = 0 , zero_count = 0 ;\n char [ ] str = s . toCharArray ( ) ;\n int n = str . length ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( str [ i ] == ' 1 ' ) one_count ++ ;\n else zero_count ++ ;\n if ( one_count % 2 == 0 ) return zero_count ;\n return one_count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef xorZero ( str ) :\n one_count = 0\n zero_count = 0\n n = len ( str )\n for i in range ( 0 , n , 1 ) :\n if ( str [ i ] == '1' ) :\n one_count += 1\n else :\n zero_count += 1\n if ( one_count % 2 == 0 ) :\n return zero_count\n return one_count\n\n"
},
{
"id": "python-java-N_TH_ROOT_NUMBER",
"pair": "python-java",
"Code1": "def nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n",
"Code2": "static double nthRoot ( int A , int N ) {\n double xPre = Math . random ( ) % 10 ;\n double eps = 0.001 ;\n double delX = 2147483647 ;\n double xK = 0.0 ;\n while ( delX > eps ) {\n xK = ( ( N - 1.0 ) * xPre + ( double ) A / Math . pow ( xPre , N - 1 ) ) / ( double ) N ;\n delX = Math . abs ( xK - xPre ) ;\n xPre = xK ;\n }\n return xK ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nthRoot ( A , N ) :\n xPre = random.randint ( 1 , 101 ) % 10\n eps = 0.001\n delX = 2147483647\n xK = 0.0\n while ( delX > eps ) :\n xK = ( ( N - 1.0 ) * xPre + A / pow ( xPre , N - 1 ) ) / N\n delX = abs ( xK - xPre )\n xPre = xK\n return xK\n\n"
},
{
"id": "python-java-RETURN_PREVIOUS_ELEMENT_IN_AN_EXPANDING_MATRIX",
"pair": "python-java",
"Code1": "def findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n",
"Code2": "static StringBuilder findLeft ( StringBuilder str ) {\n int n = str . length ( ) ;\n while ( n > 0 ) {\n n -- ;\n if ( str . charAt ( n ) == ' d ' ) {\n str . setCharAt ( n , ' c ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' b ' ) {\n str . setCharAt ( n , ' a ' ) ;\n break ;\n }\n if ( str . charAt ( n ) == ' a ' ) str . setCharAt ( n , ' b ' ) ;\n else if ( str . charAt ( n ) == ' c ' ) str . setCharAt ( n , ' d ' ) ;\n }\n return str ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLeft ( str ) :\n n = len ( str ) - 1\n while ( n > 0 ) :\n if ( str [ n ] == 'd' ) :\n str = str [ 0 : n ] + 'c' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'b' ) :\n str = str [ 0 : n ] + 'a' + str [ n + 1 : ]\n break\n if ( str [ n ] == 'a' ) :\n str = str [ 0 : n ] + 'b' + str [ n + 1 : ]\n elif ( str [ n ] == 'c' ) :\n str = str [ 0 : n ] + 'd' + str [ n + 1 : ]\n n -= 1\n return str\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS",
"pair": "python-java",
"Code1": "def subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n",
"Code2": "public static int subset ( int ar [ ] , int n ) {\n int res = 0 ;\n Arrays . sort ( ar ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 1 ;\n for ( ;\n i < n - 1 ;\n i ++ ) {\n if ( ar [ i ] == ar [ i + 1 ] ) count ++ ;\n else break ;\n }\n res = Math . max ( res , count ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subset ( ar , n ) :\n res = 0\n ar.sort ( )\n for i in range ( 0 , n ) :\n count = 1\n for i in range ( n - 1 ) :\n if ar [ i ] == ar [ i + 1 ] :\n count += 1\n else :\n break\n res = max ( res , count )\n return res\n\n"
},
{
"id": "python-java-SMALLEST_SUBARRAY_K_DISTINCT_NUMBERS",
"pair": "python-java",
"Code1": "def minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n",
"Code2": "static void minRange ( int arr [ ] , int n , int k ) {\n int l = 0 , r = n ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Set < Integer > s = new HashSet < Integer > ( ) ;\n int j ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n s . add ( arr [ j ] ) ;\n if ( s . size ( ) == k ) {\n if ( ( j - i ) < ( r - l ) ) {\n r = j ;\n l = i ;\n }\n break ;\n }\n }\n if ( j == n ) break ;\n }\n if ( l == 0 && r == n ) System . out . println ( \"Invalid k\" ) ;\n else System . out . println ( l + \" \" + r ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRange ( arr , n , k ) :\n l = 0\n r = n\n for i in range ( n ) :\n s = [ ]\n for j in range ( i , n ) :\n s.append ( arr [ j ] )\n if ( len ( s ) == k ) :\n if ( ( j - i ) < ( r - l ) ) :\n r = j\n l = i\n break\n if ( j == n ) :\n break\n if ( l == 0 and r == n ) :\n print ( \"Invalid k\" )\n else :\n print ( l , r )\n\n"
},
{
"id": "python-java-OVERLAPPING_SUM_TWO_ARRAY",
"pair": "python-java",
"Code1": "def findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n",
"Code2": "static int findSum ( int [ ] A , int [ ] B , int n ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ;\n else hash . put ( A [ i ] , 1 ) ;\n if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ;\n else hash . put ( B [ i ] , 1 ) ;\n }\n int sum = 0 ;\n for ( Map . Entry entry : hash . entrySet ( ) ) {\n if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( A , B , n ) :\n Hash = defaultdict ( lambda : 0 )\n for i in range ( 0 , n ) :\n Hash [ A [ i ] ] += 1\n Hash [ B [ i ] ] += 1\n Sum = 0\n for x in Hash :\n if Hash [ x ] == 1 :\n Sum += x\n return Sum\n\n"
},
{
"id": "python-java-LONGEST_PALINDROME_SUBSTRING_SET_1",
"pair": "python-java",
"Code1": "def printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n",
"Code2": "static void printSubStr ( String str , int low , int high ) {\n System . out . println ( str . substring ( low , high + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSubStr ( st , low , high ) :\n sys.stdout.write ( st [ low : high + 1 ] )\n sys.stdout.flush ( )\n return ''\n\n"
},
{
"id": "python-java-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS",
"pair": "python-java",
"Code1": "def evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n",
"Code2": "static int evenSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i += 2 ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evenSum ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n + 1 ) ) :\n if j == 0 or j == i :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0 ;\n for i in range ( 0 , n + 1 ) :\n if n % 2 == 0 :\n sum = sum + C [ n ] [ i ]\n return sum\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N_1",
"pair": "python-java",
"Code1": "def getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n",
"Code2": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n dp [ 2 ] = 2 ;\n dp [ 3 ] = 3 ;\n for ( int i = 4 ;\n i <= n ;\n i ++ ) {\n dp [ i ] = i ;\n for ( int x = 1 ;\n x <= Math . ceil ( Math . sqrt ( i ) ) ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > i ) break ;\n else dp [ i ] = Math . min ( dp [ i ] , 1 + dp [ i - temp ] ) ;\n }\n }\n int res = dp [ n ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMinSquares ( n ) :\n dp = [ 0 , 1 , 2 , 3 ]\n for i in range ( 4 , n + 1 ) :\n dp.append ( i )\n for x in range ( 1 , int ( ceil ( sqrt ( i ) ) ) + 1 ) :\n temp = x * x ;\n if temp > i :\n break\n else :\n dp [ i ] = min ( dp [ i ] , 1 + dp [ i - temp ] )\n return dp [ n ]\n\n"
},
{
"id": "python-java-SEGREGATE_EVEN_ODD_NUMBERS_SET_3",
"pair": "python-java",
"Code1": "def arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n",
"Code2": "static void arrayEvenAndOdd ( int arr [ ] , int n ) {\n int i = - 1 , j = 0 ;\n while ( j != n ) {\n if ( arr [ j ] % 2 == 0 ) {\n i ++ ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n j ++ ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) System . out . print ( arr [ k ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arrayEvenAndOdd ( arr , n ) :\n i = - 1\n j = 0\n while ( j != n ) :\n if ( arr [ j ] % 2 == 0 ) :\n i = i + 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n j = j + 1\n for i in arr :\n print ( str ( i ) + \" \" , end = '' )\n\n"
},
{
"id": "python-java-SQUARES_OF_MATRIX_DIAGONAL_ELEMENTS",
"pair": "python-java",
"Code1": "def diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n",
"Code2": "static void diagonalsquare ( int mat [ ] [ ] , int row , int column ) {\n System . out . print ( \"Diagonal one : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i == j ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n System . out . print ( \"Diagonal two : \" ) ;\n for ( int i = 0 ;\n i < row ;\n i ++ ) {\n for ( int j = 0 ;\n j < column ;\n j ++ ) if ( i + j == column - 1 ) System . out . print ( mat [ i ] [ j ] * mat [ i ] [ j ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef diagonalsquare ( mat , row , column ) :\n print ( \"Diagonal one : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i == j ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n print ( \" \\n\\nDiagonal two : \" , end = \"\" )\n for i in range ( 0 , row ) :\n for j in range ( 0 , column ) :\n if ( i + j == column - 1 ) :\n print ( \"{} \".format ( mat [ i ] [ j ] * mat [ i ] [ j ] ) , end = \"\" )\n\n"
},
{
"id": "python-java-CHECK_SUMS_TH_ROW_TH_COLUMN_MATRIX",
"pair": "python-java",
"Code1": "def areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n",
"Code2": "static boolean areSumSame ( int a [ ] [ ] , int n , int m ) {\n int sum1 = 0 , sum2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum1 = 0 ;\n sum2 = 0 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n sum1 += a [ i ] [ j ] ;\n sum2 += a [ j ] [ i ] ;\n }\n if ( sum1 == sum2 ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef areSumSame ( a , n , m ) :\n sum1 = 0\n sum2 = 0\n for i in range ( 0 , n ) :\n sum1 = 0\n sum2 = 0\n for j in range ( 0 , m ) :\n sum1 += a [ i ] [ j ]\n sum2 += a [ j ] [ i ]\n if ( sum1 == sum2 ) :\n return 1\n return 0\n\n"
},
{
"id": "python-java-GIVEN_SORTED_ARRAY_NUMBER_X_FIND_PAIR_ARRAY_WHOSE_SUM_CLOSEST_X",
"pair": "python-java",
"Code1": "def printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n",
"Code2": "static void printClosest ( int arr [ ] , int n , int x ) {\n int res_l = 0 , res_r = 0 ;\n int l = 0 , r = n - 1 , diff = Integer . MAX_VALUE ;\n while ( r > l ) {\n if ( Math . abs ( arr [ l ] + arr [ r ] - x ) < diff ) {\n res_l = l ;\n res_r = r ;\n diff = Math . abs ( arr [ l ] + arr [ r ] - x ) ;\n }\n if ( arr [ l ] + arr [ r ] > x ) r -- ;\n else l ++ ;\n }\n System . out . println ( \" The closest pair is \" + arr [ res_l ] + \" and \" + arr [ res_r ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printClosest ( arr , n , x ) :\n res_l , res_r = 0 , 0\n l , r , diff = 0 , n - 1 , MAX_VAL\n while r > l :\n if abs ( arr [ l ] + arr [ r ] - x ) < diff :\n res_l = l\n res_r = r\n diff = abs ( arr [ l ] + arr [ r ] - x )\n if arr [ l ] + arr [ r ] > x :\n r -= 1\n else :\n l += 1\n print ( 'The closest pair is {} and {}'.format ( arr [ res_l ] , arr [ res_r ] ) )\n\n"
},
{
"id": "python-java-GIVEN_BINARY_STRING_COUNT_NUMBER_SUBSTRINGS_START_END_1_1",
"pair": "python-java",
"Code1": "def countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n",
"Code2": "int countSubStr ( char str [ ] , int n ) {\n int m = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( str [ i ] == ' 1 ' ) m ++ ;\n }\n return m * ( m - 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubStr ( st , n ) :\n m = 0\n for i in range ( 0 , n ) :\n if ( st [ i ] == '1' ) :\n m = m + 1\n return m * ( m - 1 ) // 2\n\n"
},
{
"id": "python-java-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS",
"pair": "python-java",
"Code1": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n",
"Code2": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i ;\n j < n ;\n j ++ ) if ( s . charAt ( i ) == s . charAt ( j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n for i in range ( n ) :\n for j in range ( i , n ) :\n if ( s [ i ] == s [ j ] ) :\n result = result + 1\n return result\n\n"
},
{
"id": "python-java-CALCULATE_MAXIMUM_VALUE_USING_SIGN_TWO_NUMBERS_STRING",
"pair": "python-java",
"Code1": "def calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n",
"Code2": "static int calcMaxValue ( String str ) {\n int res = str . charAt ( 0 ) - ' 0 ' ;\n for ( int i = 1 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ' 0 ' || str . charAt ( i ) == ' 1 ' || res < 2 ) res += ( str . charAt ( i ) - ' 0 ' ) ;\n else res *= ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calcMaxValue ( str ) :\n res = ord ( str [ 0 ] ) - 48\n for i in range ( 1 , len ( str ) ) :\n if ( str [ i ] == '0' or str [ i ] == '1' or res < 2 ) :\n res += ord ( str [ i ] ) - 48\n else :\n res *= ord ( str [ i ] ) - 48\n return res\n\n"
},
{
"id": "python-java-PROGRAM_BEST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-java",
"Code1": "def bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "static void bestFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int bestIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( bestIdx == - 1 ) bestIdx = j ;\n else if ( blockSize [ bestIdx ] > blockSize [ j ] ) bestIdx = j ;\n }\n }\n if ( bestIdx != - 1 ) {\n allocation [ i ] = bestIdx ;\n blockSize [ bestIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bestFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n bestIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if bestIdx == - 1 :\n bestIdx = j\n elif blockSize [ bestIdx ] > blockSize [ j ] :\n bestIdx = j\n if bestIdx != - 1 :\n allocation [ i ] = bestIdx\n blockSize [ bestIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-java-FREQUENCY_ELEMENT_UNSORTED_ARRAY_1",
"pair": "python-java",
"Code1": "def countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n",
"Code2": "static void countFreq ( int a [ ] , int n ) {\n int hm [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm [ a [ i ] ] ++ ;\n int cumul = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n cumul += hm [ a [ i ] ] ;\n if ( hm [ a [ i ] ] != 0 ) {\n System . out . println ( a [ i ] + \"->\" + cumul ) ;\n }\n hm [ a [ i ] ] = 0 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countFreq ( a , n ) :\n hm = dict ( )\n for i in range ( n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n cumul = 0\n for i in range ( n ) :\n cumul += hm [ a [ i ] ]\n if ( hm [ a [ i ] ] > 0 ) :\n print ( a [ i ] , \"->\" , cumul )\n hm [ a [ i ] ] = 0\n\n"
},
{
"id": "python-java-GIVEN_LARGE_NUMBER_CHECK_SUBSEQUENCE_DIGITS_DIVISIBLE_8",
"pair": "python-java",
"Code1": "def isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n",
"Code2": "static boolean isSubSeqDivisible ( String str ) {\n int i , j , k , l = str . length ( ) ;\n int arr [ ] = new int [ l ] ;\n for ( i = 0 ;\n i < l ;\n i ++ ) {\n for ( j = i ;\n j < l ;\n j ++ ) {\n for ( k = j ;\n k < l ;\n k ++ ) {\n if ( arr [ i ] % 8 == 0 ) return true ;\n else if ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 && i != j ) return true ;\n else if ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 && i != j && j != k && i != k ) return true ;\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubSeqDivisible ( st ) :\n l = len ( st )\n arr = [ 0 ] * l\n for i in range ( 0 , l ) :\n for j in range ( i , l ) :\n for k in range ( j , l ) :\n if ( arr [ i ] % 8 == 0 ) :\n return True\n elif ( ( arr [ i ] * 10 + arr [ j ] ) % 8 == 0 and i != j ) :\n return True\n elif ( ( arr [ i ] * 100 + arr [ j ] * 10 + arr [ k ] ) % 8 == 0 and i != j and j != k and i != k ) :\n return True\n return False\n\n"
},
{
"id": "python-java-COMPUTE_THE_INTEGER_ABSOLUTE_VALUE_ABS_WITHOUT_BRANCHING",
"pair": "python-java",
"Code1": "def getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n",
"Code2": "static int getAbs ( int n ) {\n int mask = n >> ( SIZE_INT * CHAR_BIT - 1 ) ;\n return ( ( n + mask ) ^ mask ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getAbs ( n ) :\n mask = n >> ( SIZE_INT * CHARBIT - 1 )\n return ( ( n + mask ) ^ mask )\n\n"
},
{
"id": "python-java-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY",
"pair": "python-java",
"Code1": "def countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] == product ) {\n result ++ ;\n break ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n result = 0 ;\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ] ;\n for k in range ( 0 , n ) :\n if ( arr [ k ] == product ) :\n result = result + 1 ;\n break ;\n return result ;\n\n"
},
{
"id": "python-java-CLUSTERINGPARTITIONING_AN_ARRAY_SUCH_THAT_SUM_OF_SQUARE_DIFFERENCES_IS_MINIMUM_1",
"pair": "python-java",
"Code1": "def minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n",
"Code2": "static int minCost ( int a [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= k ;\n j ++ ) dp [ i ] [ j ] = inf ;\n dp [ 0 ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) for ( int m = i - 1 ;\n m >= 0 ;\n m -- ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCost ( a , n , k ) :\n dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n for m in range ( i - 1 , - 1 , - 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-java-CHECK_GRAPHS_CYCLE_ODD_LENGTH",
"pair": "python-java",
"Code1": "def containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n",
"Code2": "public static boolean containsOdd ( int G [ ] [ ] , int src ) {\n int colorArr [ ] = new int [ V ] ;\n for ( int i = 0 ;\n i < V ;\n ++ i ) colorArr [ i ] = - 1 ;\n colorArr [ src ] = 1 ;\n LinkedList < Integer > q = new LinkedList < Integer > ( ) ;\n q . add ( src ) ;\n while ( ! q . isEmpty ( ) ) {\n int u = q . peek ( ) ;\n q . pop ( ) ;\n if ( G [ u ] [ u ] == 1 ) return true ;\n for ( int v = 0 ;\n v < V ;\n ++ v ) {\n if ( G [ u ] [ v ] == 1 && colorArr [ v ] == - 1 ) {\n colorArr [ v ] = 1 - colorArr [ u ] ;\n q . push ( v ) ;\n }\n else if ( G [ u ] [ v ] == 1 && colorArr [ v ] == colorArr [ u ] ) return true ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef containsOdd ( G , src ) :\n global V\n colorArr = [ - 1 ] * V\n colorArr [ src ] = 1\n q = queue.Queue ( )\n q.put ( src )\n while ( not q.empty ( ) ) :\n u = q.get ( )\n if ( G [ u ] [ u ] == 1 ) :\n return True\n for v in range ( V ) :\n if ( G [ u ] [ v ] and colorArr [ v ] == - 1 ) :\n colorArr [ v ] = 1 - colorArr [ u ]\n q.put ( v )\n elif ( G [ u ] [ v ] and colorArr [ v ] == colorArr [ u ] ) :\n return True\n return False\n\n"
},
{
"id": "python-java-COUNT_SET_BITS_IN_AN_INTEGER_3",
"pair": "python-java",
"Code1": "def countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n",
"Code2": "public static int countSetBits ( int n ) {\n if ( n == 0 ) return 0 ;\n else return 1 + countSetBits ( n & ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n if ( n == 0 ) :\n return 0\n else :\n return 1 + countSetBits ( n & ( n - 1 ) )\n\n"
},
{
"id": "python-java-CHECK_STRING_FOLLOWS_ANBN_PATTERN_NOT",
"pair": "python-java",
"Code1": "def isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n",
"Code2": "public static boolean isAnBn ( String s ) {\n int l = s . length ( ) ;\n if ( l % 2 == 1 ) {\n return false ;\n }\n int i = 0 ;\n int j = l - 1 ;\n while ( i < j ) {\n if ( s . charAt ( i ) != ' a ' || s . charAt ( j ) != ' b ' ) {\n return false ;\n }\n i ++ ;\n j -- ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isAnBn ( str ) :\n n = len ( str )\n for i in range ( n ) :\n if ( str [ i ] != 'a' ) :\n break\n if ( i * 2 != n ) :\n return False\n for j in range ( i , n ) :\n if ( str [ j ] != 'b' ) :\n return False\n return True\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_SQUARES_WHOSE_SUM_EQUALS_TO_GIVEN_NUMBER_N",
"pair": "python-java",
"Code1": "def getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n",
"Code2": "static int getMinSquares ( int n ) {\n if ( n <= 3 ) return n ;\n int res = n ;\n for ( int x = 1 ;\n x <= n ;\n x ++ ) {\n int temp = x * x ;\n if ( temp > n ) break ;\n else res = Math . min ( res , 1 + getMinSquares ( n - temp ) ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMinSquares ( n ) :\n if n <= 3 :\n return n ;\n res = n\n for x in range ( 1 , n + 1 ) :\n temp = x * x ;\n if temp > n :\n break\n else :\n res = min ( res , 1 + getMinSquares ( n - temp ) )\n return res ;\n\n"
},
{
"id": "python-java-MAXIMUM_DISTANCE_TWO_OCCURRENCES_ELEMENT_ARRAY",
"pair": "python-java",
"Code1": "def maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n",
"Code2": "static int maxDistance ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > map = new HashMap < > ( ) ;\n int max_dist = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! map . containsKey ( arr [ i ] ) ) map . put ( arr [ i ] , i ) ;\n else max_dist = Math . max ( max_dist , i - map . get ( arr [ i ] ) ) ;\n }\n return max_dist ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDistance ( arr , n ) :\n mp = { }\n maxDict = 0\n for i in range ( n ) :\n if arr [ i ] not in mp.keys ( ) :\n mp [ arr [ i ] ] = i\n else :\n maxDict = max ( maxDict , i - mp [ arr [ i ] ] )\n return maxDict\n\n"
},
{
"id": "python-java-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE",
"pair": "python-java",
"Code1": "def maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n",
"Code2": "static int maxSumWO3Consec ( int arr [ ] , int n ) {\n int sum [ ] = new int [ n ] ;\n if ( n >= 1 ) sum [ 0 ] = arr [ 0 ] ;\n if ( n >= 2 ) sum [ 1 ] = arr [ 0 ] + arr [ 1 ] ;\n if ( n > 2 ) sum [ 2 ] = Math . max ( sum [ 1 ] , Math . max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) ) ;\n for ( int i = 3 ;\n i < n ;\n i ++ ) sum [ i ] = Math . max ( Math . max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] ) ;\n return sum [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumWO3Consec ( arr , n ) :\n sum = [ 0 for k in range ( n ) ]\n if n >= 1 :\n sum [ 0 ] = arr [ 0 ]\n if n >= 2 :\n sum [ 1 ] = arr [ 0 ] + arr [ 1 ]\n if n > 2 :\n sum [ 2 ] = max ( sum [ 1 ] , max ( arr [ 1 ] + arr [ 2 ] , arr [ 0 ] + arr [ 2 ] ) )\n for i in range ( 3 , n ) :\n sum [ i ] = max ( max ( sum [ i - 1 ] , sum [ i - 2 ] + arr [ i ] ) , arr [ i ] + arr [ i - 1 ] + sum [ i - 3 ] )\n return sum [ n - 1 ]\n\n"
},
{
"id": "python-java-EULERS_FOUR_SQUARE_IDENTITY_1",
"pair": "python-java",
"Code1": "def checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n",
"Code2": "public static void checkEulerFourSquareIdentity ( int a , int b ) {\n int ab = a * b ;\n boolean flag = false ;\n int i = 0 ;\n while ( i * i <= ab ) {\n int j = i ;\n while ( i * i + j * j <= ab ) {\n int k = j ;\n while ( i * i + j * j + k * k <= ab ) {\n double l = Math . sqrt ( ab - ( i * i + j * j + k * k ) ) ;\n if ( Math . floor ( l ) == Math . ceil ( l ) && l >= k ) {\n flag = true ;\n System . out . print ( \"i = \" + i + \"\\n\" ) ;\n System . out . print ( \"j = \" + j + \"\\n\" ) ;\n System . out . print ( \"k = \" + k + \"\\n\" ) ;\n System . out . print ( \"l = \" + ( int ) l + \"\\n\" ) ;\n System . out . print ( \"Product of \" + a + \" and \" + b + \" can be written as sum of squares\" + \" of i, j, k, l \\n\" ) ;\n System . out . print ( ab + \" = \" + i + \"*\" + i + \" + \" + j + \"*\" + j + \" + \" + k + \"*\" + k + \" + \" + ( int ) l + \"*\" + ( int ) l + \"\\n\" ) ;\n }\n k += 1 ;\n }\n j += 1 ;\n }\n i += 1 ;\n }\n if ( flag == false ) {\n System . out . println ( \"Solution doesn't exist!\" ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkEulerFourSquareIdentity ( a , b ) :\n ab = a * b\n flag = False\n i = 0\n while i * i <= ab :\n j = i\n while i * i + j * j <= ab :\n k = j\n while i * i + j * j + k * k <= ab :\n l = ( ab - ( i * i + j * j + k * k ) ) ** ( 0.5 )\n if l == int ( l ) and l >= k :\n flag = True\n print ( \"i = \" , i )\n print ( \"j = \" , j )\n print ( \"k = \" , k )\n print ( \"l = \" , l )\n print ( \"Product of\" , a , \"and\" , b , \"can be written as sum of squares of i, j, k, l\" )\n print ( ab , \" = \" , i , \"*\" , i , \"+\" , j , \"*\" , j , \"+\" , k , \"*\" , k , \"+\" , l , \"*\" , l )\n k += 1\n j += 1\n i += 1\n if flag == False :\n print ( \"Solution doesn't exist!\" )\n return\n\n"
},
{
"id": "python-java-NOBLE_INTEGERS_IN_AN_ARRAY_COUNT_OF_GREATER_ELEMENTS_IS_EQUAL_TO_VALUE_1",
"pair": "python-java",
"Code1": "def nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n",
"Code2": "public static int nobleInteger ( int arr [ ] ) {\n Arrays . sort ( arr ) ;\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( arr [ i ] == arr [ i + 1 ] ) continue ;\n if ( arr [ i ] == n - i - 1 ) return arr [ i ] ;\n }\n if ( arr [ n - 1 ] == 0 ) return arr [ n - 1 ] ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nobleInteger ( arr ) :\n arr.sort ( )\n n = len ( arr )\n for i in range ( n - 1 ) :\n if arr [ i ] == arr [ i + 1 ] :\n continue\n if arr [ i ] == n - i - 1 :\n return arr [ i ]\n if arr [ n - 1 ] == 0 :\n return arr [ n - 1 ]\n return - 1\n\n"
},
{
"id": "python-java-COUNT_NUMBER_ISLANDS_EVERY_ISLAND_SEPARATED_LINE",
"pair": "python-java",
"Code1": "def countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n",
"Code2": "static int countIslands ( int mat [ ] [ ] , int m , int n ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == ' X ' ) {\n if ( ( i == 0 || mat [ i - 1 ] [ j ] == ' O ' ) && ( j == 0 || mat [ i ] [ j - 1 ] == ' O ' ) ) count ++ ;\n }\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countIslands ( mat ) :\n count = 0\n for i in range ( 0 , M ) :\n for j in range ( 0 , N ) :\n if ( mat [ i ] [ j ] == 'X' ) :\n if ( ( i == 0 or mat [ i - 1 ] [ j ] == 'O' ) and ( j == 0 or mat [ i ] [ j - 1 ] == 'O' ) ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-SELECT_A_RANDOM_NUMBER_FROM_STREAM_WITH_O1_SPACE",
"pair": "python-java",
"Code1": "def selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n",
"Code2": "static int selectRandom ( int x ) {\n count ++ ;\n if ( count == 1 ) res = x ;\n else {\n Random r = new Random ( ) ;\n int i = r . nextInt ( count ) ;\n if ( i == count - 1 ) res = x ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef selectRandom ( x ) :\n res = 0\n count = 0\n count += 1\n if ( count == 1 ) :\n res = x\n else :\n i = random.randrange ( count )\n if ( i == count - 1 ) :\n res = x\n return res\n\n"
},
{
"id": "python-java-A_PRODUCT_ARRAY_PUZZLE_1",
"pair": "python-java",
"Code1": "def productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n",
"Code2": "void productArray ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n System . out . print ( \"0\" ) ;\n return ;\n }\n int i , temp = 1 ;\n int prod [ ] = new int [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) prod [ j ] = 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n prod [ i ] = temp ;\n temp *= arr [ i ] ;\n }\n temp = 1 ;\n for ( i = n - 1 ;\n i >= 0 ;\n i -- ) {\n prod [ i ] *= temp ;\n temp *= arr [ i ] ;\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) System . out . print ( prod [ i ] + \" \" ) ;\n return ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef productArray ( arr , n ) :\n if n == 1 :\n print ( 0 )\n return\n i , temp = 1 , 1\n prod = [ 1 for i in range ( n ) ]\n for i in range ( n ) :\n prod [ i ] = temp\n temp *= arr [ i ]\n temp = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n prod [ i ] *= temp\n temp *= arr [ i ]\n for i in range ( n ) :\n print ( prod [ i ] , end = \" \" )\n return\n\n"
},
{
"id": "python-java-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS",
"pair": "python-java",
"Code1": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n",
"Code2": "static boolean sortedAfterSwap ( int A [ ] , boolean B [ ] , int n ) {\n int i , j ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] ) {\n j = i ;\n while ( B [ j ] ) {\n j ++ ;\n }\n Arrays . sort ( A , i , 1 + j ) ;\n i = j ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if ( B [ i ] == 1 ) :\n j = i\n while ( B [ j ] == 1 ) :\n j = j + 1\n A = A [ 0 : i ] + sorted ( A [ i : j + 1 ] ) + A [ j + 1 : ]\n i = j\n for i in range ( 0 , n ) :\n if ( A [ i ] != i + 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-FIND_THE_MAXIMUM_SUBARRAY_XOR_IN_A_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n",
"Code2": "static int maxSubarrayXOR ( int arr [ ] , int n ) {\n int ans = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_xor = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_xor = curr_xor ^ arr [ j ] ;\n ans = Math . max ( ans , curr_xor ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSubarrayXOR ( arr , n ) :\n ans = - 2147483648\n for i in range ( n ) :\n curr_xor = 0\n for j in range ( i , n ) :\n curr_xor = curr_xor ^ arr [ j ]\n ans = max ( ans , curr_xor )\n return ans\n\n"
},
{
"id": "python-java-MINIMUM_COST_MAKE_ARRAY_SIZE_1_REMOVING_LARGER_PAIRS",
"pair": "python-java",
"Code1": "def cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n",
"Code2": "static int cost ( int [ ] a , int n ) {\n int min = a [ 0 ] ;\n for ( int i = 1 ;\n i < a . length ;\n i ++ ) {\n if ( a [ i ] < min ) min = a [ i ] ;\n }\n return ( n - 1 ) * min ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef cost ( a , n ) :\n return ( ( n - 1 ) * min ( a ) )\n\n"
},
{
"id": "python-java-REMOVE_MINIMUM_ELEMENTS_EITHER_SIDE_2MIN_MAX",
"pair": "python-java",
"Code1": "def minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n",
"Code2": "static int minRemovalsDP ( int arr [ ] , int n ) {\n int longest_start = - 1 , longest_end = 0 ;\n for ( int start = 0 ;\n start < n ;\n start ++ ) {\n int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ;\n for ( int end = start ;\n end < n ;\n end ++ ) {\n int val = arr [ end ] ;\n if ( val < min ) {\n min = val ;\n }\n if ( val > max ) {\n max = val ;\n }\n if ( 2 * min <= max ) {\n break ;\n }\n if ( end - start > longest_end - longest_start || longest_start == - 1 ) {\n longest_start = start ;\n longest_end = end ;\n }\n }\n }\n if ( longest_start == - 1 ) {\n return n ;\n }\n return ( n - ( longest_end - longest_start + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRemovalsDP ( arr , n ) :\n longest_start = - 1\n longest_end = 0\n for start in range ( n ) :\n min = sys.maxsize\n max = - sys.maxsize\n for end in range ( start , n ) :\n val = arr [ end ]\n if ( val < min ) :\n min = val\n if ( val > max ) :\n max = val\n if ( 2 * min <= max ) :\n break\n if ( end - start > longest_end - longest_start or longest_start == - 1 ) :\n longest_start = start\n longest_end = end\n if ( longest_start == - 1 ) :\n return n\n return ( n - ( longest_end - longest_start + 1 ) )\n\n"
},
{
"id": "python-java-COUNT_INVERSIONS_OF_SIZE_THREE_IN_A_GIVE_ARRAY_1",
"pair": "python-java",
"Code1": "def getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n",
"Code2": "int getInvCount ( int arr [ ] , int n ) {\n int invcount = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n int small = 0 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] > arr [ j ] ) small ++ ;\n int great = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) if ( arr [ i ] < arr [ j ] ) great ++ ;\n invcount += great * small ;\n }\n return invcount ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getInvCount ( arr , n ) :\n invcount = 0\n for i in range ( 1 , n - 1 ) :\n small = 0\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] > arr [ j ] ) :\n small += 1\n great = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( arr [ i ] < arr [ j ] ) :\n great += 1\n invcount += great * small\n return invcount\n\n"
},
{
"id": "python-java-PROGRAM_FOR_SURFACE_AREA_OF_OCTAHEDRON",
"pair": "python-java",
"Code1": "def surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n",
"Code2": "static double surface_area_octahedron ( double side ) {\n return ( 2 * ( Math . sqrt ( 3 ) ) * ( side * side ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef surface_area_octahedron ( side ) :\n return ( 2 * ( math.sqrt ( 3 ) ) * ( side * side ) )\n\n"
},
{
"id": "python-java-GNOME_SORT_A_STUPID_ONE",
"pair": "python-java",
"Code1": "def gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n",
"Code2": "static void gnomeSort ( int arr [ ] , int n ) {\n int index = 0 ;\n while ( index < n ) {\n if ( index == 0 ) index ++ ;\n if ( arr [ index ] >= arr [ index - 1 ] ) index ++ ;\n else {\n int temp = 0 ;\n temp = arr [ index ] ;\n arr [ index ] = arr [ index - 1 ] ;\n arr [ index - 1 ] = temp ;\n index -- ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef gnomeSort ( arr , n ) :\n index = 0\n while index < n :\n if index == 0 :\n index = index + 1\n if arr [ index ] >= arr [ index - 1 ] :\n index = index + 1\n else :\n arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]\n index = index - 1\n return arr\n\n"
},
{
"id": "python-java-COUNT_FREQUENCY_K_MATRIX_SIZE_N_MATRIXI_J_IJ",
"pair": "python-java",
"Code1": "def find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n",
"Code2": "public static int find ( int n , int k ) {\n if ( n + 1 >= k ) return ( k - 1 ) ;\n else return ( 2 * n + 1 - k ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find ( n , k ) :\n if ( n + 1 >= k ) :\n return ( k - 1 )\n else :\n return ( 2 * n + 1 - k )\n\n"
},
{
"id": "python-java-UNIQUE_CELLS_BINARY_MATRIX",
"pair": "python-java",
"Code1": "def countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n",
"Code2": "static int countUnique ( int mat [ ] [ ] , int n , int m ) {\n int [ ] rowsum = new int [ n ] ;\n int [ ] colsum = new int [ m ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 ) {\n rowsum [ i ] ++ ;\n colsum [ j ] ++ ;\n }\n int uniquecount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( mat [ i ] [ j ] != 0 && rowsum [ i ] == 1 && colsum [ j ] == 1 ) uniquecount ++ ;\n return uniquecount ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countUnique ( mat , n , m ) :\n rowsum = [ 0 ] * n\n colsum = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 ) :\n rowsum [ i ] += 1\n colsum [ j ] += 1\n uniquecount = 0\n for i in range ( n ) :\n for j in range ( m ) :\n if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :\n uniquecount += 1\n return uniquecount\n\n"
},
{
"id": "python-java-GENERATE_BINARY_PERMUTATIONS_1S_0S_EVERY_POINT_PERMUTATIONS",
"pair": "python-java",
"Code1": "def generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n",
"Code2": "static void generate ( int ones , int zeroes , String str , int len ) {\n if ( len == str . length ( ) ) {\n System . out . print ( str + \" \" ) ;\n return ;\n }\n generate ( ones + 1 , zeroes , str + \"1\" , len ) ;\n if ( ones > zeroes ) {\n generate ( ones , zeroes + 1 , str + \"0\" , len ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef generate ( ones , zeroes , str , len1 ) :\n if ( len1 == len ( str ) ) :\n print ( str , end = \" \" )\n return\n generate ( ones + 1 , zeroes , str + \"1\" , len1 )\n if ( ones > zeroes ) :\n generate ( ones , zeroes + 1 , str + \"0\" , len1 )\n\n"
},
{
"id": "python-java-MID_POINT_CIRCLE_DRAWING_ALGORITHM",
"pair": "python-java",
"Code1": "def midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n",
"Code2": "static void midPointCircleDraw ( int x_centre , int y_centre , int r ) {\n int x = r , y = 0 ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n if ( r > 0 ) {\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n }\n int P = 1 - r ;\n while ( x > y ) {\n y ++ ;\n if ( P <= 0 ) P = P + 2 * y + 1 ;\n else {\n x -- ;\n P = P + 2 * y - 2 * x + 1 ;\n }\n if ( x < y ) break ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - x + x_centre ) + \", \" + ( y + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - x + x_centre ) + \", \" + ( - y + y_centre ) + \")\" ) ;\n if ( x != y ) {\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( - y + x_centre ) + \", \" + ( x + y_centre ) + \")\" ) ;\n System . out . print ( \"(\" + ( y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n System . out . println ( \"(\" + ( - y + x_centre ) + \", \" + ( - x + y_centre ) + \")\" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef midPointCircleDraw ( x_centre , y_centre , r ) :\n x = r\n y = 0\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n if ( r > 0 ) :\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" )\n P = 1 - r\n while ( x > y ) :\n y += 1\n if ( P <= 0 ) :\n P = P + 2 * y + 1\n else :\n x -= 1\n P = P + 2 * y - 2 * x + 1\n if ( x < y ) :\n break\n print ( \"(\" , x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - x + x_centre , \", \" , - y + y_centre , \")\" , sep = \"\" )\n if ( x != y ) :\n print ( \"(\" , y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" , end = \"\" )\n print ( \"(\" , - y + x_centre , \", \" , - x + y_centre , \")\" , sep = \"\" )\n\n"
},
{
"id": "python-java-FIND_FACTORIAL_NUMBERS_LESS_EQUAL_N",
"pair": "python-java",
"Code1": "def printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n",
"Code2": "static void printFactorialNums ( int n ) {\n int fact = 1 ;\n int x = 2 ;\n while ( fact <= n ) {\n System . out . print ( fact + \" \" ) ;\n fact = fact * x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printFactorialNums ( n ) :\n fact = 1\n x = 2\n while fact <= n :\n print ( fact , end = \" \" )\n fact = fact * x\n x += 1\n\n"
},
{
"id": "python-java-FRIENDS_PAIRING_PROBLEM",
"pair": "python-java",
"Code1": "def countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n",
"Code2": "static int countFriendsPairings ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i <= 2 ) dp [ i ] = i ;\n else dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n dp = [ 0 for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n if ( i <= 2 ) :\n dp [ i ] = i\n else :\n dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ]\n return dp [ n ]\n\n"
},
{
"id": "python-java-PROGRAM_FIND_REMAINDER_LARGE_NUMBER_DIVIDED_11",
"pair": "python-java",
"Code1": "def remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n",
"Code2": "static int remainder ( String str ) {\n int len = str . length ( ) ;\n int num , rem = 0 ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n num = rem * 10 + ( str . charAt ( i ) - ' 0 ' ) ;\n rem = num % 11 ;\n }\n return rem ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef remainder ( st ) :\n ln = len ( st )\n rem = 0\n for i in range ( 0 , ln ) :\n num = rem * 10 + ( int ) ( st [ i ] )\n rem = num % 11\n return rem\n\n"
},
{
"id": "python-java-N_TH_NUMBER_WHOSE_SUM_OF_DIGITS_IS_TEN",
"pair": "python-java",
"Code1": "def findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n",
"Code2": "public static int findNth ( int n ) {\n int count = 0 ;\n for ( int curr = 1 ;\n ;\n curr ++ ) {\n int sum = 0 ;\n for ( int x = curr ;\n x > 0 ;\n x = x / 10 ) sum = sum + x % 10 ;\n if ( sum == 10 ) count ++ ;\n if ( count == n ) return curr ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findNth ( n ) :\n count = 0\n for curr in itertools.count ( ) :\n sum = 0\n x = curr\n while ( x ) :\n sum = sum + x % 10\n x = x // 10\n if ( sum == 10 ) :\n count = count + 1\n if ( count == n ) :\n return curr\n return - 1\n\n"
},
{
"id": "python-java-SORT_1_N_SWAPPING_ADJACENT_ELEMENTS_1",
"pair": "python-java",
"Code1": "def sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n",
"Code2": "static int sortedAfterSwap ( int [ ] A , int [ ] B , int n ) {\n int t = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( B [ i ] != 0 ) {\n if ( A [ i ] != i + 1 ) t = A [ i ] ;\n A [ i ] = A [ i + 1 ] ;\n A [ i + 1 ] = t ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( A [ i ] != i + 1 ) return 0 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortedAfterSwap ( A , B , n ) :\n for i in range ( 0 , n - 1 ) :\n if B [ i ] :\n if A [ i ] != i + 1 :\n A [ i ] , A [ i + 1 ] = A [ i + 1 ] , A [ i ]\n for i in range ( n ) :\n if A [ i ] != i + 1 :\n return False\n return True\n\n"
},
{
"id": "python-java-MAXIMIZE_ARRAY_SUN_AFTER_K_NEGATION_OPERATIONS",
"pair": "python-java",
"Code1": "def maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n",
"Code2": "static int maximumSum ( int arr [ ] , int n , int k ) {\n for ( int i = 1 ;\n i <= k ;\n i ++ ) {\n int min = + 2147483647 ;\n int index = - 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < min ) {\n min = arr [ j ] ;\n index = j ;\n }\n }\n if ( min == 0 ) break ;\n arr [ index ] = - arr [ index ] ;\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumSum ( arr , n , k ) :\n for i in range ( 1 , k + 1 ) :\n min = + 2147483647\n index = - 1\n for j in range ( n ) :\n if ( arr [ j ] < min ) :\n min = arr [ j ]\n index = j\n if ( min == 0 ) :\n break\n arr [ index ] = - arr [ index ]\n sum = 0\n for i in range ( n ) :\n sum += arr [ i ]\n return sum\n\n"
},
{
"id": "python-java-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING_1",
"pair": "python-java",
"Code1": "def printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n",
"Code2": "static void printSquares ( int n ) {\n int square = 0 , odd = 1 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n System . out . print ( square + \" \" ) ;\n square = square + odd ;\n odd = odd + 2 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSquares ( n ) :\n square = 0\n odd = 1\n for x in range ( 0 , n ) :\n print ( square , end = \" \" )\n square = square + odd\n odd = odd + 2\n\n"
},
{
"id": "python-java-CHECK_REVERSING_SUB_ARRAY_MAKE_ARRAY_SORTED_1",
"pair": "python-java",
"Code1": "def checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n",
"Code2": "static boolean checkReverse ( int arr [ ] , int n ) {\n if ( n == 1 ) {\n return true ;\n }\n int i ;\n for ( i = 1 ;\n arr [ i - 1 ] < arr [ i ] && i < n ;\n i ++ ) ;\n if ( i == n ) {\n return true ;\n }\n int j = i ++ ;\n while ( arr [ j ] < arr [ j - 1 ] ) {\n if ( i > 1 && arr [ j ] < arr [ i - 2 ] ) {\n return false ;\n }\n j ++ ;\n }\n if ( j == n ) {\n return true ;\n }\n int k = j ;\n if ( arr [ k ] < arr [ i - 1 ] ) {\n return false ;\n }\n while ( k > 1 && k < n ) {\n if ( arr [ k ] < arr [ k - 1 ] ) {\n return false ;\n }\n k ++ ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkReverse ( arr , n ) :\n if ( n == 1 ) :\n return True\n i = 1\n for i in range ( 1 , n ) :\n if arr [ i - 1 ] < arr [ i ] :\n if ( i == n ) :\n return True\n j = i\n while ( arr [ j ] < arr [ j - 1 ] ) :\n if ( i > 1 and arr [ j ] < arr [ i - 2 ] ) :\n return False\n j += 1\n if ( j == n ) :\n return True\n k = j\n if ( arr [ k ] < arr [ i - 1 ] ) :\n return False\n while ( k > 1 and k < n ) :\n if ( arr [ k ] < arr [ k - 1 ] ) :\n return False\n k += 1\n return True\n\n"
},
{
"id": "python-java-PROGRAM_CALCULATE_VOLUME_OCTAHEDRON",
"pair": "python-java",
"Code1": "def vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n",
"Code2": "static double vol_of_octahedron ( double side ) {\n return ( ( side * side * side ) * ( Math . sqrt ( 2 ) / 3 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef vol_of_octahedron ( side ) :\n return ( ( side * side * side ) * ( math.sqrt ( 2 ) / 3 ) )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX",
"pair": "python-java",
"Code1": "def numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n if ( m == 1 || n == 1 ) return 1 ;\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n if ( m == 1 or n == 1 ) :\n return 1\n return numberOfPaths ( m - 1 , n ) + numberOfPaths ( m , n - 1 )\n\n"
},
{
"id": "python-java-BINARY_SEARCH",
"pair": "python-java",
"Code1": "def binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 1 , x ) ;\n return binarySearch ( arr , mid + 1 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n if r >= l :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] > x :\n return binarySearch ( arr , l , mid - 1 , x )\n else :\n return binarySearch ( arr , mid + 1 , r , x )\n else :\n return - 1\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_1",
"pair": "python-java",
"Code1": "def numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int count [ ] [ ] = new int [ m ] [ n ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) count [ i ] [ 0 ] = 1 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) count [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ] ;\n }\n return count [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n count = [ [ 0 for x in range ( m ) ] for y in range ( n ) ]\n for i in range ( m ) :\n count [ i ] [ 0 ] = 1 ;\n for j in range ( n ) :\n count [ 0 ] [ j ] = 1 ;\n for i in range ( 1 , m ) :\n for j in range ( n ) :\n count [ i ] [ j ] = count [ i - 1 ] [ j ] + count [ i ] [ j - 1 ]\n return count [ m - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-NUMBER_N_DIGIT_STEPPING_NUMBERS",
"pair": "python-java",
"Code1": "def answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n",
"Code2": "static long answer ( int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ 10 ] ;\n if ( n == 1 ) return 10 ;\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) dp [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= 9 ;\n j ++ ) {\n if ( j == 0 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ] ;\n else if ( j == 9 ) dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] ;\n }\n }\n long sum = 0 ;\n for ( int j = 1 ;\n j <= 9 ;\n j ++ ) sum += dp [ n ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef answer ( n ) :\n dp = [ [ 0 for x in range ( 10 ) ] for y in range ( n + 1 ) ]\n if ( n == 1 ) :\n return 10\n for j in range ( 10 ) :\n dp [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 10 ) :\n if ( j == 0 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j + 1 ]\n elif ( j == 9 ) :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 1 ] [ j + 1 ] )\n sum = 0\n for j in range ( 1 , 10 ) :\n sum = sum + dp [ n ] [ j ]\n return sum\n\n"
},
{
"id": "python-java-PARTITION_INTO_TWO_SUBARRAYS_OF_LENGTHS_K_AND_N_K_SUCH_THAT_THE_DIFFERENCE_OF_SUMS_IS_MAXIMUM",
"pair": "python-java",
"Code1": "def maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n",
"Code2": "static int maxDifference ( int arr [ ] , int N , int k ) {\n int M , S = 0 , S1 = 0 , max_difference = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) S += arr [ i ] ;\n int temp ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < N ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n }\n M = Math . max ( k , N - k ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) S1 += arr [ i ] ;\n max_difference = S1 - ( S - S1 ) ;\n return max_difference ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxDifference ( arr , N , k ) :\n S = 0\n S1 = 0\n max_difference = 0\n for i in range ( N ) :\n S += arr [ i ]\n arr.sort ( reverse = True )\n M = max ( k , N - k )\n for i in range ( M ) :\n S1 += arr [ i ]\n max_difference = S1 - ( S - S1 )\n return max_difference\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_SUBARRAY_REMOVING_ONE_ELEMENT",
"pair": "python-java",
"Code1": "def maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n",
"Code2": "static int maxSumSubarrayRemovingOneEle ( int arr [ ] , int n ) {\n int fw [ ] = new int [ n ] ;\n int bw [ ] = new int [ n ] ;\n int cur_max = arr [ 0 ] , max_so_far = arr [ 0 ] ;\n fw [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n fw [ i ] = cur_max ;\n }\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n cur_max = Math . max ( arr [ i ] , cur_max + arr [ i ] ) ;\n max_so_far = Math . max ( max_so_far , cur_max ) ;\n bw [ i ] = cur_max ;\n }\n int fans = max_so_far ;\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) fans = Math . max ( fans , fw [ i - 1 ] + bw [ i + 1 ] ) ;\n return fans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumSubarrayRemovingOneEle ( arr , n ) :\n fw = [ 0 for k in range ( n ) ]\n bw = [ 0 for k in range ( n ) ]\n cur_max , max_so_far = arr [ 0 ] , arr [ 0 ]\n for i in range ( n ) :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n fw [ i ] = cur_max\n cur_max = max_so_far = bw [ n - 1 ] = arr [ n - 1 ]\n i = n - 2\n while i >= 0 :\n cur_max = max ( arr [ i ] , cur_max + arr [ i ] )\n max_so_far = max ( max_so_far , cur_max )\n bw [ i ] = cur_max\n i -= 1\n fans = max_so_far\n for i in range ( 1 , n - 1 ) :\n fans = max ( fans , fw [ i - 1 ] + bw [ i + 1 ] )\n return fans\n\n"
},
{
"id": "python-java-MOVE_SPACES_FRONT_STRING_SINGLE_TRAVERSAL",
"pair": "python-java",
"Code1": "def moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n",
"Code2": "static void moveSpaceInFront ( char str [ ] ) {\n int i = str . length - 1 ;\n for ( int j = i ;\n j >= 0 ;\n j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ;\n while ( i >= 0 ) str [ i -- ] = ' ▁ ' ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef moveSpaceInFront ( s ) :\n i = len ( s ) - 1\n for j in range ( i , - 1 , - 1 ) :\n if ( s [ j ] != ' ' ) :\n s = s [ : i ] + s [ j ] + s [ i + 1 : ]\n i -= 1\n while ( i >= 0 ) :\n s = s [ : i ] + ' ' + s [ i + 1 : ]\n i -= 1\n return s\n\n"
},
{
"id": "python-java-RECAMANS_SEQUENCE",
"pair": "python-java",
"Code1": "def recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n",
"Code2": "static void recaman ( int n ) {\n int arr [ ] = new int [ n ] ;\n arr [ 0 ] = 0 ;\n System . out . print ( arr [ 0 ] + \" ,\" ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int curr = arr [ i - 1 ] - i ;\n int j ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( ( arr [ j ] == curr ) || curr < 0 ) {\n curr = arr [ i - 1 ] + i ;\n break ;\n }\n }\n arr [ i ] = curr ;\n System . out . print ( arr [ i ] + \", \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef recaman ( n ) :\n arr = [ 0 ] * n\n arr [ 0 ] = 0\n print ( arr [ 0 ] , end = \", \" )\n for i in range ( 1 , n ) :\n curr = arr [ i - 1 ] - i\n for j in range ( 0 , i ) :\n if ( ( arr [ j ] == curr ) or curr < 0 ) :\n curr = arr [ i - 1 ] + i\n break\n arr [ i ] = curr\n print ( arr [ i ] , end = \", \" )\n\n"
},
{
"id": "python-java-MAXIMUM_POINTS_COLLECTED_BY_TWO_PERSONS_ALLOWED_TO_MEET_ONCE",
"pair": "python-java",
"Code1": "def findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n",
"Code2": "static int findMaxPoints ( int A [ ] [ ] ) {\n int [ ] [ ] P1S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P1E = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2S = new int [ M + 2 ] [ N + 2 ] ;\n int [ ] [ ] P2E = new int [ M + 2 ] [ N + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P1S [ i ] [ j ] = Math . max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = M ;\n j >= 1 ;\n j -- ) P1E [ i ] [ j ] = Math . max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) for ( int j = 1 ;\n j <= M ;\n j ++ ) P2S [ i ] [ j ] = Math . max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = M ;\n j >= 1 ;\n j -- ) P2E [ i ] [ j ] = Math . max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ] ;\n int ans = 0 ;\n for ( int i = 2 ;\n i < N ;\n i ++ ) {\n for ( int j = 2 ;\n j < M ;\n j ++ ) {\n int op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ] ;\n int op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ] ;\n ans = Math . max ( ans , Math . max ( op1 , op2 ) ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxPoints ( A ) :\n P1S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P1E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2S = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n P2E = [ [ 0 for i in range ( N + 2 ) ] for j in range ( M + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n P1S [ i ] [ j ] = max ( P1S [ i - 1 ] [ j ] , P1S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P1E [ i ] [ j ] = max ( P1E [ i + 1 ] [ j ] , P1E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( 1 , M + 1 ) :\n P2S [ i ] [ j ] = max ( P2S [ i + 1 ] [ j ] , P2S [ i ] [ j - 1 ] ) + A [ i - 1 ] [ j - 1 ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( M , 0 , - 1 ) :\n P2E [ i ] [ j ] = max ( P2E [ i - 1 ] [ j ] , P2E [ i ] [ j + 1 ] ) + A [ i - 1 ] [ j - 1 ]\n ans = 0\n for i in range ( 2 , N ) :\n for j in range ( 2 , M ) :\n op1 = P1S [ i ] [ j - 1 ] + P1E [ i ] [ j + 1 ] + \\\n P2S [ i + 1 ] [ j ] + P2E [ i - 1 ] [ j ]\n op2 = P1S [ i - 1 ] [ j ] + P1E [ i + 1 ] [ j ] + \\\n P2S [ i ] [ j - 1 ] + P2E [ i ] [ j + 1 ]\n ans = max ( ans , max ( op1 , op2 ) )\n return ans\n\n"
},
{
"id": "python-java-SPACE_OPTIMIZED_DP_SOLUTION_0_1_KNAPSACK_PROBLEM",
"pair": "python-java",
"Code1": "def KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n",
"Code2": "static int KnapSack ( int val [ ] , int wt [ ] , int n , int W ) {\n int mat [ ] [ ] = new int [ 2 ] [ W + 1 ] ;\n int i = 0 ;\n while ( i < n ) {\n int j = 0 ;\n if ( i % 2 != 0 ) {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 1 ] [ j ] = Math . max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] ) ;\n }\n else {\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ] ;\n }\n }\n }\n else {\n while ( ++ j <= W ) {\n if ( wt [ i ] <= j ) {\n mat [ 0 ] [ j ] = Math . max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] ) ;\n }\n else {\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ] ;\n }\n }\n }\n i ++ ;\n }\n return ( n % 2 != 0 ) ? mat [ 0 ] [ W ] : mat [ 1 ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef KnapSack ( val , wt , n , W ) :\n mat = [ [ 0 for i in range ( W + 1 ) ] for i in range ( 2 ) ]\n i = 0\n while i < n :\n j = 0\n if i % 2 == 0 :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 1 ] [ j ] = max ( val [ i ] + mat [ 0 ] [ j - wt [ i ] ] , mat [ 0 ] [ j ] )\n else :\n mat [ 1 ] [ j ] = mat [ 0 ] [ j ]\n else :\n while j < W :\n j += 1\n if wt [ i ] <= j :\n mat [ 0 ] [ j ] = max ( val [ i ] + mat [ 1 ] [ j - wt [ i ] ] , mat [ 1 ] [ j ] )\n else :\n mat [ 0 ] [ j ] = mat [ 1 ] [ j ]\n i += 1\n if n % 2 == 0 :\n return mat [ 0 ] [ W ]\n else :\n return mat [ 1 ] [ W ]\n\n"
},
{
"id": "python-java-MULTIPLICATIVE_INVERSE_UNDER_MODULO_M",
"pair": "python-java",
"Code1": "def modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n",
"Code2": "static int modInverse ( int a , int m ) {\n a = a % m ;\n for ( int x = 1 ;\n x < m ;\n x ++ ) if ( ( a * x ) % m == 1 ) return x ;\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef modInverse ( a , m ) :\n a = a % m\n for x in range ( 1 , m ) :\n if ( ( a * x ) % m == 1 ) :\n return x\n return 1\n\n"
},
{
"id": "python-java-LENGTH_OF_THE_LONGEST_ARITHMATIC_PROGRESSION_IN_A_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n",
"Code2": "static int lenghtOfLongestAP ( int set [ ] , int n ) {\n if ( n <= 2 ) return n ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llap = 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ n - 1 ] = 2 ;\n for ( int j = n - 2 ;\n j >= 1 ;\n j -- ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ;\n else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n llap = Math . max ( llap , L [ i ] [ j ] ) ;\n i -- ;\n k ++ ;\n }\n }\n while ( i >= 0 ) {\n L [ i ] [ j ] = 2 ;\n i -- ;\n }\n }\n return llap ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lenghtOfLongestAP ( set , n ) :\n if ( n <= 2 ) :\n return n\n L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n llap = 2\n for i in range ( n ) :\n L [ i ] [ n - 1 ] = 2\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while ( i >= 0 and k <= n - 1 ) :\n if ( set [ i ] + set [ k ] < 2 * set [ j ] ) :\n k += 1\n elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) :\n L [ i ] [ j ] = 2\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n llap = max ( llap , L [ i ] [ j ] )\n i -= 1\n k += 1\n while ( i >= 0 ) :\n L [ i ] [ j ] = 2\n i -= 1\n return llap\n\n"
},
{
"id": "python-java-COUNT_BINARY_DIGIT_NUMBERS_SMALLER_N",
"pair": "python-java",
"Code1": "def countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n",
"Code2": "static int countOfBinaryNumberLessThanN ( int N ) {\n Queue < Integer > q = new LinkedList < > ( ) ;\n q . add ( 1 ) ;\n int cnt = 0 ;\n int t ;\n while ( q . size ( ) > 0 ) {\n t = q . peek ( ) ;\n q . remove ( ) ;\n if ( t <= N ) {\n cnt ++ ;\n q . add ( t * 10 ) ;\n q . add ( t * 10 + 1 ) ;\n }\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOfBinaryNumberLessThanN ( N ) :\n q = deque ( )\n q.append ( 1 )\n cnt = 0\n while ( q ) :\n t = q.popleft ( )\n if ( t <= N ) :\n cnt = cnt + 1\n q.append ( t * 10 )\n q.append ( t * 10 + 1 )\n return cnt\n\n"
},
{
"id": "python-java-FIND_INDEX_GIVEN_FIBONACCI_NUMBER_CONSTANT_TIME",
"pair": "python-java",
"Code1": "def findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n",
"Code2": "static int findIndex ( int n ) {\n if ( n <= 1 ) return n ;\n int a = 0 , b = 1 , c = 1 ;\n int res = 1 ;\n while ( c < n ) {\n c = a + b ;\n res ++ ;\n a = b ;\n b = c ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findIndex ( n ) :\n if ( n <= 1 ) :\n return n\n a = 0\n b = 1\n c = 1\n res = 1\n while ( c < n ) :\n c = a + b\n res = res + 1\n a = b\n b = c\n return res\n\n"
},
{
"id": "python-java-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL_1",
"pair": "python-java",
"Code1": "def substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n",
"Code2": "static void substringConversions ( String str , int k , int b ) {\n int i = 0 , sum = 0 , counter = k - 1 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n sum = ( int ) ( sum + ( ( str . charAt ( i ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter -- ;\n }\n System . out . print ( sum + \" \" ) ;\n int prev = sum ;\n sum = 0 ;\n counter = 0 ;\n for ( ;\n i < str . length ( ) ;\n i ++ ) {\n sum = ( int ) ( prev - ( ( str . charAt ( i - k ) - ' 0 ' ) * Math . pow ( b , k - 1 ) ) ) ;\n sum = sum * b ;\n sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n System . out . print ( sum + \" \" ) ;\n prev = sum ;\n counter ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef substringConversions ( str1 , k , b ) :\n for i in range ( 0 , len ( str1 ) - k + 1 ) :\n sub = str1 [ i : k + i ]\n Sum = 0\n counter = 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n Sum = ( Sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) ) )\n counter += 1\n print ( Sum , end = \" \" )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_PAIRS_SPECIFIC_DIFFERENCE_1",
"pair": "python-java",
"Code1": "def maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n",
"Code2": "static int maxSumPairWithDifferenceLessThanK ( int arr [ ] , int N , int k ) {\n int maxSum = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = N - 1 ;\n i > 0 ;\n -- i ) {\n if ( arr [ i ] - arr [ i - 1 ] < k ) {\n maxSum += arr [ i ] ;\n maxSum += arr [ i - 1 ] ;\n -- i ;\n }\n }\n return maxSum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumPairWithDifferenceLessThanK ( arr , N , k ) :\n maxSum = 0\n arr.sort ( )\n i = N - 1\n while ( i >= 0 ) :\n if ( arr [ i ] - arr [ i - 1 ] < k ) :\n maxSum += arr [ i ]\n maxSum += arr [ i - 1 ]\n i -= 1\n i -= 1\n return maxSum\n\n"
},
{
"id": "python-java-LONGEST_REPEATED_SUBSEQUENCE_1",
"pair": "python-java",
"Code1": "def longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n",
"Code2": "static String longestRepeatedSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= n ;\n j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n String res = \"\" ;\n int i = n , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) {\n res = res + str . charAt ( i - 1 ) ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ;\n else j -- ;\n }\n String reverse = \"\" ;\n for ( int k = res . length ( ) - 1 ;\n k >= 0 ;\n k -- ) {\n reverse = reverse + res . charAt ( k ) ;\n }\n return reverse ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestRepeatedSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n res = ''\n i = n\n j = n\n while ( i > 0 and j > 0 ) :\n if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) :\n res += str [ i - 1 ]\n i -= 1\n j -= 1\n elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) :\n i -= 1\n else :\n j -= 1\n res = ''.join ( reversed ( res ) )\n return res\n\n"
},
{
"id": "python-java-HOW_TO_CHECK_IF_A_GIVEN_ARRAY_REPRESENTS_A_BINARY_HEAP_1",
"pair": "python-java",
"Code1": "def isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "static boolean isHeap ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i <= ( n - 2 ) / 2 ;\n i ++ ) {\n if ( arr [ 2 * i + 1 ] > arr [ i ] ) {\n return false ;\n }\n if ( 2 * i + 2 < n && arr [ 2 * i + 2 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isHeap ( arr , n ) :\n for i in range ( int ( ( n - 2 ) / 2 ) + 1 ) :\n if arr [ 2 * i + 1 ] > arr [ i ] :\n return False\n if ( 2 * i + 2 < n and arr [ 2 * i + 2 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-java-MINIMUM_COST_SORT_MATRIX_NUMBERS_0_N2_1",
"pair": "python-java",
"Code1": "def calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n",
"Code2": "public static int calculateEnergy ( int mat [ ] [ ] , int n ) {\n int i_des , j_des , q ;\n int tot_energy = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n q = mat [ i ] [ j ] / n ;\n i_des = q ;\n j_des = mat [ i ] [ j ] - ( n * q ) ;\n tot_energy += Math . abs ( i_des - i ) + Math . abs ( j_des - j ) ;\n }\n }\n return tot_energy ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calculateEnergy ( mat , n ) :\n tot_energy = 0\n for i in range ( n ) :\n for j in range ( n ) :\n q = mat [ i ] [ j ] // n\n i_des = q\n j_des = mat [ i ] [ j ] - ( n * q )\n tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )\n return tot_energy\n\n"
},
{
"id": "python-java-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS",
"pair": "python-java",
"Code1": "def rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n",
"Code2": "static void rearrange ( int a [ ] , int size ) {\n int positive = 0 , negative = 1 , temp ;\n while ( true ) {\n while ( positive < size && a [ positive ] >= 0 ) positive += 2 ;\n while ( negative < size && a [ negative ] <= 0 ) negative += 2 ;\n if ( positive < size && negative < size ) {\n temp = a [ positive ] ;\n a [ positive ] = a [ negative ] ;\n a [ negative ] = temp ;\n }\n else break ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rearrange ( a , size ) :\n positive = 0\n negative = 1\n while ( True ) :\n while ( positive < size and a [ positive ] >= 0 ) :\n positive = positive + 2\n while ( negative < size and a [ negative ] <= 0 ) :\n negative = negative + 2\n if ( positive < size and negative < size ) :\n temp = a [ positive ]\n a [ positive ] = a [ negative ]\n a [ negative ] = temp\n else :\n break\n\n"
},
{
"id": "python-java-PRINT_MATRIX_ANTISPIRAL_FORM",
"pair": "python-java",
"Code1": "def antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n",
"Code2": "public static void antiSpiralTraversal ( int m , int n , int a [ ] [ ] ) {\n int i , k = 0 , l = 0 ;\n Stack < Integer > stk = new Stack < Integer > ( ) ;\n while ( k <= m && l <= n ) {\n for ( i = l ;\n i <= n ;\n ++ i ) stk . push ( a [ k ] [ i ] ) ;\n k ++ ;\n for ( i = k ;\n i <= m ;\n ++ i ) stk . push ( a [ i ] [ n ] ) ;\n n -- ;\n if ( k <= m ) {\n for ( i = n ;\n i >= l ;\n -- i ) stk . push ( a [ m ] [ i ] ) ;\n m -- ;\n }\n if ( l <= n ) {\n for ( i = m ;\n i >= k ;\n -- i ) stk . push ( a [ i ] [ l ] ) ;\n l ++ ;\n }\n }\n while ( ! stk . empty ( ) ) {\n System . out . print ( stk . peek ( ) + \" \" ) ;\n stk . pop ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef antiSpiralTraversal ( m , n , a ) :\n k = 0\n l = 0\n stk = [ ]\n while ( k <= m and l <= n ) :\n for i in range ( l , n + 1 ) :\n stk.append ( a [ k ] [ i ] )\n k += 1\n for i in range ( k , m + 1 ) :\n stk.append ( a [ i ] [ n ] )\n n -= 1\n if ( k <= m ) :\n for i in range ( n , l - 1 , - 1 ) :\n stk.append ( a [ m ] [ i ] )\n m -= 1\n if ( l <= n ) :\n for i in range ( m , k - 1 , - 1 ) :\n stk.append ( a [ i ] [ l ] )\n l += 1\n while len ( stk ) != 0 :\n print ( str ( stk [ - 1 ] ) , end = \" \" )\n stk.pop ( )\n\n"
},
{
"id": "python-java-RETURN_A_PAIR_WITH_MAXIMUM_PRODUCT_IN_ARRAY_OF_INTEGERS_1",
"pair": "python-java",
"Code1": "def maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n",
"Code2": "static void maxProduct ( int arr [ ] , int n ) {\n if ( n < 2 ) {\n System . out . println ( \"No pairs exists\" ) ;\n return ;\n }\n if ( n == 2 ) {\n System . out . println ( arr [ 0 ] + \" \" + arr [ 1 ] ) ;\n return ;\n }\n int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ;\n int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] > posa ) {\n posb = posa ;\n posa = arr [ i ] ;\n }\n else if ( arr [ i ] > posb ) posb = arr [ i ] ;\n if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) {\n negb = nega ;\n nega = arr [ i ] ;\n }\n else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ;\n }\n if ( nega * negb > posa * posb ) System . out . println ( \"Max product pair is {\" + nega + \", \" + negb + \"}\" ) ;\n else System . out . println ( \"Max product pair is {\" + posa + \", \" + posb + \"}\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if ( n < 2 ) :\n print ( \"No pairs exists\" )\n return\n if ( n == 2 ) :\n print ( arr [ 0 ] , \" \" , arr [ 1 ] )\n return\n posa = 0\n posb = 0\n nega = 0\n negb = 0\n for i in range ( n ) :\n if ( arr [ i ] > posa ) :\n posb = posa\n posa = arr [ i ]\n elif ( arr [ i ] > posb ) :\n posb = arr [ i ]\n if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) :\n negb = nega\n nega = arr [ i ]\n elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) :\n negb = arr [ i ]\n if ( nega * negb > posa * posb ) :\n print ( \"Max product pair is {\" , nega , \", \" , negb , \"}\" )\n else :\n print ( \"Max product pair is {\" , posa , \", \" , posb , \"}\" )\n\n"
},
{
"id": "python-java-MAXIMIZE_ARRAY_ELEMENTS_UPTO_GIVEN_NUMBER",
"pair": "python-java",
"Code1": "def findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n",
"Code2": "static int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) {\n int ind ;\n int val ;\n int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ;\n for ( ind = 0 ;\n ind < n ;\n ind ++ ) {\n for ( val = 0 ;\n val <= maxLimit ;\n val ++ ) {\n if ( ind == 0 ) {\n if ( num - arr [ ind ] == val || num + arr [ ind ] == val ) {\n dp [ ind ] [ val ] = 1 ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n else {\n if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) {\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 || dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ;\n }\n else if ( val - arr [ ind ] >= 0 ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;\n }\n else if ( val + arr [ ind ] <= maxLimit ) {\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;\n }\n else {\n dp [ ind ] [ val ] = 0 ;\n }\n }\n }\n }\n for ( val = maxLimit ;\n val >= 0 ;\n val -- ) {\n if ( dp [ n - 1 ] [ val ] == 1 ) {\n return val ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxVal ( arr , n , num , maxLimit ) :\n ind = - 1\n val = - 1\n dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ]\n for ind in range ( n ) :\n for val in range ( maxLimit + 1 ) :\n if ( ind == 0 ) :\n if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :\n dp [ ind ] [ val ] = 1\n else :\n dp [ ind ] [ val ] = 0\n else :\n if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :\n if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :\n dp [ ind ] [ val ] = 1\n elif ( val - arr [ ind ] >= 0 ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ]\n elif ( val + arr [ ind ] <= maxLimit ) :\n dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ]\n else :\n dp [ ind ] [ val ] = 0\n for val in range ( maxLimit , - 1 , - 1 ) :\n if ( dp [ n - 1 ] [ val ] == 1 ) :\n return val\n return - 1\n\n"
},
{
"id": "python-java-PROGRAM_FOR_DEADLOCK_FREE_CONDITION_IN_OPERATING_SYSTEM",
"pair": "python-java",
"Code1": "def Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n",
"Code2": "static int Resources ( int process , int need ) {\n int minResources = 0 ;\n minResources = process * ( need - 1 ) + 1 ;\n return minResources ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef Resources ( process , need ) :\n minResources = 0\n minResources = process * ( need - 1 ) + 1\n return minResources\n\n"
},
{
"id": "python-java-BUBBLE_SORT",
"pair": "python-java",
"Code1": "def bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n",
"Code2": "void bubbleSort ( int arr [ ] ) {\n int n = arr . length ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = 0 ;\n j < n - i - 1 ;\n j ++ ) if ( arr [ j ] > arr [ j + 1 ] ) {\n int temp = arr [ j ] ;\n arr [ j ] = arr [ j + 1 ] ;\n arr [ j + 1 ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bubbleSort ( arr ) :\n n = len ( arr )\n for i in range ( n ) :\n for j in range ( 0 , n - i - 1 ) :\n if arr [ j ] > arr [ j + 1 ] :\n arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]\n\n"
},
{
"id": "python-java-SHORTEST_COMMON_SUPERSEQUENCE_1",
"pair": "python-java",
"Code1": "def superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n",
"Code2": "static int superSeq ( String X , String Y , int m , int n ) {\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n return dp [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef superSeq ( X , Y , m , n ) :\n dp = [ [ 0 ] * ( n + 2 ) for i in range ( m + 2 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( not i ) : dp [ i ] [ j ] = j\n elif ( not j ) : dp [ i ] [ j ] = i\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else : dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n return dp [ m ] [ n ]\n\n"
},
{
"id": "python-java-NUMBER_NON_NEGATIVE_INTEGRAL_SOLUTIONS_B_C_N",
"pair": "python-java",
"Code1": "def countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n",
"Code2": "static int countIntegralSolutions ( int n ) {\n int result = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n - i ;\n j ++ ) for ( int k = 0 ;\n k <= ( n - i - j ) ;\n k ++ ) if ( i + j + k == n ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countIntegralSolutions ( n ) :\n result = 0\n for i in range ( n + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( n + 1 ) :\n if i + j + k == n :\n result += 1\n return result\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_2",
"pair": "python-java",
"Code1": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n",
"Code2": "static int minJumps ( int arr [ ] , int n ) {\n int [ ] jumps = new int [ n ] ;\n int min ;\n jumps [ n - 1 ] = 0 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] == 0 ) jumps [ i ] = Integer . MAX_VALUE ;\n else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ;\n else {\n min = Integer . MAX_VALUE ;\n for ( int j = i + 1 ;\n j < n && j <= arr [ i ] + i ;\n j ++ ) {\n if ( min > jumps [ j ] ) min = jumps [ j ] ;\n }\n if ( min != Integer . MAX_VALUE ) jumps [ i ] = min + 1 ;\n else jumps [ i ] = min ;\n }\n }\n return jumps [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] == 0 ) :\n jumps [ i ] = float ( 'inf' )\n elif ( arr [ i ] >= n - i - 1 ) :\n jumps [ i ] = 1\n else :\n min = float ( 'inf' )\n for j in range ( i + 1 , n ) :\n if ( j <= arr [ i ] + i ) :\n if ( min > jumps [ j ] ) :\n min = jumps [ j ]\n if ( min != float ( 'inf' ) ) :\n jumps [ i ] = min + 1\n else :\n jumps [ i ] = min\n return jumps [ 0 ]\n\n"
},
{
"id": "python-java-FIND_MINIMUM_ADJUSTMENT_COST_OF_AN_ARRAY",
"pair": "python-java",
"Code1": "def minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n",
"Code2": "static int minAdjustmentCost ( int A [ ] , int n , int target ) {\n int [ ] [ ] dp = new int [ n ] [ M + 1 ] ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) dp [ 0 ] [ j ] = Math . abs ( j - A [ 0 ] ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= M ;\n j ++ ) {\n dp [ i ] [ j ] = Integer . MAX_VALUE ;\n int k = Math . max ( j - target , 0 ) ;\n for ( ;\n k <= Math . min ( M , j + target ) ;\n k ++ ) dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + Math . abs ( A [ i ] - j ) ) ;\n }\n }\n int res = Integer . MAX_VALUE ;\n for ( int j = 0 ;\n j <= M ;\n j ++ ) res = Math . min ( res , dp [ n - 1 ] [ j ] ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minAdjustmentCost ( A , n , target ) :\n dp = [ [ 0 for i in range ( M + 1 ) ] for i in range ( n ) ]\n for j in range ( M + 1 ) :\n dp [ 0 ] [ j ] = abs ( j - A [ 0 ] )\n for i in range ( 1 , n ) :\n for j in range ( M + 1 ) :\n dp [ i ] [ j ] = 100000000\n for k in range ( max ( j - target , 0 ) , min ( M , j + target ) + 1 ) :\n dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ i - 1 ] [ k ] + abs ( A [ i ] - j ) )\n res = 10000000\n for j in range ( M + 1 ) :\n res = min ( res , dp [ n - 1 ] [ j ] )\n return res\n\n"
},
{
"id": "python-java-KTH_SMALLESTLARGEST_ELEMENT_UNSORTED_ARRAY",
"pair": "python-java",
"Code1": "def kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n",
"Code2": "public static int kthSmallest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr ) ;\n return arr [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kthSmallest ( arr , n , k ) :\n arr.sort ( )\n return arr [ k - 1 ]\n\n"
},
{
"id": "python-java-FIND_THE_MINIMUM_COST_TO_REACH_A_DESTINATION_WHERE_EVERY_STATION_IS_CONNECTED_IN_ONE_DIRECTION",
"pair": "python-java",
"Code1": "def minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n",
"Code2": "static int minCost ( int cost [ ] [ ] ) {\n int dist [ ] = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dist [ i ] = INF ;\n dist [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = i + 1 ;\n j < N ;\n j ++ ) if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) dist [ j ] = dist [ i ] + cost [ i ] [ j ] ;\n return dist [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCost ( cost ) :\n dist = [ 0 for i in range ( N ) ]\n for i in range ( N ) :\n dist [ i ] = INF\n dist [ 0 ] = 0\n for i in range ( N ) :\n for j in range ( i + 1 , N ) :\n if ( dist [ j ] > dist [ i ] + cost [ i ] [ j ] ) :\n dist [ j ] = dist [ i ] + cost [ i ] [ j ]\n return dist [ N - 1 ]\n\n"
},
{
"id": "python-java-REVERSE_STRING_WITHOUT_USING_ANY_TEMPORARY_VARIABLE",
"pair": "python-java",
"Code1": "def reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n",
"Code2": "static String reversingString ( char [ ] str , int start , int end ) {\n while ( start < end ) {\n str [ start ] ^= str [ end ] ;\n str [ end ] ^= str [ start ] ;\n str [ start ] ^= str [ end ] ;\n ++ start ;\n -- end ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef reversingString ( str , start , end ) :\n while ( start < end ) :\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n str = ( str [ : end ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ end + 1 : ] )\n str = ( str [ : start ] + chr ( ord ( str [ start ] ) ^ ord ( str [ end ] ) ) + str [ start + 1 : ] )\n start += 1\n end -= 1\n return str\n\n"
},
{
"id": "python-java-MINIMAL_MOVES_FORM_STRING_ADDING_CHARACTERS_APPENDING_STRING",
"pair": "python-java",
"Code1": "def minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n",
"Code2": "static int minimalSteps ( String s , int n ) {\n int [ ] dp = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = Integer . MAX_VALUE ;\n String s1 = \"\" , s2 = \"\" ;\n dp [ 0 ] = 1 ;\n s1 += s . charAt ( 0 ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n s1 += s . charAt ( i ) ;\n s2 = s . substring ( i + 1 , i + 1 ) ;\n dp [ i ] = Math . min ( dp [ i ] , dp [ i - 1 ] + 1 ) ;\n if ( s1 == s2 ) dp [ i * 2 + 1 ] = Math . min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] ) ;\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimalSteps ( s , n ) :\n dp = [ INT_MAX for i in range ( n ) ]\n s1 = \"\"\n s2 = \"\"\n dp [ 0 ] = 1\n s1 += s [ 0 ]\n for i in range ( 1 , n ) :\n s1 += s [ i ]\n s2 = s [ i + 1 : i + 1 + i + 1 ]\n dp [ i ] = min ( dp [ i ] , dp [ i - 1 ] + 1 )\n if ( s1 == s2 ) :\n dp [ i * 2 + 1 ] = min ( dp [ i ] + 1 , dp [ i * 2 + 1 ] )\n return dp [ n - 1 ]\n\n"
},
{
"id": "python-java-MINIMUM_COST_TO_FILL_GIVEN_WEIGHT_IN_A_BAG",
"pair": "python-java",
"Code1": "def MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n",
"Code2": "public static int MinimumCost ( int cost [ ] , int n , int W ) {\n Vector < Integer > val = new Vector < Integer > ( ) ;\n Vector < Integer > wt = new Vector < Integer > ( ) ;\n int size = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( cost [ i ] != - 1 ) {\n val . add ( cost [ i ] ) ;\n wt . add ( i + 1 ) ;\n size ++ ;\n }\n }\n n = size ;\n int min_cost [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( int i = 0 ;\n i <= W ;\n i ++ ) min_cost [ 0 ] [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) min_cost [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= W ;\n j ++ ) {\n if ( wt . get ( i - 1 ) > j ) min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ] ;\n else min_cost [ i ] [ j ] = Math . min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt . get ( i - 1 ) ] + val . get ( i - 1 ) ) ;\n }\n }\n return ( min_cost [ n ] [ W ] == Integer . MAX_VALUE ) ? - 1 : min_cost [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MinimumCost ( cost , n , W ) :\n val = list ( )\n wt = list ( )\n size = 0\n for i in range ( n ) :\n if ( cost [ i ] != - 1 ) :\n val.append ( cost [ i ] )\n wt.append ( i + 1 )\n size += 1\n n = size\n min_cost = [ [ 0 for i in range ( W + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( W + 1 ) :\n min_cost [ 0 ] [ i ] = INF\n for i in range ( 1 , n + 1 ) :\n min_cost [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , W + 1 ) :\n if ( wt [ i - 1 ] > j ) :\n min_cost [ i ] [ j ] = min_cost [ i - 1 ] [ j ]\n else :\n min_cost [ i ] [ j ] = min ( min_cost [ i - 1 ] [ j ] , min_cost [ i ] [ j - wt [ i - 1 ] ] + val [ i - 1 ] )\n if ( min_cost [ n ] [ W ] == INF ) :\n return - 1\n else :\n return min_cost [ n ] [ W ]\n\n"
},
{
"id": "python-java-SORT_EVEN_PLACED_ELEMENTS_INCREASING_ODD_PLACED_DECREASING_ORDER",
"pair": "python-java",
"Code1": "def bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n",
"Code2": "static void bitonicGenerator ( int arr [ ] , int n ) {\n Vector < Integer > evenArr = new Vector < Integer > ( ) ;\n Vector < Integer > oddArr = new Vector < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 1 ) {\n evenArr . add ( arr [ i ] ) ;\n }\n else {\n oddArr . add ( arr [ i ] ) ;\n }\n }\n Collections . sort ( evenArr ) ;\n Collections . sort ( oddArr , Collections . reverseOrder ( ) ) ;\n int i = 0 ;\n for ( int j = 0 ;\n j < evenArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = evenArr . get ( j ) ;\n }\n for ( int j = 0 ;\n j < oddArr . size ( ) ;\n j ++ ) {\n arr [ i ++ ] = oddArr . get ( j ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bitonicGenerator ( arr , n ) :\n evenArr = [ ]\n oddArr = [ ]\n for i in range ( n ) :\n if ( ( i % 2 ) == 0 ) :\n evenArr.append ( arr [ i ] )\n else :\n oddArr.append ( arr [ i ] )\n evenArr = sorted ( evenArr )\n oddArr = sorted ( oddArr )\n oddArr = oddArr [ : : - 1 ]\n i = 0\n for j in range ( len ( evenArr ) ) :\n arr [ i ] = evenArr [ j ]\n i += 1\n for j in range ( len ( oddArr ) ) :\n arr [ i ] = oddArr [ j ]\n i += 1\n\n"
},
{
"id": "python-java-COUNT_DIVISIBLE_PAIRS_ARRAY",
"pair": "python-java",
"Code1": "def countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n",
"Code2": "static int countDivisibles ( int arr [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] % arr [ j ] == 0 || arr [ j ] % arr [ i ] == 0 ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDivisibles ( arr , n ) :\n res = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] % arr [ j ] == 0 or arr [ j ] % arr [ i ] == 0 ) :\n res += 1\n return res\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n\n"
},
{
"id": "python-java-FIND_FIRST_REPEATING_ELEMENT_ARRAY_INTEGERS",
"pair": "python-java",
"Code1": "def printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n",
"Code2": "static void printFirstRepeating ( int arr [ ] ) {\n int min = - 1 ;\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = arr . length - 1 ;\n i >= 0 ;\n i -- ) {\n if ( set . contains ( arr [ i ] ) ) min = i ;\n else set . add ( arr [ i ] ) ;\n }\n if ( min != - 1 ) System . out . println ( \"The first repeating element is \" + arr [ min ] ) ;\n else System . out . println ( \"There are no repeating elements\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printFirstRepeating ( arr , n ) :\n Min = - 1\n myset = dict ( )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if arr [ i ] in myset.keys ( ) :\n Min = i\n else :\n myset [ arr [ i ] ] = 1\n if ( Min != - 1 ) :\n print ( \"The first repeating element is\" , arr [ Min ] )\n else :\n print ( \"There are no repeating elements\" )\n\n"
},
{
"id": "python-java-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE",
"pair": "python-java",
"Code1": "def minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n",
"Code2": "static int minCoins ( int coins [ ] , int m , int V ) {\n if ( V == 0 ) return 0 ;\n int res = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n if ( coins [ i ] <= V ) {\n int sub_res = minCoins ( coins , m , V - coins [ i ] ) ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCoins ( coins , m , V ) :\n if ( V == 0 ) :\n return 0\n res = sys.maxsize\n for i in range ( 0 , m ) :\n if ( coins [ i ] <= V ) :\n sub_res = minCoins ( coins , m , V - coins [ i ] )\n if ( sub_res != sys.maxsize and sub_res + 1 < res ) :\n res = sub_res + 1\n return res\n\n"
},
{
"id": "python-java-FIND_PAIRS_GIVEN_SUM_ELEMENTS_PAIR_DIFFERENT_ROWS",
"pair": "python-java",
"Code1": "def pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n",
"Code2": "static void pairSum ( int mat [ ] [ ] , int n , int sum ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Arrays . sort ( mat [ i ] ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int left = 0 , right = n - 1 ;\n while ( left < n && right >= 0 ) {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) {\n System . out . print ( \"(\" + mat [ i ] [ left ] + \", \" + mat [ j ] [ right ] + \"), \" ) ;\n left ++ ;\n right -- ;\n }\n else {\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) left ++ ;\n else right -- ;\n }\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pairSum ( mat , n , sum ) :\n for i in range ( n ) :\n mat [ i ].sort ( )\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n left = 0\n right = n - 1\n while ( left < n and right >= 0 ) :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) == sum ) :\n print ( \"(\" , mat [ i ] [ left ] , \", \" , mat [ j ] [ right ] , \"), \" , end = \" \" )\n left += 1\n right -= 1\n else :\n if ( ( mat [ i ] [ left ] + mat [ j ] [ right ] ) < sum ) :\n left += 1\n else :\n right -= 1\n\n"
},
{
"id": "python-java-MINIMUM_COST_CONNECT_WEIGHTED_NODES_REPRESENTED_ARRAY",
"pair": "python-java",
"Code1": "def minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n",
"Code2": "static int minimum_cost ( int a [ ] , int n ) {\n int mn = Integer . MAX_VALUE ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n mn = Math . min ( a [ i ] , mn ) ;\n sum += a [ i ] ;\n }\n return mn * ( sum - mn ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimum_cost ( a , n ) :\n mn = sys.maxsize\n sum = 0\n for i in range ( n ) :\n mn = min ( a [ i ] , mn )\n sum += a [ i ]\n return mn * ( sum - mn )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_12_LONGEST_PALINDROMIC_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n",
"Code2": "static int lps ( String seq ) {\n int n = seq . length ( ) ;\n int i , j , cl ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) L [ i ] [ i ] = 1 ;\n for ( cl = 2 ;\n cl <= n ;\n cl ++ ) {\n for ( i = 0 ;\n i < n - cl + 1 ;\n i ++ ) {\n j = i + cl - 1 ;\n if ( seq . charAt ( i ) == seq . charAt ( j ) && cl == 2 ) L [ i ] [ j ] = 2 ;\n else if ( seq . charAt ( i ) == seq . charAt ( j ) ) L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2 ;\n else L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n }\n }\n return L [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lps ( str ) :\n n = len ( str )\n L = [ [ 0 for x in range ( n ) ] for x in range ( n ) ]\n for i in range ( n ) :\n L [ i ] [ i ] = 1\n for cl in range ( 2 , n + 1 ) :\n for i in range ( n - cl + 1 ) :\n j = i + cl - 1\n if str [ i ] == str [ j ] and cl == 2 :\n L [ i ] [ j ] = 2\n elif str [ i ] == str [ j ] :\n L [ i ] [ j ] = L [ i + 1 ] [ j - 1 ] + 2\n else :\n L [ i ] [ j ] = max ( L [ i ] [ j - 1 ] , L [ i + 1 ] [ j ] ) ;\n return L [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-PROGRAM_CENSOR_WORD_ASTERISKS_SENTENCE",
"pair": "python-java",
"Code1": "def censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n",
"Code2": "static String censor ( String text , String word ) {\n String [ ] word_list = text . split ( \"\\\\s+\" ) ;\n String result = \"\" ;\n String stars = \"\" ;\n for ( int i = 0 ;\n i < word . length ( ) ;\n i ++ ) stars += ' * ' ;\n int index = 0 ;\n for ( String i : word_list ) {\n if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ;\n index ++ ;\n }\n for ( String i : word_list ) result += i + ' ▁ ' ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef censor ( text , word ) :\n word_list = text.split ( )\n result = ''\n stars = '*' * len ( word )\n count = 0\n index = 0\n for i in word_list :\n if i == word :\n word_list [ index ] = stars\n index += 1\n result = ' '.join ( word_list )\n return result\n\n"
},
{
"id": "python-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT",
"pair": "python-java",
"Code1": "def isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n",
"Code2": "static int isPowerOfFour ( int n ) {\n if ( n == 0 ) return 0 ;\n while ( n != 1 ) {\n if ( n % 4 != 0 ) return 0 ;\n n = n / 4 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 4 != 0 ) :\n return False\n n = n // 4\n return True\n\n"
},
{
"id": "python-java-AREA_OF_THE_CIRCLE_THAT_HAS_A_SQUARE_AND_A_CIRCLE_INSCRIBED_IN_IT",
"pair": "python-java",
"Code1": "def getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n",
"Code2": "static float getArea ( int a ) {\n float area = ( float ) ( Math . PI * a * a ) / 4 ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getArea ( a ) :\n area = ( math.pi * a * a ) / 4\n return area\n\n"
},
{
"id": "python-java-SUM_MANHATTAN_DISTANCES_PAIRS_POINTS",
"pair": "python-java",
"Code1": "def distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n",
"Code2": "static int distancesum ( int x [ ] , int y [ ] , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef distancesum ( x , y , n ) :\n sum = 0\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )\n return sum\n\n"
},
{
"id": "python-java-FIND_ROW_NUMBER_BINARY_MATRIX_MAXIMUM_NUMBER_1S",
"pair": "python-java",
"Code1": "def findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n",
"Code2": "static void findMax ( int arr [ ] [ ] ) {\n int row = 0 , i , j ;\n for ( i = 0 , j = N - 1 ;\n i < N ;\n i ++ ) {\n while ( j >= 0 && arr [ i ] [ j ] == 1 ) {\n row = i ;\n j -- ;\n }\n }\n System . out . print ( \"Row number = \" + ( row + 1 ) ) ;\n System . out . print ( \", MaxCount = \" + ( N - 1 - j ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMax ( arr ) :\n row = 0\n j = N - 1\n for i in range ( 0 , N ) :\n while ( arr [ i ] [ j ] == 1 and j >= 0 ) :\n row = i\n j -= 1\n print ( \"Row number = \" , row + 1 , \", MaxCount = \" , N - 1 - j )\n\n"
},
{
"id": "python-java-LAST_NON_ZERO_DIGIT_FACTORIAL",
"pair": "python-java",
"Code1": "def lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n",
"Code2": "static int lastNon0Digit ( int n ) {\n if ( n < 10 ) return dig [ n ] ;\n if ( ( ( n / 10 ) % 10 ) % 2 == 0 ) return ( 6 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n else return ( 4 * lastNon0Digit ( n / 5 ) * dig [ n % 10 ] ) % 10 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lastNon0Digit ( n ) :\n if ( n < 10 ) :\n return dig [ n ]\n if ( ( ( n // 10 ) % 10 ) % 2 == 0 ) :\n return ( 6 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n else :\n return ( 4 * lastNon0Digit ( n // 5 ) * dig [ n % 10 ] ) % 10\n return 0\n\n"
},
{
"id": "python-java-EVEN_FIBONACCI_NUMBERS_SUM",
"pair": "python-java",
"Code1": "def evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n",
"Code2": "static int evenFibSum ( int limit ) {\n if ( limit < 2 ) return 0 ;\n long ef1 = 0 , ef2 = 2 ;\n long sum = ef1 + ef2 ;\n while ( ef2 <= limit ) {\n long ef3 = 4 * ef2 + ef1 ;\n if ( ef3 > limit ) break ;\n ef1 = ef2 ;\n ef2 = ef3 ;\n sum += ef2 ;\n }\n return ( int ) sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evenFibSum ( limit ) :\n if ( limit < 2 ) :\n return 0\n ef1 = 0\n ef2 = 2\n sm = ef1 + ef2\n while ( ef2 <= limit ) :\n ef3 = 4 * ef2 + ef1\n if ( ef3 > limit ) :\n break\n ef1 = ef2\n ef2 = ef3\n sm = sm + ef2\n return sm\n\n"
},
{
"id": "python-java-SEARCH_AN_ELEMENT_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_ELEMENTS_IS_1",
"pair": "python-java",
"Code1": "def search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . abs ( arr [ i ] - x ) ;\n }\n System . out . println ( \"number is not\" + \" present!\" ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + abs ( arr [ i ] - x )\n print ( \"number is not present!\" )\n return - 1\n\n"
},
{
"id": "python-java-CHECK_STRING_CAN_OBTAINED_ROTATING_ANOTHER_STRING_2_PLACES",
"pair": "python-java",
"Code1": "def isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n",
"Code2": "static boolean isRotated ( String str1 , String str2 ) {\n if ( str1 . length ( ) != str2 . length ( ) ) return false ;\n String clock_rot = \"\" ;\n String anticlock_rot = \"\" ;\n int len = str2 . length ( ) ;\n anticlock_rot = anticlock_rot + str2 . substring ( len - 2 , len ) + str2 . substring ( 0 , len - 2 ) ;\n clock_rot = clock_rot + str2 . substring ( 2 ) + str2 . substring ( 0 , 2 ) ;\n return ( str1 . equals ( clock_rot ) || str1 . equals ( anticlock_rot ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isRotated ( str1 , str2 ) :\n if ( len ( str1 ) != len ( str2 ) ) :\n return False\n clock_rot = \"\"\n anticlock_rot = \"\"\n l = len ( str2 )\n anticlock_rot = ( anticlock_rot + str2 [ l - 2 : ] + str2 [ 0 : l - 2 ] )\n clock_rot = clock_rot + str2 [ 2 : ] + str2 [ 0 : 2 ]\n return ( str1 == clock_rot or str1 == anticlock_rot )\n\n"
},
{
"id": "python-java-HOSOYAS_TRIANGLE",
"pair": "python-java",
"Code1": "def printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n",
"Code2": "static void printHosoya ( int n ) {\n int dp [ ] [ ] = new int [ N ] [ N ] ;\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( i > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) System . out . print ( dp [ i ] [ j ] + \" \" ) ;\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printHosoya ( n ) :\n dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]\n dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1\n for i in range ( 2 , n ) :\n for j in range ( n ) :\n if ( i > j ) :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )\n else :\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )\n for i in range ( n ) :\n for j in range ( i + 1 ) :\n print ( dp [ i ] [ j ] , end = ' ' )\n print ( )\n\n"
},
{
"id": "python-java-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S",
"pair": "python-java",
"Code1": "def findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n",
"Code2": "int findSubArray ( int arr [ ] , int n ) {\n int sum = 0 ;\n int maxsize = - 1 , startindex = 0 ;\n int endindex = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n sum = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] == 0 ) sum += - 1 ;\n else sum += 1 ;\n if ( sum == 0 && maxsize < j - i + 1 ) {\n maxsize = j - i + 1 ;\n startindex = i ;\n }\n }\n }\n endindex = startindex + maxsize - 1 ;\n if ( maxsize == - 1 ) System . out . println ( \"No such subarray\" ) ;\n else System . out . println ( startindex + \" to \" + endindex ) ;\n return maxsize ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSubArray ( arr , n ) :\n sum = 0\n maxsize = - 1\n for i in range ( 0 , n - 1 ) :\n sum = - 1 if ( arr [ i ] == 0 ) else 1\n for j in range ( i + 1 , n ) :\n sum = sum + ( - 1 ) if ( arr [ j ] == 0 ) else sum + 1\n if ( sum == 0 and maxsize < j - i + 1 ) :\n maxsize = j - i + 1\n startindex = i\n if ( maxsize == - 1 ) :\n print ( \"No such subarray\" )\n else :\n print ( startindex , \"to\" , startindex + maxsize - 1 )\n return maxsize\n\n"
},
{
"id": "python-java-RECURSIVE_INSERTION_SORT",
"pair": "python-java",
"Code1": "def insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n",
"Code2": "static void insertionSortRecursive ( int arr [ ] , int n ) {\n if ( n <= 1 ) return ;\n insertionSortRecursive ( arr , n - 1 ) ;\n int last = arr [ n - 1 ] ;\n int j = n - 2 ;\n while ( j >= 0 && arr [ j ] > last ) {\n arr [ j + 1 ] = arr [ j ] ;\n j -- ;\n }\n arr [ j + 1 ] = last ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef insertionSortRecursive ( arr , n ) :\n if n <= 1 :\n return\n insertionSortRecursive ( arr , n - 1 )\n last = arr [ n - 1 ]\n j = n - 2\n while ( j >= 0 and arr [ j ] > last ) :\n arr [ j + 1 ] = arr [ j ]\n j = j - 1\n arr [ j + 1 ] = last\n\n"
},
{
"id": "python-java-DIFFERENCE_BETWEEN_HIGHEST_AND_LEAST_FREQUENCIES_IN_AN_ARRAY_1",
"pair": "python-java",
"Code1": "def findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n",
"Code2": "static int findDiff ( int arr [ ] , int n ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n }\n int max_count = 0 , min_count = n ;\n for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) {\n max_count = Math . max ( max_count , x . getValue ( ) ) ;\n min_count = Math . min ( min_count , x . getValue ( ) ) ;\n }\n return ( max_count - min_count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDiff ( arr , n ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n max_count = 0 min_count = n\n for key , values in mp.items ( ) :\n max_count = max ( max_count , values )\n min_count = min ( min_count , values )\n return max_count - min_count\n\n"
},
{
"id": "python-java-GAME_REPLACING_ARRAY_ELEMENTS",
"pair": "python-java",
"Code1": "def playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n",
"Code2": "public static int playGame ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i : arr ) set . add ( i ) ;\n return ( set . size ( ) % 2 == 0 ) ? 1 : 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef playGame ( arr , n ) :\n s = set ( )\n for i in range ( n ) :\n s.add ( arr [ i ] )\n return 1 if len ( s ) % 2 == 0 else 2\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_SUBSETS_DISTINCT_ELEMENTS_1",
"pair": "python-java",
"Code1": "def subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n",
"Code2": "static int subset ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int res = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subset ( arr , n ) :\n mp = { i : 0 for i in range ( 10 ) }\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n res = 0\n for key , value in mp.items ( ) :\n res = max ( res , value )\n return res\n\n"
},
{
"id": "python-java-PAIR_WITH_GIVEN_PRODUCT_SET_1_FIND_IF_ANY_PAIR_EXISTS_1",
"pair": "python-java",
"Code1": "def isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n",
"Code2": "static boolean isProduct ( int arr [ ] , int n , int x ) {\n HashSet < Integer > hset = new HashSet < > ( ) ;\n if ( n < 2 ) return false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == 0 ) {\n if ( x == 0 ) return true ;\n else continue ;\n }\n if ( x % arr [ i ] == 0 ) {\n if ( hset . contains ( x / arr [ i ] ) ) return true ;\n hset . add ( arr [ i ] ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isProduct ( arr , n , x ) :\n if n < 2 :\n return False\n s = set ( )\n for i in range ( 0 , n ) :\n if arr [ i ] == 0 :\n if x == 0 :\n return True\n else :\n continue\n if x % arr [ i ] == 0 :\n if x // arr [ i ] in s :\n return True\n s.add ( arr [ i ] )\n return False\n\n"
},
{
"id": "python-java-MAXIMUM_AVERAGE_SUM_PARTITION_ARRAY",
"pair": "python-java",
"Code1": "def largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n",
"Code2": "static double largestSumOfAverages ( int [ ] A , int K ) {\n int n = A . length ;\n double [ ] pre_sum = new double [ n + 1 ] ;\n pre_sum [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ;\n double [ ] dp = new double [ n ] ;\n double sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ;\n for ( int k = 0 ;\n k < K - 1 ;\n k ++ ) for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ;\n return dp [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largestSumOfAverages ( A , K ) :\n n = len ( A )\n pre_sum = [ 0 ] * ( n + 1 )\n pre_sum [ 0 ] = 0\n for i in range ( n ) :\n pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ]\n dp = [ 0 ] * n\n sum = 0\n for i in range ( n ) :\n dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i )\n for k in range ( K - 1 ) :\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n dp [ i ] = max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] )\n return int ( dp [ 0 ] )\n\n"
},
{
"id": "python-java-MINIMUM_STEPS_MINIMIZE_N_PER_GIVEN_CONDITION",
"pair": "python-java",
"Code1": "def getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n ",
"Code2": "static int getMinSteps ( int n ) {\n int table [ ] = new int [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) table [ i ] = n - i ;\n for ( int i = n ;\n i >= 1 ;\n i -- ) {\n if ( ! ( i % 2 > 0 ) ) table [ i / 2 ] = Math . min ( table [ i ] + 1 , table [ i / 2 ] ) ;\n if ( ! ( i % 3 > 0 ) ) table [ i / 3 ] = Math . min ( table [ i ] + 1 , table [ i / 3 ] ) ;\n }\n return table [ 1 ] ;\n ",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMinSteps ( n ) :\n table = [ 0 ] * ( n + 1 )\n for i in range ( n + 1 ) :\n table [ i ] = n - i\n for i in range ( n , 0 , - 1 ) :\n if ( not ( i % 2 ) ) :\n table [ i // 2 ] = min ( table [ i ] + 1 , table [ i // 2 ] )\n if ( not ( i % 3 ) ) :\n table [ i // 3 ] = min ( table [ i ] + 1 , table [ i // 3 ] )\n return table [ 1 ]\n \n"
},
{
"id": "python-java-N_TH_TERM_SERIES_2_12_36_80_150",
"pair": "python-java",
"Code1": "def nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n",
"Code2": "public static int nthTerm ( int n ) {\n return ( n * n ) + ( n * n * n ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nthTerm ( n ) :\n return ( n * n ) + ( n * n * n )\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH_1",
"pair": "python-java",
"Code1": "def findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n",
"Code2": "static int findMaxAverage ( int arr [ ] , int n , int k ) {\n if ( k > n ) return - 1 ;\n int sum = arr [ 0 ] ;\n for ( int i = 1 ;\n i < k ;\n i ++ ) sum += arr [ i ] ;\n int max_sum = sum , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n sum = sum + arr [ i ] - arr [ i - k ] ;\n if ( sum > max_sum ) {\n max_sum = sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxAverage ( arr , n , k ) :\n if ( k > n ) :\n return - 1\n sum = arr [ 0 ]\n for i in range ( 1 , k ) :\n sum += arr [ i ]\n max_sum = sum\n max_end = k - 1\n for i in range ( k , n ) :\n sum = sum + arr [ i ] - arr [ i - k ]\n if ( sum > max_sum ) :\n max_sum = sum\n max_end = i\n return max_end - k + 1\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE",
"pair": "python-java",
"Code1": "def eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n",
"Code2": "static int eggDrop ( int n , int k ) {\n if ( k == 1 || k == 0 ) return k ;\n if ( n == 1 ) return k ;\n int min = Integer . MAX_VALUE ;\n int x , res ;\n for ( x = 1 ;\n x <= k ;\n x ++ ) {\n res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ;\n if ( res < min ) min = res ;\n }\n return min + 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef eggDrop ( n , k ) :\n if ( k == 1 or k == 0 ) :\n return k\n if ( n == 1 ) :\n return k\n min = sys.maxsize\n for x in range ( 1 , k + 1 ) :\n res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )\n if ( res < min ) :\n min = res\n return min + 1\n\n"
},
{
"id": "python-java-PROGRAM_COUNT_OCCURRENCE_GIVEN_CHARACTER_STRING",
"pair": "python-java",
"Code1": "def count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n",
"Code2": "public static int count ( String s , char c ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n if ( s . charAt ( i ) == c ) res ++ ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count ( s , c ) :\n res = 0\n for i in range ( len ( s ) ) :\n if ( s [ i ] == c ) :\n res = res + 1\n return res\n\n"
},
{
"id": "python-java-MINIMUM_ROTATIONS_REQUIRED_GET_STRING",
"pair": "python-java",
"Code1": "def findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n",
"Code2": "static int findRotations ( String str ) {\n String tmp = str + str ;\n int n = str . length ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n String substring = tmp . substring ( i , str . length ( ) ) ;\n if ( str == substring ) return i ;\n }\n return n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRotations ( str ) :\n tmp = str + str\n n = len ( str )\n for i in range ( 1 , n + 1 ) :\n substring = tmp [ i : n ]\n if ( str == substring ) :\n return i\n return n\n\n"
},
{
"id": "python-java-SHUFFLE_A_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n",
"Code2": "static void randomize ( int arr [ ] , int n ) {\n Random r = new Random ( ) ;\n for ( int i = n - 1 ;\n i > 0 ;\n i -- ) {\n int j = r . nextInt ( i + 1 ) ;\n int temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n System . out . println ( Arrays . toString ( arr ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef randomize ( arr , n ) :\n for i in range ( n - 1 , 0 , - 1 ) :\n j = random.randint ( 0 , i + 1 )\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n return arr\n\n"
},
{
"id": "python-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_2",
"pair": "python-java",
"Code1": "def findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n",
"Code2": "static int findLength ( String str , int n ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum [ i ] = ( sum [ i - 1 ] + str . charAt ( i - 1 ) - ' 0 ' ) ;\n int ans = 0 ;\n for ( int len = 2 ;\n len <= n ;\n len += 2 ) {\n for ( int i = 0 ;\n i <= n - len ;\n i ++ ) {\n int j = i + len - 1 ;\n if ( sum [ i + len / 2 ] - sum [ i ] == sum [ i + len ] - sum [ i + len / 2 ] ) ans = Math . max ( ans , len ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLength ( string , n ) :\n Sum = [ 0 ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n Sum [ i ] = ( Sum [ i - 1 ] + int ( string [ i - 1 ] ) )\n ans = 0\n for length in range ( 2 , n + 1 , 2 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n if ( Sum [ i + length // 2 ] - Sum [ i ] == Sum [ i + length ] - Sum [ i + length // 2 ] ) :\n ans = max ( ans , length )\n return ans\n\n"
},
{
"id": "python-java-REPLACE_OCCURRENCES_STRING_AB_C_WITHOUT_USING_EXTRA_SPACE_1",
"pair": "python-java",
"Code1": "def translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n",
"Code2": "static void translate ( char str [ ] ) {\n int len = str . length ;\n if ( len < 2 ) return ;\n int i = 0 ;\n int j = 0 ;\n while ( j < len - 1 ) {\n if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) {\n j = j + 2 ;\n str [ i ++ ] = ' C ' ;\n continue ;\n }\n str [ i ++ ] = str [ j ++ ] ;\n }\n if ( j == len - 1 ) str [ i ++ ] = str [ j ] ;\n str [ i ] = ' ▁ ' ;\n str [ len - 1 ] = ' ▁ ' ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef translate ( st ) :\n l = len ( st )\n if ( l < 2 ) :\n return\n i = 0\n j = 0\n while ( j < l - 1 ) :\n if ( st [ j ] == 'A' and st [ j + 1 ] == 'B' ) :\n j += 2\n st [ i ] = 'C'\n i += 1\n continue\n st [ i ] = st [ j ]\n i += 1\n j += 1\n if ( j == l - 1 ) :\n st [ i ] = st [ j ]\n i += 1\n st [ i ] = ' '\n st [ l - 1 ] = ' '\n\n"
},
{
"id": "python-java-NUMBER_WHICH_HAS_THE_MAXIMUM_NUMBER_OF_DISTINCT_PRIME_FACTORS_IN_RANGE_M_TO_N",
"pair": "python-java",
"Code1": "def maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n",
"Code2": "static int maximumNumberDistinctPrimeRange ( int m , int n ) {\n long factorCount [ ] = new long [ n + 1 ] ;\n boolean prime [ ] = new boolean [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n factorCount [ i ] = 0 ;\n prime [ i ] = true ;\n }\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( prime [ i ] == true ) {\n factorCount [ i ] = 1 ;\n for ( int j = i * 2 ;\n j <= n ;\n j += i ) {\n factorCount [ j ] ++ ;\n prime [ j ] = false ;\n }\n }\n }\n int max = ( int ) factorCount [ m ] ;\n int num = m ;\n for ( int i = m ;\n i <= n ;\n i ++ ) {\n if ( factorCount [ i ] > max ) {\n max = ( int ) factorCount [ i ] ;\n num = i ;\n }\n }\n return num ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumNumberDistinctPrimeRange ( m , n ) :\n factorCount = [ 0 ] * ( n + 1 )\n prime = [ False ] * ( n + 1 )\n for i in range ( n + 1 ) :\n factorCount [ i ] = 0\n prime [ i ] = True\n for i in range ( 2 , n + 1 ) :\n if ( prime [ i ] == True ) :\n factorCount [ i ] = 1\n for j in range ( i * 2 , n + 1 , i ) :\n factorCount [ j ] += 1\n prime [ j ] = False\n max = factorCount [ m ]\n num = m\n for i in range ( m , n + 1 ) :\n if ( factorCount [ i ] > max ) :\n max = factorCount [ i ]\n num = i\n return num\n\n"
},
{
"id": "python-java-PROGRAM_NTH_CATALAN_NUMBER",
"pair": "python-java",
"Code1": "def catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n",
"Code2": "int catalan ( int n ) {\n int res = 0 ;\n if ( n <= 1 ) {\n return 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res += catalan ( i ) * catalan ( n - i - 1 ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef catalan ( n ) :\n if n <= 1 :\n return 1\n res = 0\n for i in range ( n ) :\n res += catalan ( i ) * catalan ( n - i - 1 )\n return res\n\n"
},
{
"id": "python-java-SUM_SERIES_12_32_52_2N_12",
"pair": "python-java",
"Code1": "def sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n",
"Code2": "static int sumOfSeries ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumOfSeries ( n ) :\n sum = 0\n for i in range ( 1 , n + 1 ) :\n sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 )\n return sum\n\n"
},
{
"id": "python-java-MINIMUM_REVOLUTIONS_MOVE_CENTER_CIRCLE_TARGET",
"pair": "python-java",
"Code1": "def minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n",
"Code2": "static double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) {\n double d = Math . sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ;\n return Math . ceil ( d / ( 2 * r ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRevolutions ( r , x1 , y1 , x2 , y2 ) :\n d = math.sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) )\n return math.ceil ( d // ( 2 * r ) )\n\n"
},
{
"id": "python-java-PRINT_STRING_SPECIFIED_CHARACTER_OCCURRED_GIVEN_NO_TIMES",
"pair": "python-java",
"Code1": "def printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n",
"Code2": "static void printString ( String str , char ch , int count ) {\n int occ = 0 , i ;\n if ( count == 0 ) {\n System . out . println ( str ) ;\n return ;\n }\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( str . charAt ( i ) == ch ) occ ++ ;\n if ( occ == count ) break ;\n }\n if ( i < str . length ( ) - 1 ) System . out . println ( str . substring ( i + 1 ) ) ;\n else System . out . println ( \"Empty string\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printString ( str , ch , count ) :\n occ , i = 0 , 0\n if ( count == 0 ) :\n print ( str )\n for i in range ( len ( str ) ) :\n if ( str [ i ] == ch ) :\n occ += 1\n if ( occ == count ) :\n break\n if ( i < len ( str ) - 1 ) :\n print ( str [ i + 1 : len ( str ) - i + 2 ] )\n else :\n print ( \"Empty string\" )\n\n"
},
{
"id": "python-java-FINDING_THE_MAXIMUM_SQUARE_SUB_MATRIX_WITH_ALL_EQUAL_ELEMENTS",
"pair": "python-java",
"Code1": "def largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n",
"Code2": "static int largestKSubmatrix ( int [ ] [ ] a ) {\n int [ ] [ ] dp = new int [ Row ] [ Col ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i < Row ;\n i ++ ) {\n for ( int j = 0 ;\n j < Col ;\n j ++ ) {\n if ( i == 0 || j == 0 ) dp [ i ] [ j ] = 1 ;\n else {\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] && a [ i ] [ j ] == a [ i ] [ j - 1 ] && a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) {\n dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] > dp [ i ] [ j - 1 ] && dp [ i - 1 ] [ j ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i - 1 ] [ j ] : ( dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j ] && dp [ i ] [ j - 1 ] > dp [ i - 1 ] [ j - 1 ] + 1 ) ? dp [ i ] [ j - 1 ] : dp [ i - 1 ] [ j - 1 ] + 1 ;\n }\n else dp [ i ] [ j ] = 1 ;\n }\n result = result > dp [ i ] [ j ] ? result : dp [ i ] [ j ] ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largestKSubmatrix ( a ) :\n dp = [ [ 0 for x in range ( Row ) ] for y in range ( Col ) ]\n result = 0\n for i in range ( Row ) :\n for j in range ( Col ) :\n if ( i == 0 or j == 0 ) :\n dp [ i ] [ j ] = 1\n else :\n if ( a [ i ] [ j ] == a [ i - 1 ] [ j ] and a [ i ] [ j ] == a [ i ] [ j - 1 ] and a [ i ] [ j ] == a [ i - 1 ] [ j - 1 ] ) :\n dp [ i ] [ j ] = min ( min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , dp [ i - 1 ] [ j - 1 ] ) + 1\n else :\n dp [ i ] [ j ] = 1\n result = max ( result , dp [ i ] [ j ] )\n return result\n\n"
},
{
"id": "python-java-PASCAL_TRIANGLE",
"pair": "python-java",
"Code1": "def printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n",
"Code2": "public static void printPascal ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int line = 0 ;\n line < n ;\n line ++ ) {\n for ( int i = 0 ;\n i <= line ;\n i ++ ) {\n if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ;\n else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ;\n System . out . print ( arr [ line ] [ i ] ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printPascal ( n : int ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for line in range ( 0 , n ) :\n for i in range ( 0 , line + 1 ) :\n if ( i is 0 or i is line ) :\n arr [ line ] [ i ] = 1\n print ( arr [ line ] [ i ] , end = \"\" )\n else :\n arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] )\n print ( arr [ line ] [ i ] , end = \"\" )\n print ( \"\\n\" , end = \"\" )\n\n"
},
{
"id": "python-java-NUMBER_INDEXES_EQUAL_ELEMENTS_GIVEN_RANGE",
"pair": "python-java",
"Code1": "def answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n",
"Code2": "static int answer_query ( int a [ ] , int n , int l , int r ) {\n int count = 0 ;\n for ( int i = l ;\n i < r ;\n i ++ ) if ( a [ i ] == a [ i + 1 ] ) count += 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef answer_query ( a , n , l , r ) :\n count = 0\n for i in range ( l , r ) :\n if ( a [ i ] == a [ i + 1 ] ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-CASSINIS_IDENTITY",
"pair": "python-java",
"Code1": "def cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n",
"Code2": "static int cassini ( int n ) {\n return ( n & 1 ) != 0 ? - 1 : 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef cassini ( n ) :\n return - 1 if ( n & 1 ) else 1\n\n"
},
{
"id": "python-java-COMPUTE_AVERAGE_TWO_NUMBERS_WITHOUT_OVERFLOW",
"pair": "python-java",
"Code1": "def compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n",
"Code2": "static int compute_average ( int a , int b ) {\n return ( a + b ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef compute_average ( a , b ) :\n return floor ( ( a + b ) / 2 )\n\n"
},
{
"id": "python-java-NUMBER_OF_WAYS_TO_ARRANGE_N_ITEMS_UNDER_GIVEN_CONSTRAINTS",
"pair": "python-java",
"Code1": "def waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n",
"Code2": "static int waysToArrange ( int N , int K , int [ ] k ) {\n int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= N ;\n i ++ ) {\n for ( j = 0 ;\n j <= i ;\n j ++ ) {\n if ( j == 0 || j == i ) {\n C [ i ] [ j ] = 1 ;\n }\n else {\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ;\n }\n }\n }\n int [ ] dp = new int [ K + 1 ] ;\n int count = 0 ;\n dp [ 0 ] = 1 ;\n for ( i = 0 ;\n i < K ;\n i ++ ) {\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ;\n count += k [ i ] ;\n }\n return dp [ K ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef waysToArrange ( N , K , k ) :\n C = np.zeros ( ( N + 1 , N + 1 ) )\n for i in range ( N + 1 ) :\n for j in range ( i + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n dp = np.zeros ( ( K + 1 ) )\n count = 0\n dp [ 0 ] = 1\n for i in range ( K ) :\n dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] )\n count += k [ i ]\n return dp [ K ]\n\n"
},
{
"id": "python-java-FIND_DIMENSIONS_RIGHT_ANGLED_TRIANGLE",
"pair": "python-java",
"Code1": "def findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n",
"Code2": "static void findDimen ( int H , int A ) {\n if ( H * H < 4 * A ) {\n System . out . println ( \"Not Possible\" ) ;\n return ;\n }\n double apb = Math . sqrt ( H * H + 4 * A ) ;\n double asb = Math . sqrt ( H * H - 4 * A ) ;\n System . out . println ( \"P = \" + Math . round ( ( ( apb - asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n System . out . print ( \"B = \" + Math . round ( ( ( apb + asb ) / 2.0 ) * 100.0 ) / 100.0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDimen ( H , A ) :\n if H * H < 4 * A :\n print ( \"Not Possible\" )\n return\n apb = sqrt ( H * H + 4 * A )\n asb = sqrt ( H * H - 4 * A )\n print ( \"P = \" , \"%.2f\" % ( ( apb - asb ) / 2.0 ) )\n print ( \"B = \" , \"%.2f\" % ( ( apb + asb ) / 2.0 ) )\n\n"
},
{
"id": "python-java-MAXIMUM_TRIPLET_SUM_ARRAY_1",
"pair": "python-java",
"Code1": "def maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n",
"Code2": "static int maxTripletSum ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxTripletSum ( arr , n ) :\n arr.sort ( )\n return ( arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] )\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_DOT_PRODUCT_TWO_ARRAYS_INSERTION_0S",
"pair": "python-java",
"Code1": "def MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n",
"Code2": "static int MaxDotProduct ( int A [ ] , int B [ ] , int m , int n ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int [ ] row : dp ) Arrays . fill ( row , 0 ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= m ;\n j ++ ) dp [ i ] [ j ] = Math . max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] ) ;\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MaxDotProduct ( A , B , m , n ) :\n dp = [ [ 0 for i in range ( m + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n for j in range ( i , m + 1 , 1 ) :\n dp [ i ] [ j ] = max ( ( dp [ i - 1 ] [ j - 1 ] + ( A [ j - 1 ] * B [ i - 1 ] ) ) , dp [ i ] [ j - 1 ] )\n return dp [ n ] [ m ]\n\n"
},
{
"id": "python-java-FIND_MINIMUM_DIFFERENCE_PAIR_1",
"pair": "python-java",
"Code1": "def findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n",
"Code2": "static int findMinDiff ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ;\n return diff ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinDiff ( arr , n ) :\n arr = sorted ( arr )\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n if arr [ i + 1 ] - arr [ i ] < diff :\n diff = arr [ i + 1 ] - arr [ i ]\n return diff\n\n"
},
{
"id": "python-java-FIND_LAST_INDEX_CHARACTER_STRING_1",
"pair": "python-java",
"Code1": "def findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n",
"Code2": "static int findLastIndex ( String str , Character x ) {\n for ( int i = str . length ( ) - 1 ;\n i >= 0 ;\n i -- ) if ( str . charAt ( i ) == x ) return i ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLastIndex ( str , x ) :\n for i in range ( len ( str ) - 1 , - 1 , - 1 ) :\n if ( str [ i ] == x ) :\n return i\n return - 1\n\n"
},
{
"id": "python-java-MAXIMUM_DISTINCT_LOWERCASE_ALPHABETS_TWO_UPPERCASE",
"pair": "python-java",
"Code1": "def maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n",
"Code2": "static int maxLower ( String str ) {\n int n = str . length ( ) ;\n int i = 0 ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n i ++ ;\n break ;\n }\n }\n int maxCount = 0 ;\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( ;\n i < n ;\n i ++ ) {\n if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) {\n int currCount = 0 ;\n for ( int j = 0 ;\n j < MAX_CHAR ;\n j ++ ) {\n if ( count [ j ] > 0 ) {\n currCount ++ ;\n }\n }\n maxCount = Math . max ( maxCount , currCount ) ;\n Arrays . fill ( count , 0 ) ;\n }\n if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) {\n count [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n }\n return maxCount ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLower ( str ) :\n n = len ( str )\n i = 0\n for i in range ( n ) :\n if str [ i ] >= 'A' and str [ i ] <= 'Z' :\n i += 1\n break\n maxCount = 0\n count = [ ]\n for j in range ( MAX_CHAR ) :\n count.append ( 0 )\n for j in range ( i , n ) :\n if str [ j ] >= 'A' and str [ j ] <= 'Z' :\n currCount = 0\n for k in range ( MAX_CHAR ) :\n if count [ k ] > 0 :\n currCount += 1\n maxCount = max ( maxCount , currCount )\n for y in count :\n y = 0\n if str [ j ] >= 'a' and str [ j ] <= 'z' :\n count [ ord ( str [ j ] ) - ord ( 'a' ) ] += 1\n return maxCount\n\n"
},
{
"id": "python-java-FIND_ELEMENTS_ARRAY_LEAST_TWO_GREATER_ELEMENTS",
"pair": "python-java",
"Code1": "def findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "static void findElements ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( arr [ j ] > arr [ i ] ) count ++ ;\n if ( count >= 2 ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findElements ( arr , n ) :\n for i in range ( n ) :\n count = 0\n for j in range ( 0 , n ) :\n if arr [ j ] > arr [ i ] :\n count = count + 1\n if count >= 2 :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-NTH_EVEN_LENGTH_PALINDROME",
"pair": "python-java",
"Code1": "def evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n",
"Code2": "static String evenlength ( String n ) {\n String res = n ;\n for ( int j = n . length ( ) - 1 ;\n j >= 0 ;\n -- j ) res += n . charAt ( j ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evenlength ( n ) :\n res = n\n for j in range ( len ( n ) - 1 , - 1 , - 1 ) :\n res += n [ j ]\n return res\n\n"
},
{
"id": "python-java-LARGEST_SUBARRAY_WITH_EQUAL_NUMBER_OF_0S_AND_1S_1",
"pair": "python-java",
"Code1": "def maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n",
"Code2": "int maxLen ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 ;\n int max_len = 0 ;\n int ending_index = - 1 ;\n int start_index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == 0 ) ? - 1 : 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] ;\n if ( sum == 0 ) {\n max_len = i + 1 ;\n ending_index = i ;\n }\n if ( hM . containsKey ( sum + n ) ) {\n if ( max_len < i - hM . get ( sum + n ) ) {\n max_len = i - hM . get ( sum + n ) ;\n ending_index = i ;\n }\n }\n else hM . put ( sum + n , i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = ( arr [ i ] == - 1 ) ? 0 : 1 ;\n }\n int end = ending_index - max_len + 1 ;\n System . out . println ( end + \" to \" + ending_index ) ;\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLen ( arr , n ) :\n hash_map = { }\n curr_sum = 0\n max_len = 0\n ending_index = - 1\n for i in range ( 0 , n ) :\n if ( arr [ i ] == 0 ) :\n arr [ i ] = - 1\n else :\n arr [ i ] = 1\n for i in range ( 0 , n ) :\n curr_sum = curr_sum + arr [ i ]\n if ( curr_sum == 0 ) :\n max_len = i + 1\n ending_index = i\n if ( curr_sum + n ) in hash_map :\n max_len = max ( max_len , i - hash_map [ curr_sum + n ] )\n else :\n hash_map [ curr_sum ] = i\n for i in range ( 0 , n ) :\n if ( arr [ i ] == - 1 ) :\n arr [ i ] = 0\n else :\n arr [ i ] = 1\n print ( ending_index - max_len + 1 , end = \" \" )\n print ( \"to\" , end = \" \" )\n print ( ending_index )\n return max_len\n\n"
},
{
"id": "python-java-COUNT_NUMBER_OF_STRINGS_MADE_OF_R_G_AND_B_USING_GIVEN_COMBINATION",
"pair": "python-java",
"Code1": "def possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n",
"Code2": "static int possibleStrings ( int n , int r , int b , int g ) {\n int fact [ ] = new int [ n + 1 ] ;\n fact [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) fact [ i ] = fact [ i - 1 ] * i ;\n int left = n - ( r + g + b ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i <= left ;\n i ++ ) {\n for ( int j = 0 ;\n j <= left - i ;\n j ++ ) {\n int k = left - ( i + j ) ;\n sum = sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef possibleStrings ( n , r , b , g ) :\n fact = [ 0 for i in range ( n + 1 ) ]\n fact [ 0 ] = 1\n for i in range ( 1 , n + 1 , 1 ) :\n fact [ i ] = fact [ i - 1 ] * i\n left = n - ( r + g + b )\n sum = 0\n for i in range ( 0 , left + 1 , 1 ) :\n for j in range ( 0 , left - i + 1 , 1 ) :\n k = left - ( i + j )\n sum = ( sum + fact [ n ] / ( fact [ i + r ] * fact [ j + b ] * fact [ k + g ] ) )\n return sum\n\n"
},
{
"id": "python-java-NUMBER_WAYS_INSERT_CHARACTER_INCREASE_LCS_ONE",
"pair": "python-java",
"Code1": "def numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n",
"Code2": "static int numberofways ( String A , String B , int N , int M ) {\n Vector < Integer > [ ] pos = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) pos [ i ] = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) pos [ B . charAt ( i ) ] . add ( i + 1 ) ;\n int [ ] [ ] dpl = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n for ( int j = 1 ;\n j <= M ;\n j ++ ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1 ;\n else dpl [ i ] [ j ] = Math . max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] ) ;\n }\n }\n int LCS = dpl [ N ] [ M ] ;\n int [ ] [ ] dpr = new int [ N + 2 ] [ M + 2 ] ;\n for ( int i = N ;\n i >= 1 ;\n i -- ) {\n for ( int j = M ;\n j >= 1 ;\n j -- ) {\n if ( A . charAt ( i - 1 ) == B . charAt ( j - 1 ) ) dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1 ;\n else dpr [ i ] [ j ] = Math . max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] ) ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i <= N ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n for ( int x : pos [ j ] ) {\n if ( dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS ) {\n ans ++ ;\n break ;\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberofways ( A , B , N , M ) :\n pos = [ [ ] for _ in range ( MAX ) ]\n for i in range ( M ) :\n pos [ ord ( B [ i ] ) ].append ( i + 1 )\n dpl = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( 1 , N + 1 ) :\n for j in range ( 1 , M + 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpl [ i ] [ j ] = dpl [ i - 1 ] [ j - 1 ] + 1\n else :\n dpl [ i ] [ j ] = max ( dpl [ i - 1 ] [ j ] , dpl [ i ] [ j - 1 ] )\n LCS = dpl [ N ] [ M ]\n dpr = [ [ 0 ] * ( M + 2 ) for _ in range ( N + 2 ) ]\n for i in range ( N , 0 , - 1 ) :\n for j in range ( M , 0 , - 1 ) :\n if A [ i - 1 ] == B [ j - 1 ] :\n dpr [ i ] [ j ] = dpr [ i + 1 ] [ j + 1 ] + 1\n else :\n dpr [ i ] [ j ] = max ( dpr [ i + 1 ] [ j ] , dpr [ i ] [ j + 1 ] )\n ans = 0\n for i in range ( N + 1 ) :\n for j in range ( MAX ) :\n for x in pos [ j ] :\n if dpl [ i ] [ x - 1 ] + dpr [ i + 1 ] [ x + 1 ] == LCS :\n ans += 1\n break\n return ans\n\n"
},
{
"id": "python-java-PROGRAM_FIND_CIRCUMFERENCE_CIRCLE",
"pair": "python-java",
"Code1": "def circumference ( r ) :\n return ( 2 * PI * r )\n",
"Code2": "static double circumference ( double r ) {\n double PI = 3.1415 ;\n double cir = 2 * PI * r ;\n return cir ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef circumference ( r ) :\n return ( 2 * PI * r )\n\n"
},
{
"id": "python-java-CONVERT_SUBSTRINGS_LENGTH_K_BASE_B_DECIMAL",
"pair": "python-java",
"Code1": "def substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n",
"Code2": "static void substringConversions ( String str , int k , int b ) {\n for ( int i = 0 ;\n i + k <= str . length ( ) ;\n i ++ ) {\n String sub = str . substring ( i , i + k ) ;\n int sum = 0 , counter = 0 ;\n for ( int j = sub . length ( ) - 1 ;\n j >= 0 ;\n j -- ) {\n sum = ( int ) ( sum + ( ( sub . charAt ( j ) - ' 0 ' ) * Math . pow ( b , counter ) ) ) ;\n counter ++ ;\n }\n System . out . print ( sum + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef substringConversions ( s , k , b ) :\n l = len ( s )\n for i in range ( l ) :\n if ( ( i + k ) < l + 1 ) :\n sub = s [ i : i + k ]\n sum , counter = 0 , 0\n for i in range ( len ( sub ) - 1 , - 1 , - 1 ) :\n sum = sum + ( ( ord ( sub [ i ] ) - ord ( '0' ) ) * pow ( b , counter ) )\n counter += 1\n print ( sum , end = \" \" )\n\n"
},
{
"id": "python-java-MAXIMUM_PATH_SUM_TRIANGLE",
"pair": "python-java",
"Code1": "def maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n",
"Code2": "static int maxPathSum ( int tri [ ] [ ] , int m , int n ) {\n for ( int i = m - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j <= i ;\n j ++ ) {\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) tri [ i ] [ j ] += tri [ i + 1 ] [ j ] ;\n else tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ] ;\n }\n }\n return tri [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxPathSum ( tri , m , n ) :\n for i in range ( m - 1 , - 1 , - 1 ) :\n for j in range ( i + 1 ) :\n if ( tri [ i + 1 ] [ j ] > tri [ i + 1 ] [ j + 1 ] ) :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j ]\n else :\n tri [ i ] [ j ] += tri [ i + 1 ] [ j + 1 ]\n return tri [ 0 ] [ 0 ]\n\n"
},
{
"id": "python-java-SUM_MINIMUM_MAXIMUM_ELEMENTS_SUBARRAYS_SIZE_K",
"pair": "python-java",
"Code1": "def SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n",
"Code2": "public static int SumOfKsubArray ( int arr [ ] , int k ) {\n int sum = 0 ;\n Deque < Integer > S = new LinkedList < > ( ) , G = new LinkedList < > ( ) ;\n int i = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n for ( ;\n i < arr . length ;\n i ++ ) {\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n while ( ! S . isEmpty ( ) && S . peekFirst ( ) <= i - k ) S . removeFirst ( ) ;\n while ( ! G . isEmpty ( ) && G . peekFirst ( ) <= i - k ) G . removeFirst ( ) ;\n while ( ! S . isEmpty ( ) && arr [ S . peekLast ( ) ] >= arr [ i ] ) S . removeLast ( ) ;\n while ( ! G . isEmpty ( ) && arr [ G . peekLast ( ) ] <= arr [ i ] ) G . removeLast ( ) ;\n G . addLast ( i ) ;\n S . addLast ( i ) ;\n }\n sum += arr [ S . peekFirst ( ) ] + arr [ G . peekFirst ( ) ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef SumOfKsubArray ( arr , n , k ) :\n Sum = 0\n S = deque ( )\n G = deque ( )\n for i in range ( k ) :\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n for i in range ( k , n ) :\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :\n S.popleft ( )\n while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :\n G.popleft ( )\n while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :\n S.pop ( )\n while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :\n G.pop ( )\n G.append ( i )\n S.append ( i )\n Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]\n return Sum\n\n"
},
{
"id": "python-java-TURN_OFF_THE_RIGHTMOST_SET_BIT",
"pair": "python-java",
"Code1": "def fun ( n ) :\n return n & ( n - 1 )\n",
"Code2": "static int fun ( int n ) {\n return n & ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fun ( n ) :\n return n & ( n - 1 )\n\n"
},
{
"id": "python-java-FIND_MIRROR_IMAGE_POINT_2_D_PLANE",
"pair": "python-java",
"Code1": "def mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n",
"Code2": "static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) {\n double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ;\n double x = temp * a + x1 ;\n double y = temp * b + y1 ;\n return new pair ( x , y ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef mirrorImage ( a , b , c , x1 , y1 ) :\n temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b )\n x = temp * a + x1\n y = temp * b + y1\n return ( x , y )\n\n"
},
{
"id": "python-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_1",
"pair": "python-java",
"Code1": "def printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "static void printDistinct ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n arr.sort ( )\n for i in range ( n ) :\n if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :\n while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) :\n i += 1\n else :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-UNION_AND_INTERSECTION_OF_TWO_SORTED_ARRAYS_2_1",
"pair": "python-java",
"Code1": "def printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n",
"Code2": "static void printIntersection ( int arr1 [ ] , int arr2 [ ] , int m , int n ) {\n int i = 0 , j = 0 ;\n while ( i < m && j < n ) {\n if ( arr1 [ i ] < arr2 [ j ] ) i ++ ;\n else if ( arr2 [ j ] < arr1 [ i ] ) j ++ ;\n else {\n System . out . print ( arr2 [ j ++ ] + \" \" ) ;\n i ++ ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printIntersection ( arr1 , arr2 , m , n ) :\n i , j = 0 , 0\n while i < m and j < n :\n if arr1 [ i ] < arr2 [ j ] :\n i += 1\n elif arr2 [ j ] < arr1 [ i ] :\n j += 1\n else :\n print ( arr2 [ j ] )\n j += 1\n i += 1\n\n"
},
{
"id": "python-java-SEARCHING_ARRAY_ADJACENT_DIFFER_K",
"pair": "python-java",
"Code1": "def search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n",
"Code2": "static int search ( int arr [ ] , int n , int x , int k ) {\n int i = 0 ;\n while ( i < n ) {\n if ( arr [ i ] == x ) return i ;\n i = i + Math . max ( 1 , Math . abs ( arr [ i ] - x ) / k ) ;\n }\n System . out . println ( \"number is \" + \"not present!\" ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x , k ) :\n i = 0\n while ( i < n ) :\n if ( arr [ i ] == x ) :\n return i\n i = i + max ( 1 , int ( abs ( arr [ i ] - x ) / k ) )\n print ( \"number is not present!\" )\n return - 1\n\n"
},
{
"id": "python-java-REARRANGE_A_STRING_IN_SORTED_ORDER_FOLLOWED_BY_THE_INTEGER_SUM",
"pair": "python-java",
"Code1": "def arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n",
"Code2": "static String arrangeString ( String str ) {\n int char_count [ ] = new int [ MAX_CHAR ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) char_count [ str . charAt ( i ) - ' A ' ] ++ ;\n else sum = sum + ( str . charAt ( i ) - ' 0 ' ) ;\n }\n String res = \"\" ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) {\n char ch = ( char ) ( ' A ' + i ) ;\n while ( char_count [ i ] -- != 0 ) res = res + ch ;\n }\n if ( sum > 0 ) res = res + sum ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arrangeString ( string ) :\n char_count = [ 0 ] * MAX_CHAR\n s = 0\n for i in range ( len ( string ) ) :\n if string [ i ] >= \"A\" and string [ i ] <= \"Z\" :\n char_count [ ord ( string [ i ] ) - ord ( \"A\" ) ] += 1\n else :\n s += ord ( string [ i ] ) - ord ( \"0\" )\n res = \"\"\n for i in range ( MAX_CHAR ) :\n ch = chr ( ord ( \"A\" ) + i )\n while char_count [ i ] :\n res += ch\n char_count [ i ] -= 1\n if s > 0 :\n res += str ( s )\n return res\n\n"
},
{
"id": "python-java-COUNT_NUMBER_BINARY_STRINGS_WITHOUT_CONSECUTIVE_1S",
"pair": "python-java",
"Code1": "def countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n",
"Code2": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] ;\n int b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n return a [ n - 1 ] + b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countStrings ( n ) :\n a = [ 0 for i in range ( n ) ]\n b = [ 0 for i in range ( n ) ]\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return a [ n - 1 ] + b [ n - 1 ]\n\n"
},
{
"id": "python-java-MINIMUM_SUM_SUBSEQUENCE_LEAST_ONE_EVERY_FOUR_CONSECUTIVE_ELEMENTS_PICKED",
"pair": "python-java",
"Code1": "def minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n",
"Code2": "static int minSum ( int [ ] arr , int n ) {\n int [ ] dp = new int [ n ] ;\n if ( n == 1 ) return arr [ 0 ] ;\n if ( n == 2 ) return Math . min ( arr [ 0 ] , arr [ 1 ] ) ;\n if ( n == 3 ) return Math . min ( arr [ 0 ] , Math . min ( arr [ 1 ] , arr [ 2 ] ) ) ;\n if ( n == 4 ) return Math . min ( Math . min ( arr [ 0 ] , arr [ 1 ] ) , Math . min ( arr [ 2 ] , arr [ 3 ] ) ) ;\n dp [ 0 ] = arr [ 0 ] ;\n dp [ 1 ] = arr [ 1 ] ;\n dp [ 2 ] = arr [ 2 ] ;\n dp [ 3 ] = arr [ 3 ] ;\n for ( int i = 4 ;\n i < n ;\n i ++ ) dp [ i ] = arr [ i ] + Math . min ( Math . min ( dp [ i - 1 ] , dp [ i - 2 ] ) , Math . min ( dp [ i - 3 ] , dp [ i - 4 ] ) ) ;\n return Math . min ( Math . min ( dp [ n - 1 ] , dp [ n - 2 ] ) , Math . min ( dp [ n - 4 ] , dp [ n - 3 ] ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSum ( arr , n ) :\n dp = [ 0 ] * n\n if ( n == 1 ) :\n return arr [ 0 ]\n if ( n == 2 ) :\n return min ( arr [ 0 ] , arr [ 1 ] )\n if ( n == 3 ) :\n return min ( arr [ 0 ] , min ( arr [ 1 ] , arr [ 2 ] ) )\n if ( n == 4 ) :\n return min ( min ( arr [ 0 ] , arr [ 1 ] ) , min ( arr [ 2 ] , arr [ 3 ] ) )\n dp [ 0 ] = arr [ 0 ]\n dp [ 1 ] = arr [ 1 ]\n dp [ 2 ] = arr [ 2 ]\n dp [ 3 ] = arr [ 3 ]\n for i in range ( 4 , n ) :\n dp [ i ] = arr [ i ] + min ( min ( dp [ i - 1 ] , dp [ i - 2 ] ) , min ( dp [ i - 3 ] , dp [ i - 4 ] ) )\n return min ( min ( dp [ n - 1 ] , dp [ n - 2 ] ) , min ( dp [ n - 4 ] , dp [ n - 3 ] ) )\n\n"
},
{
"id": "python-java-CONVERT_SENTENCE_EQUIVALENT_MOBILE_NUMERIC_KEYPAD_SEQUENCE",
"pair": "python-java",
"Code1": "def printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n",
"Code2": "static String printSequence ( String arr [ ] , String input ) {\n String output = \"\" ;\n int n = input . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( input . charAt ( i ) == ' ▁ ' ) output = output + \"0\" ;\n else {\n int position = input . charAt ( i ) - ' A ' ;\n output = output + arr [ position ] ;\n }\n }\n return output ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSequence ( arr , input ) :\n n = len ( input )\n output = \"\"\n for i in range ( n ) :\n if ( input [ i ] == ' ' ) :\n output = output + \"0\"\n else :\n position = ord ( input [ i ] ) - ord ( 'A' )\n output = output + arr [ position ]\n return output\n\n"
},
{
"id": "python-java-ROTATE_MATRIX_ELEMENTS",
"pair": "python-java",
"Code1": "def rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n",
"Code2": "static void rotatematrix ( int m , int n , int mat [ ] [ ] ) {\n int row = 0 , col = 0 ;\n int prev , curr ;\n while ( row < m && col < n ) {\n if ( row + 1 == m || col + 1 == n ) break ;\n prev = mat [ row + 1 ] [ col ] ;\n for ( int i = col ;\n i < n ;\n i ++ ) {\n curr = mat [ row ] [ i ] ;\n mat [ row ] [ i ] = prev ;\n prev = curr ;\n }\n row ++ ;\n for ( int i = row ;\n i < m ;\n i ++ ) {\n curr = mat [ i ] [ n - 1 ] ;\n mat [ i ] [ n - 1 ] = prev ;\n prev = curr ;\n }\n n -- ;\n if ( row < m ) {\n for ( int i = n - 1 ;\n i >= col ;\n i -- ) {\n curr = mat [ m - 1 ] [ i ] ;\n mat [ m - 1 ] [ i ] = prev ;\n prev = curr ;\n }\n }\n m -- ;\n if ( col < n ) {\n for ( int i = m - 1 ;\n i >= row ;\n i -- ) {\n curr = mat [ i ] [ col ] ;\n mat [ i ] [ col ] = prev ;\n prev = curr ;\n }\n }\n col ++ ;\n }\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rotateMatrix ( mat ) :\n if not len ( mat ) :\n return\n top = 0\n bottom = len ( mat ) - 1\n left = 0\n right = len ( mat [ 0 ] ) - 1\n while left < right and top < bottom :\n prev = mat [ top + 1 ] [ left ]\n for i in range ( left , right + 1 ) :\n curr = mat [ top ] [ i ]\n mat [ top ] [ i ] = prev\n prev = curr\n top += 1\n for i in range ( top , bottom + 1 ) :\n curr = mat [ i ] [ right ]\n mat [ i ] [ right ] = prev\n prev = curr\n right -= 1\n for i in range ( right , left - 1 , - 1 ) :\n curr = mat [ bottom ] [ i ]\n mat [ bottom ] [ i ] = prev\n prev = curr\n bottom -= 1\n for i in range ( bottom , top - 1 , - 1 ) :\n curr = mat [ i ] [ left ]\n mat [ i ] [ left ] = prev\n prev = curr\n left += 1\n return mat\n\n"
},
{
"id": "python-java-MAXIMUM_BINOMIAL_COEFFICIENT_TERM_VALUE",
"pair": "python-java",
"Code1": "def maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n",
"Code2": "static int maxcoefficientvalue ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int maxvalue = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) maxvalue = Math . max ( maxvalue , C [ n ] [ i ] ) ;\n return maxvalue ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxcoefficientvalue ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for j in range ( min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n maxvalue = 0\n for i in range ( n + 1 ) :\n maxvalue = max ( maxvalue , C [ n ] [ i ] )\n return maxvalue\n\n"
},
{
"id": "python-java-PROGRAM_FIND_GCD_FLOATING_POINT_NUMBERS",
"pair": "python-java",
"Code1": "def gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n",
"Code2": "static double gcd ( double a , double b ) {\n if ( a < b ) return gcd ( b , a ) ;\n if ( Math . abs ( b ) < 0.001 ) return a ;\n else return ( gcd ( b , a - Math . floor ( a / b ) * b ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a < b ) :\n return gcd ( b , a )\n if ( abs ( b ) < 0.001 ) :\n return a\n else :\n return ( gcd ( b , a - math.floor ( a / b ) * b ) )\n\n"
},
{
"id": "python-java-SORT_STRING_ACCORDING_ORDER_DEFINED_ANOTHER_STRING",
"pair": "python-java",
"Code1": "def sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n",
"Code2": "static void sortByPattern ( char [ ] str , char [ ] pat ) {\n int count [ ] = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n count [ str [ i ] - ' a ' ] ++ ;\n }\n int index = 0 ;\n for ( int i = 0 ;\n i < pat . length ;\n i ++ ) {\n for ( int j = 0 ;\n j < count [ pat [ i ] - ' a ' ] ;\n j ++ ) {\n str [ index ++ ] = pat [ i ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortByPattern ( str , pat ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( str ) ) :\n count [ ord ( str [ i ] ) - 97 ] += 1\n index = 0\n str = \"\"\n for i in range ( 0 , len ( pat ) ) :\n j = 0\n while ( j < count [ ord ( pat [ i ] ) - ord ( 'a' ) ] ) :\n str += pat [ i ]\n j = j + 1\n index += 1\n return str\n\n"
},
{
"id": "python-java-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM_SET_2_O1_EXTRA_SPACE",
"pair": "python-java",
"Code1": "def rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n",
"Code2": "public static void rearrange ( int arr [ ] , int n ) {\n int max_idx = n - 1 , min_idx = 0 ;\n int max_elem = arr [ n - 1 ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) {\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem ;\n max_idx -- ;\n }\n else {\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem ;\n min_idx ++ ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = arr [ i ] / max_elem ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n max_idx = n - 1\n min_idx = 0\n max_elem = arr [ n - 1 ] + 1\n for i in range ( 0 , n ) :\n if i % 2 == 0 :\n arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem\n max_idx -= 1\n else :\n arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem\n min_idx += 1\n for i in range ( 0 , n ) :\n arr [ i ] = arr [ i ] / max_elem\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY_1",
"pair": "python-java",
"Code1": "def minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n",
"Code2": "private static int minJumps ( int [ ] arr , int n ) {\n int jumps [ ] = new int [ n ] ;\n int i , j ;\n if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ;\n jumps [ 0 ] = 0 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) {\n jumps [ i ] = Integer . MAX_VALUE ;\n for ( j = 0 ;\n j < i ;\n j ++ ) {\n if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) {\n jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ;\n break ;\n }\n }\n }\n return jumps [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , n ) :\n jumps = [ 0 for i in range ( n ) ]\n if ( n == 0 ) or ( arr [ 0 ] == 0 ) :\n return float ( 'inf' )\n jumps [ 0 ] = 0\n for i in range ( 1 , n ) :\n jumps [ i ] = float ( 'inf' )\n for j in range ( i ) :\n if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( 'inf' ) ) :\n jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 )\n break\n return jumps [ n - 1 ]\n\n"
},
{
"id": "python-java-PROBABILITY_REACHING_POINT_2_3_STEPS_TIME",
"pair": "python-java",
"Code1": "def find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n",
"Code2": "static float find_prob ( int N , float P ) {\n double dp [ ] = new double [ N + 1 ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 0 ;\n dp [ 2 ] = P ;\n dp [ 3 ] = 1 - P ;\n for ( int i = 4 ;\n i <= N ;\n ++ i ) dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ] ;\n return ( ( float ) ( dp [ N ] ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find_prob ( N , P ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 1\n dp [ 1 ] = 0\n dp [ 2 ] = P\n dp [ 3 ] = 1 - P\n for i in range ( 4 , N + 1 ) :\n dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]\n return dp [ N ]\n\n"
},
{
"id": "python-java-COUNT_WAYS_INCREASE_LCS_LENGTH_TWO_STRINGS_ONE",
"pair": "python-java",
"Code1": "def waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n",
"Code2": "static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) {\n int m = str1 . length ( ) , n = str2 . length ( ) ;\n Vector < Integer > [ ] position = new Vector [ M ] ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) position [ i ] = new Vector < > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ;\n int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ;\n int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ;\n for ( int i = 0 ;\n i <= m + 1 ;\n i ++ ) for ( int j = 0 ;\n j <= n + 1 ;\n j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ;\n else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ;\n }\n }\n for ( int i = m ;\n i >= 1 ;\n i -- ) {\n for ( int j = n ;\n j >= 1 ;\n j -- ) {\n if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ;\n else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ;\n }\n }\n int ways = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( char d = 0 ;\n d < 26 ;\n d ++ ) {\n for ( int j = 0 ;\n j < position [ d ] . size ( ) ;\n j ++ ) {\n int p = position [ d ] . elementAt ( j ) ;\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ;\n }\n }\n }\n return ways ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef waysToIncreaseLCSBy1 ( str1 , str2 ) :\n m = len ( str1 )\n n = len ( str2 )\n position = [ [ ] for i in range ( M ) ]\n for i in range ( 1 , n + 1 , 1 ) :\n position [ ord ( str2 [ i - 1 ] ) - 97 ].append ( i )\n lcsl = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n lcsr = [ [ 0 for i in range ( n + 2 ) ] for j in range ( m + 2 ) ]\n for i in range ( 1 , m + 1 , 1 ) :\n for j in range ( 1 , n + 1 , 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ]\n else :\n lcsl [ i ] [ j ] = max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] )\n for i in range ( m , 0 , - 1 ) :\n for j in range ( n , 0 , - 1 ) :\n if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :\n lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ]\n else :\n lcsr [ i ] [ j ] = max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] )\n ways = 0\n for i in range ( 0 , m + 1 , 1 ) :\n for C in range ( 0 , 26 , 1 ) :\n for j in range ( 0 , len ( position [ C ] ) , 1 ) :\n p = position [ C ] [ j ]\n if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) :\n ways += 1\n return ways\n\n"
},
{
"id": "python-java-LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "python-java",
"Code1": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n\n"
},
{
"id": "python-java-STERN_BROCOT_SEQUENCE",
"pair": "python-java",
"Code1": "def SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n",
"Code2": "static void SternSequenceFunc ( Vector < Integer > BrocotSequence , int n ) {\n for ( int i = 1 ;\n BrocotSequence . size ( ) < n ;\n i ++ ) {\n int considered_element = BrocotSequence . get ( i ) ;\n int precedent = BrocotSequence . get ( i - 1 ) ;\n BrocotSequence . add ( considered_element + precedent ) ;\n BrocotSequence . add ( considered_element ) ;\n }\n for ( int i = 0 ;\n i < 15 ;\n ++ i ) System . out . print ( BrocotSequence . get ( i ) + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef SternSequenceFunc ( BrocotSequence , n ) :\n for i in range ( 1 , n ) :\n considered_element = BrocotSequence [ i ]\n precedent = BrocotSequence [ i - 1 ]\n BrocotSequence.append ( considered_element + precedent )\n BrocotSequence.append ( considered_element )\n for i in range ( 0 , 15 ) :\n print ( BrocotSequence [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-PRUFER_CODE_TREE_CREATION",
"pair": "python-java",
"Code1": "def printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n",
"Code2": "static void printTreeEdges ( int prufer [ ] , int m ) {\n int vertices = m + 2 ;\n int vertex_set [ ] = new int [ vertices ] ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) vertex_set [ i ] = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) vertex_set [ prufer [ i ] - 1 ] += 1 ;\n System . out . print ( \"\\nThe edge set E(G) is :\\n\" ) ;\n int j = 0 ;\n for ( int i = 0 ;\n i < vertices - 2 ;\n i ++ ) {\n for ( j = 0 ;\n j < vertices ;\n j ++ ) {\n if ( vertex_set [ j ] == 0 ) {\n vertex_set [ j ] = - 1 ;\n System . out . print ( \"(\" + ( j + 1 ) + \", \" + prufer [ i ] + \") \" ) ;\n vertex_set [ prufer [ i ] - 1 ] -- ;\n break ;\n }\n }\n }\n j = 0 ;\n for ( int i = 0 ;\n i < vertices ;\n i ++ ) {\n if ( vertex_set [ i ] == 0 && j == 0 ) {\n System . out . print ( \"(\" + ( i + 1 ) + \", \" ) ;\n j ++ ;\n }\n else if ( vertex_set [ i ] == 0 && j == 1 ) System . out . print ( ( i + 1 ) + \")\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printTreeEdges ( prufer , m ) :\n vertices = m + 2\n vertex_set = [ 0 ] * vertices\n for i in range ( vertices - 2 ) :\n vertex_set [ prufer [ i ] - 1 ] += 1\n print ( \"The edge set E(G) is :\" )\n j = 0\n for i in range ( vertices - 2 ) :\n for j in range ( vertices ) :\n if ( vertex_set [ j ] == 0 ) :\n vertex_set [ j ] = - 1\n print ( \"(\" , ( j + 1 ) , \", \" , prufer [ i ] , \") \" , sep = \"\" , end = \"\" )\n vertex_set [ prufer [ i ] - 1 ] -= 1\n break\n j = 0\n for i in range ( vertices ) :\n if ( vertex_set [ i ] == 0 and j == 0 ) :\n print ( \"(\" , ( i + 1 ) , \", \" , sep = \"\" , end = \"\" )\n j += 1\n elif ( vertex_set [ i ] == 0 and j == 1 ) :\n print ( ( i + 1 ) , \")\" )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_DECODINGS_GIVEN_DIGIT_SEQUENCE_1",
"pair": "python-java",
"Code1": "def countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n",
"Code2": "static int countDecodingDP ( char digits [ ] , int n ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 1 ;\n count [ 1 ] = 1 ;\n if ( digits [ 0 ] == ' 0 ' ) return 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n count [ i ] = 0 ;\n if ( digits [ i - 1 ] > ' 0 ' ) count [ i ] = count [ i - 1 ] ;\n if ( digits [ i - 2 ] == ' 1 ' || ( digits [ i - 2 ] == ' 2 ' && digits [ i - 1 ] < ' 7 ' ) ) count [ i ] += count [ i - 2 ] ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDecodingDP ( digits , n ) :\n count = [ 0 ] * ( n + 1 )\n count [ 0 ] = 1\n count [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n count [ i ] = 0\n if ( digits [ i - 1 ] > '0' ) :\n count [ i ] = count [ i - 1 ]\n if ( digits [ i - 2 ] == '1' or ( digits [ i - 2 ] == '2' and digits [ i - 1 ] < '7' ) ) :\n count [ i ] += count [ i - 2 ]\n return count [ n ]\n\n"
},
{
"id": "python-java-COUNT_STRINGS_WITH_CONSECUTIVE_1S",
"pair": "python-java",
"Code1": "def countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n",
"Code2": "static int countStrings ( int n ) {\n int a [ ] = new int [ n ] , b [ ] = new int [ n ] ;\n a [ 0 ] = b [ 0 ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n a [ i ] = a [ i - 1 ] + b [ i - 1 ] ;\n b [ i ] = a [ i - 1 ] ;\n }\n from 2 ^ n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countStrings ( n ) :\n a = [ 0 ] * n\n b = [ 0 ] * n\n a [ 0 ] = b [ 0 ] = 1\n for i in range ( 1 , n ) :\n a [ i ] = a [ i - 1 ] + b [ i - 1 ]\n b [ i ] = a [ i - 1 ]\n return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]\n\n"
},
{
"id": "python-java-MAXIMUM_NUMBER_SEGMENTS_LENGTHS_B_C",
"pair": "python-java",
"Code1": "def maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n",
"Code2": "static int maximumSegments ( int n , int a , int b , int c ) {\n int dp [ ] = new int [ n + 10 ] ;\n Arrays . fill ( dp , - 1 ) ;\n dp [ 0 ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( dp [ i ] != - 1 ) {\n if ( i + a <= n ) dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ;\n if ( i + b <= n ) dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ;\n if ( i + c <= n ) dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ;\n }\n }\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumSegments ( n , a , b , c ) :\n dp = [ - 1 ] * ( n + 10 )\n dp [ 0 ] = 0\n for i in range ( 0 , n ) :\n if ( dp [ i ] != - 1 ) :\n if ( i + a <= n ) :\n dp [ i + a ] = max ( dp [ i ] + 1 , dp [ i + a ] )\n if ( i + b <= n ) :\n dp [ i + b ] = max ( dp [ i ] + 1 , dp [ i + b ] )\n if ( i + c <= n ) :\n dp [ i + c ] = max ( dp [ i ] + 1 , dp [ i + c ] )\n return dp [ n ]\n\n"
},
{
"id": "python-java-PRINT_BRACKET_NUMBER",
"pair": "python-java",
"Code1": "def printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n",
"Code2": "static void printBracketNumber ( String exp , int n ) {\n int left_bnum = 1 ;\n Stack < Integer > right_bnum = new Stack < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( exp . charAt ( i ) == ' ( ' ) {\n System . out . print ( left_bnum + \" \" ) ;\n right_bnum . push ( left_bnum ) ;\n left_bnum ++ ;\n }\n else if ( exp . charAt ( i ) == ' ) ' ) {\n System . out . print ( right_bnum . peek ( ) + \" \" ) ;\n right_bnum . pop ( ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printBracketNumber ( exp , n ) :\n left_bnum = 1\n right_bnum = list ( )\n for i in range ( n ) :\n if exp [ i ] == '(' :\n print ( left_bnum , end = \" \" )\n right_bnum.append ( left_bnum )\n left_bnum += 1\n elif exp [ i ] == ')' :\n print ( right_bnum [ - 1 ] , end = \" \" )\n right_bnum.pop ( )\n\n"
},
{
"id": "python-java-COUNT_WORDS_WHOSE_TH_LETTER_EITHER_1_TH_TH_I1_TH_LETTER_GIVEN_WORD",
"pair": "python-java",
"Code1": "def countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n",
"Code2": "static int countWords ( String str , int len ) {\n int count = 1 ;\n if ( len == 1 ) return count ;\n if ( str . charAt ( 0 ) == str . charAt ( 1 ) ) count *= 1 ;\n else count *= 2 ;\n for ( int j = 1 ;\n j < len - 1 ;\n j ++ ) {\n if ( str . charAt ( j ) == str . charAt ( j - 1 ) && str . charAt ( j ) == str . charAt ( j + 1 ) ) count *= 1 ;\n else if ( str . charAt ( j ) == str . charAt ( j - 1 ) || str . charAt ( j ) == str . charAt ( j + 1 ) || str . charAt ( j - 1 ) == str . charAt ( j + 1 ) ) count *= 2 ;\n else count *= 3 ;\n }\n if ( str . charAt ( len - 1 ) == str . charAt ( len - 2 ) ) count *= 1 ;\n else count *= 2 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWords ( str , l ) :\n count = 1 ;\n if ( l == 1 ) :\n return count\n if ( str [ 0 ] == str [ 1 ] ) :\n count *= 1\n else :\n count *= 2\n for j in range ( 1 , l - 1 ) :\n if ( str [ j ] == str [ j - 1 ] and str [ j ] == str [ j + 1 ] ) :\n count *= 1\n elif ( str [ j ] == str [ j - 1 ] or str [ j ] == str [ j + 1 ] or str [ j - 1 ] == str [ j + 1 ] ) :\n count *= 2\n else :\n count *= 3\n if ( str [ l - 1 ] == str [ l - 2 ] ) :\n count *= 1\n else :\n count *= 2\n return count\n\n"
},
{
"id": "python-java-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY",
"pair": "python-java",
"Code1": "def largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n",
"Code2": "static int largest ( ) {\n int i ;\n int max = arr [ 0 ] ;\n for ( i = 1 ;\n i < arr . length ;\n i ++ ) if ( arr [ i ] > max ) max = arr [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largest ( arr , n ) :\n max = arr [ 0 ]\n for i in range ( 1 , n ) :\n if arr [ i ] > max :\n max = arr [ i ]\n return max\n\n"
},
{
"id": "python-java-FIND_MINIMUM_DIFFERENCE_PAIR",
"pair": "python-java",
"Code1": "def findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n",
"Code2": "static int findMinDiff ( int [ ] arr , int n ) {\n int diff = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ;\n return diff ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinDiff ( arr , n ) :\n diff = 10 ** 20\n for i in range ( n - 1 ) :\n for j in range ( i + 1 , n ) :\n if abs ( arr [ i ] - arr [ j ] ) < diff :\n diff = abs ( arr [ i ] - arr [ j ] )\n return diff\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_IARRI_AMONG_ROTATIONS_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n",
"Code2": "static int maxSum ( int arr [ ] , int n ) {\n int res = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n int index = ( i + j ) % n ;\n curr_sum += j * arr [ index ] ;\n }\n res = Math . max ( res , curr_sum ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( arr , n ) :\n res = - sys.maxsize\n for i in range ( 0 , n ) :\n curr_sum = 0\n for j in range ( 0 , n ) :\n index = int ( ( i + j ) % n )\n curr_sum += j * arr [ index ]\n res = max ( res , curr_sum )\n return res\n\n"
},
{
"id": "python-java-PROGRAM_CALCULATE_VOLUME_ELLIPSOID",
"pair": "python-java",
"Code1": "def volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n",
"Code2": "public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) {\n float pi = ( float ) 3.14 ;\n return ( float ) 1.33 * pi * r1 * r2 * r3 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef volumeOfEllipsoid ( r1 , r2 , r3 ) :\n return 1.33 * math.pi * r1 * r2 * r3\n\n"
},
{
"id": "python-java-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS",
"pair": "python-java",
"Code1": "def lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n",
"Code2": "static int lcsOf3 ( String X , String Y , String Z , int m , int n , int o ) {\n int [ ] [ ] [ ] L = new int [ m + 1 ] [ n + 1 ] [ o + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n for ( int k = 0 ;\n k <= o ;\n k ++ ) {\n if ( i == 0 || j == 0 || k == 0 ) L [ i ] [ j ] [ k ] = 0 ;\n else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) && X . charAt ( i - 1 ) == Z . charAt ( k - 1 ) ) L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1 ;\n else L [ i ] [ j ] [ k ] = Math . max ( Math . max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] ) ;\n }\n }\n }\n return L [ m ] [ n ] [ o ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lcsOf3 ( X , Y , Z , m , n , o ) :\n L = [ [ [ 0 for i in range ( o + 1 ) ] for j in range ( n + 1 ) ] for k in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n for k in range ( o + 1 ) :\n if ( i == 0 or j == 0 or k == 0 ) :\n L [ i ] [ j ] [ k ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] and X [ i - 1 ] == Z [ k - 1 ] ) :\n L [ i ] [ j ] [ k ] = L [ i - 1 ] [ j - 1 ] [ k - 1 ] + 1\n else :\n L [ i ] [ j ] [ k ] = max ( max ( L [ i - 1 ] [ j ] [ k ] , L [ i ] [ j - 1 ] [ k ] ) , L [ i ] [ j ] [ k - 1 ] )\n return L [ m ] [ n ] [ o ]\n\n"
},
{
"id": "python-java-FIND_NUMBER_ENDLESS_POINTS",
"pair": "python-java",
"Code1": "def countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n",
"Code2": "static int countEndless ( boolean input [ ] [ ] , int n ) {\n boolean row [ ] [ ] = new boolean [ n ] [ n ] ;\n boolean col [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n boolean isEndless = true ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n col [ i ] [ j ] = isEndless ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n boolean isEndless = true ;\n for ( int j = n - 1 ;\n j >= 0 ;\n j -- ) {\n if ( input [ i ] [ j ] == false ) isEndless = false ;\n row [ i ] [ j ] = isEndless ;\n }\n }\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n j < n ;\n j ++ ) if ( row [ i ] [ j ] && col [ i ] [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countEndless ( input_mat , n ) :\n row = np.zeros ( ( n , n ) )\n col = np.zeros ( ( n , n ) )\n for j in range ( n ) :\n isEndless = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n col [ i ] [ j ] = isEndless\n for i in range ( n ) :\n isEndless = 1\n for j in range ( n - 1 , - 1 , - 1 ) :\n if ( input_mat [ i ] [ j ] == 0 ) :\n isEndless = 0\n row [ i ] [ j ] = isEndless\n ans = 0\n for i in range ( n ) :\n for j in range ( 1 , n ) :\n if ( row [ i ] [ j ] and col [ i ] [ j ] ) :\n ans += 1\n return ans\n\n"
},
{
"id": "python-java-PROGRAM_NEXT_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-java",
"Code1": "def NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "static void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] , j = 0 ;\n Arrays . fill ( allocation , - 1 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < m ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n allocation [ i ] = j ;\n blockSize [ j ] -= processSize [ i ] ;\n break ;\n }\n j = ( j + 1 ) % m ;\n }\n }\n System . out . print ( \"\\nProcess No.\\tProcess Size\\tBlock no.\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( i + 1 + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) {\n System . out . print ( allocation [ i ] + 1 ) ;\n }\n else {\n System . out . print ( \"Not Allocated\" ) ;\n }\n System . out . println ( \"\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef NextFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n j = 0\n for i in range ( n ) :\n while j < m :\n if blockSize [ j ] >= processSize [ i ] :\n allocation [ i ] = j\n blockSize [ j ] -= processSize [ i ]\n break\n j = ( j + 1 ) % m\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-java-LONGEST_GEOMETRIC_PROGRESSION",
"pair": "python-java",
"Code1": "def lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n",
"Code2": "static int lenOfLongestGP ( int set [ ] , int n ) {\n if ( n < 2 ) {\n return n ;\n }\n if ( n == 2 ) {\n return ( set [ 1 ] % set [ 0 ] == 0 ? 1 : 0 ) ;\n }\n Arrays . sort ( set ) ;\n int L [ ] [ ] = new int [ n ] [ n ] ;\n int llgp = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n if ( set [ n - 1 ] % set [ i ] == 0 ) {\n L [ i ] [ n - 1 ] = 2 ;\n }\n else {\n L [ i ] [ n - 1 ] = 1 ;\n }\n }\n for ( int j = n - 2 ;\n j >= 1 ;\n -- j ) {\n int i = j - 1 , k = j + 1 ;\n while ( i >= 0 && k <= n - 1 ) {\n if ( set [ i ] * set [ k ] < set [ j ] * set [ j ] ) {\n ++ k ;\n }\n else if ( set [ i ] * set [ k ] > set [ j ] * set [ j ] ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n else {\n L [ i ] [ j ] = L [ j ] [ k ] + 1 ;\n if ( L [ i ] [ j ] > llgp ) {\n llgp = L [ i ] [ j ] ;\n }\n -- i ;\n ++ k ;\n }\n }\n while ( i >= 0 ) {\n if ( set [ j ] % set [ i ] == 0 ) {\n L [ i ] [ j ] = 2 ;\n }\n else {\n L [ i ] [ j ] = 1 ;\n }\n -- i ;\n }\n }\n return llgp ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lenOfLongestGP ( sett , n ) :\n if n < 2 :\n return n\n if n == 2 :\n return ( sett [ 1 ] % sett [ 0 ] == 0 )\n sett.sort ( )\n L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n llgp = 1\n for i in range ( 0 , n ) :\n if sett [ n - 1 ] % sett [ i ] == 0 :\n L [ i ] [ n - 1 ] = 2\n else :\n L [ i ] [ n - 1 ] = 1\n for j in range ( n - 2 , 0 , - 1 ) :\n i = j - 1\n k = j + 1\n while i >= 0 and k <= n - 1 :\n if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :\n k += 1\n elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n else :\n L [ i ] [ j ] = L [ j ] [ k ] + 1\n if L [ i ] [ j ] > llgp :\n llgp = L [ i ] [ j ]\n i -= 1\n k + 1\n while i >= 0 :\n if sett [ j ] % sett [ i ] == 0 :\n L [ i ] [ j ] = 2\n else :\n L [ i ] [ j ] = 1\n i -= 1\n return llgp\n\n"
},
{
"id": "python-java-CHECK_WHETHER_TRIANGLE_VALID_NOT_SIDES_GIVEN",
"pair": "python-java",
"Code1": "def checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n",
"Code2": "public static int checkValidity ( int a , int b , int c ) {\n if ( a + b <= c || a + c <= b || b + c <= a ) return 0 ;\n else return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkValidity ( a , b , c ) :\n if ( a + b <= c ) or ( a + c <= b ) or ( b + c <= a ) :\n return False\n else :\n return True\n\n"
},
{
"id": "python-java-DIAGONALLY_DOMINANT_MATRIX",
"pair": "python-java",
"Code1": "def isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n",
"Code2": "static boolean isDDM ( int m [ ] [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += Math . abs ( m [ i ] [ j ] ) ;\n sum -= Math . abs ( m [ i ] [ i ] ) ;\n if ( Math . abs ( m [ i ] [ i ] ) < sum ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDDM ( m , n ) :\n for i in range ( 0 , n ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum = sum + abs ( m [ i ] [ j ] )\n sum = sum - abs ( m [ i ] [ i ] )\n if ( abs ( m [ i ] [ i ] ) < sum ) :\n return False\n return True\n\n"
},
{
"id": "python-java-PROGRAM_TO_FIND_TRANSPOSE_OF_A_MATRIX",
"pair": "python-java",
"Code1": "def transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n",
"Code2": "static void transpose ( int A [ ] [ ] , int B [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) B [ i ] [ j ] = A [ j ] [ i ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef transpose ( A , B ) :\n for i in range ( N ) :\n for j in range ( N ) :\n B [ i ] [ j ] = A [ j ] [ i ]\n\n"
},
{
"id": "python-java-MAXIMUM_POSSIBLE_SUM_WINDOW_ARRAY_ELEMENTS_WINDOW_ARRAY_UNIQUE",
"pair": "python-java",
"Code1": "def returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n",
"Code2": "static int returnMaxSum ( int A [ ] , int B [ ] , int n ) {\n Set < Integer > mp = new HashSet < Integer > ( ) ;\n int result = 0 ;\n int curr_sum = 0 , curr_begin = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n while ( mp . contains ( A [ i ] ) ) {\n mp . remove ( A [ curr_begin ] ) ;\n curr_sum -= B [ curr_begin ] ;\n curr_begin ++ ;\n }\n mp . add ( A [ i ] ) ;\n curr_sum += B [ i ] ;\n result = Integer . max ( result , curr_sum ) ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef returnMaxSum ( A , B , n ) :\n mp = set ( )\n result = 0\n curr_sum = curr_begin = 0\n for i in range ( 0 , n ) :\n while A [ i ] in mp :\n mp.remove ( A [ curr_begin ] )\n curr_sum -= B [ curr_begin ]\n curr_begin += 1\n mp.add ( A [ i ] )\n curr_sum += B [ i ]\n result = max ( result , curr_sum )\n return result\n\n"
},
{
"id": "python-java-NUMBER_OF_PAIRS_IN_AN_ARRAY_HAVING_SUM_EQUAL_TO_PRODUCT",
"pair": "python-java",
"Code1": "def sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n",
"Code2": "static int sumEqualProduct ( int a [ ] , int n ) {\n int zero = 0 , two = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n zero ++ ;\n }\n if ( a [ i ] == 2 ) {\n two ++ ;\n }\n }\n int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2 ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumEqualProduct ( a , n ) :\n zero = 0\n two = 0\n for i in range ( n ) :\n if a [ i ] == 0 :\n zero += 1\n if a [ i ] == 2 :\n two += 1\n cnt = ( zero * ( zero - 1 ) ) // 2 + \\\n ( two * ( two - 1 ) ) // 2\n return cnt\n\n"
},
{
"id": "python-java-MULTISTAGE_GRAPH_SHORTEST_PATH",
"pair": "python-java",
"Code1": "def shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n",
"Code2": "public static int shortestDist ( int [ ] [ ] graph ) {\n int [ ] dist = new int [ N ] ;\n dist [ N - 1 ] = 0 ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n dist [ i ] = INF ;\n for ( int j = i ;\n j < N ;\n j ++ ) {\n if ( graph [ i ] [ j ] == INF ) {\n continue ;\n }\n dist [ i ] = Math . min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] ) ;\n }\n }\n return dist [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef shortestDist ( graph ) :\n global INF\n dist = [ 0 ] * N\n dist [ N - 1 ] = 0\n for i in range ( N - 2 , - 1 , - 1 ) :\n dist [ i ] = INF\n for j in range ( N ) :\n if graph [ i ] [ j ] == INF :\n continue\n dist [ i ] = min ( dist [ i ] , graph [ i ] [ j ] + dist [ j ] )\n return dist [ 0 ]\n\n"
},
{
"id": "python-java-SUM_OF_ALL_ELEMENTS_UP_TO_NTH_ROW_IN_A_PASCALS_TRIANGLE_1",
"pair": "python-java",
"Code1": "def calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n",
"Code2": "static long calculateSum ( int n ) {\n long sum = 0 ;\n sum = 1 << n ;\n return ( sum - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calculateSum ( n ) :\n sum = 0\n sum = 1 << n\n return ( sum - 1 )\n\n"
},
{
"id": "python-java-PRIMALITY_TEST_SET_1_INTRODUCTION_AND_SCHOOL_METHOD_1",
"pair": "python-java",
"Code1": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n",
"Code2": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n if ( n <= 3 ) return true ;\n if ( n % 2 == 0 || n % 3 == 0 ) return false ;\n for ( int i = 5 ;\n i * i <= n ;\n i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n if ( n <= 3 ) :\n return True\n if ( n % 2 == 0 or n % 3 == 0 ) :\n return False\n i = 5\n while ( i * i <= n ) :\n if ( n % i == 0 or n % ( i + 2 ) == 0 ) :\n return False\n i = i + 6\n return True\n\n"
},
{
"id": "python-java-PRINT_FIBONACCI_SEQUENCE_USING_2_VARIABLES_1",
"pair": "python-java",
"Code1": "def fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n",
"Code2": "static void fib ( int n ) {\n int a = 0 , b = 1 ;\n if ( n >= 0 ) System . out . print ( a + \" \" ) ;\n if ( n >= 1 ) System . out . print ( b + \" \" ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n System . out . print ( a + b + \" \" ) ;\n b = a + b ;\n a = b - a ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n a = 0\n b = 1\n if ( n >= 0 ) :\n print ( a , end = ' ' )\n if ( n >= 1 ) :\n print ( b , end = ' ' )\n for i in range ( 2 , n + 1 ) :\n print ( a + b , end = ' ' )\n b = a + b\n a = b - a\n\n"
},
{
"id": "python-java-K_TH_DIGIT_RAISED_POWER_B",
"pair": "python-java",
"Code1": "def kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n",
"Code2": "public static int kthdigit ( int a , int b , int k ) {\n int p = ( int ) Math . pow ( a , b ) ;\n int count = 0 ;\n while ( p > 0 && count < k ) {\n int rem = p % 10 ;\n count ++ ;\n if ( count == k ) return rem ;\n p = p / 10 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kthdigit ( a , b , k ) :\n p = a ** b\n count = 0\n while ( p > 0 and count < k ) :\n rem = p % 10\n count = count + 1\n if ( count == k ) :\n return rem\n p = p / 10\n\n"
},
{
"id": "python-java-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD_1",
"pair": "python-java",
"Code1": "def isEven ( n ) :\n return ( not ( n & 1 ) )\n",
"Code2": "public static boolean isEven ( int n ) {\n if ( ( n & 1 ) == 0 ) return true ;\n else return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isEven ( n ) :\n return ( not ( n & 1 ) )\n\n"
},
{
"id": "python-java-PRINT_SHORTEST_PATH_PRINT_STRING_SCREEN",
"pair": "python-java",
"Code1": "def printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n",
"Code2": "static void printPath ( String str ) {\n int i = 0 ;\n int curX = 0 , curY = 0 ;\n while ( i < str . length ( ) ) {\n int nextX = ( str . charAt ( i ) - ' A ' ) / 5 ;\n int nextY = ( str . charAt ( i ) - ' B ' + 1 ) % 5 ;\n while ( curX > nextX ) {\n System . out . println ( \"Move Up\" ) ;\n curX -- ;\n }\n while ( curY > nextY ) {\n System . out . println ( \"Move Left\" ) ;\n curY -- ;\n }\n while ( curX < nextX ) {\n System . out . println ( \"Move Down\" ) ;\n curX ++ ;\n }\n while ( curY < nextY ) {\n System . out . println ( \"Move Right\" ) ;\n curY ++ ;\n }\n System . out . println ( \"Press OK\" ) ;\n i ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printPath ( str ) :\n i = 0\n curX = 0\n curY = 0\n while ( i < len ( str ) ) :\n nextX = int ( ( ord ( str [ i ] ) - ord ( 'A' ) ) / 5 )\n nextY = ( ord ( str [ i ] ) - ord ( 'B' ) + 1 ) % 5\n while ( curX > nextX ) :\n print ( \"Move Up\" )\n curX -= 1\n while ( curY > nextY ) :\n print ( \"Move Left\" )\n curY -= 1\n while ( curX < nextX ) :\n print ( \"Move Down\" )\n curX += 1\n while ( curY < nextY ) :\n print ( \"Move Right\" )\n curY += 1\n print ( \"Press OK\" )\n i += 1\n\n"
},
{
"id": "python-java-CHECK_GIVEN_CIRCLE_LIES_COMPLETELY_INSIDE_RING_FORMED_TWO_CONCENTRIC_CIRCLES",
"pair": "python-java",
"Code1": "def checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n",
"Code2": "public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) {\n int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ;\n return ( dis - r1 >= R && dis + r1 <= r ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkcircle ( r , R , r1 , x1 , y1 ) :\n dis = int ( math.sqrt ( x1 * x1 + y1 * y1 ) )\n return ( dis - r1 >= R and dis + r1 <= r )\n\n"
},
{
"id": "python-java-GIVEN_LEVEL_ORDER_TRAVERSAL_BINARY_TREE_CHECK_TREE_MIN_HEAP",
"pair": "python-java",
"Code1": "def isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n",
"Code2": "static boolean isMinHeap ( int [ ] level ) {\n int n = level . length - 1 ;\n for ( int i = ( n / 2 - 1 ) ;\n i >= 0 ;\n i -- ) {\n if ( level [ i ] > level [ 2 * i + 1 ] ) return false ;\n if ( 2 * i + 2 < n ) {\n if ( level [ i ] > level [ 2 * i + 2 ] ) return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isMinHeap ( level , n ) :\n for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :\n if level [ i ] > level [ 2 * i + 1 ] :\n return False\n if 2 * i + 2 < n :\n if level [ i ] > level [ 2 * i + 2 ] :\n return False\n return True\n\n"
},
{
"id": "python-java-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS",
"pair": "python-java",
"Code1": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n",
"Code2": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > first ) first = arr [ i ] ;\n int second = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > second && arr [ i ] < first ) second = arr [ i ] ;\n int third = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < arr_size ;\n i ++ ) if ( arr [ i ] > third && arr [ i ] < second ) third = arr [ i ] ;\n System . out . printf ( \"The third Largest \" + \"element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n first = arr [ i ]\n second = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > second and arr [ i ] < first ) :\n second = arr [ i ]\n third = - sys.maxsize\n for i in range ( 0 , arr_size ) :\n if ( arr [ i ] > third and arr [ i ] < second ) :\n third = arr [ i ]\n print ( \"The Third Largest\" , \"element is\" , third )\n\n"
},
{
"id": "python-java-FIND_A_ROTATION_WITH_MAXIMUM_HAMMING_DISTANCE",
"pair": "python-java",
"Code1": "def maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n",
"Code2": "static int maxHamming ( int arr [ ] , int n ) {\n int brr [ ] = new int [ 2 * n + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) brr [ n + i ] = arr [ i ] ;\n int maxHam = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int currHam = 0 ;\n for ( int j = i , k = 0 ;\n j < ( i + n ) ;\n j ++ , k ++ ) if ( brr [ j ] != arr [ k ] ) currHam ++ ;\n if ( currHam == n ) return n ;\n maxHam = Math . max ( maxHam , currHam ) ;\n }\n return maxHam ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxHamming ( arr , n ) :\n brr = [ 0 ] * ( 2 * n + 1 )\n for i in range ( n ) :\n brr [ i ] = arr [ i ]\n for i in range ( n ) :\n brr [ n + i ] = arr [ i ]\n maxHam = 0\n for i in range ( 1 , n ) :\n currHam = 0\n k = 0\n for j in range ( i , i + n ) :\n if brr [ j ] != arr [ k ] :\n currHam += 1\n k = k + 1\n if currHam == n :\n return n\n maxHam = max ( maxHam , currHam )\n return maxHam\n\n"
},
{
"id": "python-java-FIND_SUM_MODULO_K_FIRST_N_NATURAL_NUMBER",
"pair": "python-java",
"Code1": "def findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n",
"Code2": "static int findSum ( int N , int K ) {\n int ans = 0 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) ans += ( i % K ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( N , K ) :\n ans = 0\n for i in range ( 1 , N + 1 ) :\n ans += ( i % K )\n return ans\n\n"
},
{
"id": "python-java-SUM_SERIES_23_45_67_89_UPTO_N_TERMS",
"pair": "python-java",
"Code1": "def seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n",
"Code2": "static double seriesSum ( int n ) {\n int i = 1 ;\n double res = 0.0 ;\n boolean sign = true ;\n while ( n > 0 ) {\n n -- ;\n if ( sign ) {\n sign = ! sign ;\n res = res + ( double ) ++ i / ++ i ;\n }\n else {\n sign = ! sign ;\n res = res - ( double ) ++ i / ++ i ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef seriesSum ( n ) :\n i = 1\n res = 0.0\n sign = True\n while ( n > 0 ) :\n n = n - 1\n if ( sign ) :\n sign = False\n res = res + ( i + 1 ) / ( i + 2 )\n i = i + 2\n else :\n sign = True\n res = res - ( i + 1 ) / ( i + 2 )\n i = i + 2\n return res\n\n"
},
{
"id": "python-java-COUNT_TOTAL_SET_BITS_IN_ALL_NUMBERS_FROM_1_TO_N",
"pair": "python-java",
"Code1": "def countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n",
"Code2": "static int countSetBits ( int n ) {\n int i = 0 ;\n int ans = 0 ;\n while ( ( 1 << i ) <= n ) {\n boolean k = false ;\n int change = 1 << i ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( k == true ) ans += 1 ;\n else ans += 0 ;\n if ( change == 1 ) {\n k = ! k ;\n change = 1 << i ;\n }\n else {\n change -- ;\n }\n }\n i ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n i = 0\n ans = 0\n while ( ( 1 << i ) <= n ) :\n k = 0\n change = 1 << i\n for j in range ( 0 , n + 1 ) :\n ans += k\n if change == 1 :\n k = not k\n change = 1 << i\n else :\n change -= 1\n i += 1\n return ans\n\n"
},
{
"id": "python-java-COUNT_PAIRS_WITH_GIVEN_SUM_1",
"pair": "python-java",
"Code1": "def getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n",
"Code2": "static int getPairsCount ( int n , int sum ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ;\n hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ;\n }\n int twice_count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ;\n if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ;\n }\n return twice_count / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getPairsCount ( arr , n , sum ) :\n m = [ 0 ] * 1000\n for i in range ( 0 , n ) :\n m [ arr [ i ] ]\n m [ arr [ i ] ] += 1\n twice_count = 0\n for i in range ( 0 , n ) :\n twice_count += m [ sum - arr [ i ] ]\n if ( sum - arr [ i ] == arr [ i ] ) :\n twice_count -= 1\n return int ( twice_count / 2 )\n\n"
},
{
"id": "python-java-PROGRAM_CHECK_DIAGONAL_MATRIX_SCALAR_MATRIX",
"pair": "python-java",
"Code1": "def isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n",
"Code2": "static boolean isDiagonalMatrix ( int mat [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDiagonalMatrix ( mat ) :\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) :\n return False\n return True\n\n"
},
{
"id": "python-java-SORT_3_INTEGERS_WITHOUT_USING_CONDITION_USING_MAX_FUNCTION",
"pair": "python-java",
"Code1": "def printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n",
"Code2": "static void printSorted ( int a , int b , int c ) {\n int get_max = Math . max ( a , Math . max ( b , c ) ) ;\n int get_min = - Math . max ( - a , Math . max ( - b , - c ) ) ;\n int get_mid = ( a + b + c ) - ( get_max + get_min ) ;\n System . out . print ( get_min + \" \" + get_mid + \" \" + get_max ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSorted ( a , b , c ) :\n get_max = max ( a , max ( b , c ) )\n get_min = - max ( - a , max ( - b , - c ) )\n get_mid = ( a + b + c ) - ( get_max + get_min )\n print ( get_min , \" \" , get_mid , \" \" , get_max )\n\n"
},
{
"id": "python-java-NUMBER_IS_DIVISIBLE_BY_29_OR_NOT",
"pair": "python-java",
"Code1": "def isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n",
"Code2": "static boolean isDivisible ( long n ) {\n while ( n / 100 > 0 ) {\n int last_digit = ( int ) n % 10 ;\n n /= 10 ;\n n += last_digit * 3 ;\n }\n return ( n % 29 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDivisible ( n ) :\n while ( int ( n / 100 ) ) :\n last_digit = int ( n % 10 )\n n = int ( n / 10 )\n n += last_digit * 3\n return ( n % 29 == 0 )\n\n"
},
{
"id": "python-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE",
"pair": "python-java",
"Code1": "def getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos",
"Code2": "static int getSingle ( int arr [ ] , int n ) {\n int ones = 0 , twos = 0 ;\n int common_bit_mask ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n twos = twos",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getSingle ( arr , n ) :\n ones = 0\n twos = 0\n for i in range ( n ) :\n twos = twos\n"
},
{
"id": "python-java-MINIMUM_SUM_PATH_TRIANGLE",
"pair": "python-java",
"Code1": "def minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n",
"Code2": "static int minSumPath ( ) {\n int [ ] memo = new int [ A . length ] ;\n int n = A . length - 1 ;\n for ( int i = 0 ;\n i < A [ n ] . length ;\n i ++ ) memo [ i ] = A [ n ] [ i ] ;\n for ( int i = A . length - 2 ;\n i >= 0 ;\n i -- ) for ( int j = 0 ;\n j < A [ i ] . length ;\n j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSumPath ( A ) :\n memo = [ None ] * len ( A )\n n = len ( A ) - 1\n for i in range ( len ( A [ n ] ) ) :\n memo [ i ] = A [ n ] [ i ]\n for i in range ( len ( A ) - 2 , - 1 , - 1 ) :\n for j in range ( len ( A [ i ] ) ) :\n memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;\n return memo [ 0 ]\n\n"
},
{
"id": "python-java-REARRANGE_POSITIVE_AND_NEGATIVE_NUMBERS_PUBLISH",
"pair": "python-java",
"Code1": "def rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n",
"Code2": "static void rearrange ( int arr [ ] , int n ) {\n int i = - 1 , temp = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] < 0 ) {\n i ++ ;\n temp = arr [ i ] ;\n arr [ i ] = arr [ j ] ;\n arr [ j ] = temp ;\n }\n }\n int pos = i + 1 , neg = 0 ;\n while ( pos < n && neg < pos && arr [ neg ] < 0 ) {\n temp = arr [ neg ] ;\n arr [ neg ] = arr [ pos ] ;\n arr [ pos ] = temp ;\n pos ++ ;\n neg += 2 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n i = - 1\n for j in range ( n ) :\n if ( arr [ j ] < 0 ) :\n i += 1\n arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]\n pos , neg = i + 1 , 0\n while ( pos < n and neg < pos and arr [ neg ] < 0 ) :\n arr [ neg ] , arr [ pos ] = arr [ pos ] , arr [ neg ]\n pos += 1\n neg += 2\n\n"
},
{
"id": "python-java-ELEMENTS_TO_BE_ADDED_SO_THAT_ALL_ELEMENTS_OF_A_RANGE_ARE_PRESENT_IN_ARRAY",
"pair": "python-java",
"Code1": "def countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n",
"Code2": "static int countNum ( int [ ] arr , int n ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNum ( arr , n ) :\n count = 0\n arr.sort ( )\n for i in range ( 0 , n - 1 ) :\n if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :\n count += arr [ i + 1 ] - arr [ i ] - 1\n return count\n\n"
},
{
"id": "python-java-LARGEST_SUBSEQUENCE_GCD_GREATER_1",
"pair": "python-java",
"Code1": "def largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n",
"Code2": "static int largestGCDSubsequence ( int arr [ ] , int n ) {\n int ans = 0 ;\n int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ;\n ;\n for ( int i = 2 ;\n i <= maxele ;\n ++ i ) {\n int count = 0 ;\n for ( int j = 0 ;\n j < n ;\n ++ j ) {\n if ( arr [ j ] % i == 0 ) ++ count ;\n }\n ans = Math . max ( ans , count ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largestGCDSubsequence ( arr , n ) :\n ans = 0\n maxele = max ( arr )\n for i in range ( 2 , maxele + 1 ) :\n count = 0\n for j in range ( n ) :\n if ( arr [ j ] % i == 0 ) :\n count += 1\n ans = max ( ans , count )\n return ans\n\n"
},
{
"id": "python-java-PROGRAM_CHECK_INPUT_INTEGER_STRING",
"pair": "python-java",
"Code1": "def isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n",
"Code2": "static boolean isNumber ( String s ) {\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) if ( Character . isDigit ( s . charAt ( i ) ) == false ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isNumber ( s ) :\n for i in range ( len ( s ) ) :\n if s [ i ].isdigit ( ) != True :\n return False\n return True\n\n"
},
{
"id": "python-java-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X_1",
"pair": "python-java",
"Code1": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n",
"Code2": "static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) {\n int count = 0 ;\n HashSet < Integer > us = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) us . add ( arr1 [ i ] ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n us = set ( )\n for i in range ( m ) :\n us.add ( arr1 [ i ] )\n for j in range ( n ) :\n if x - arr2 [ j ] in us :\n count += 1\n return count\n\n"
},
{
"id": "python-java-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS",
"pair": "python-java",
"Code1": "def CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n",
"Code2": "static int countSquares ( int a , int b ) {\n int cnt = 0 ;\n for ( int i = a ;\n i <= b ;\n i ++ ) for ( int j = 1 ;\n j * j <= i ;\n j ++ ) if ( j * j == i ) cnt ++ ;\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountSquares ( a , b ) :\n cnt = 0\n for i in range ( a , b + 1 ) :\n j = 1 ;\n while j * j <= i :\n if j * j == i :\n cnt = cnt + 1\n j = j + 1\n i = i + 1\n return cnt\n\n"
},
{
"id": "python-java-MINIMIZE_THE_SUM_OF_DIGITS_OF_A_AND_B_SUCH_THAT_A_B_N",
"pair": "python-java",
"Code1": "def minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n",
"Code2": "static int minSum ( int n ) {\n int sum = 0 ;\n while ( n > 0 ) {\n sum += ( n % 10 ) ;\n n /= 10 ;\n }\n if ( sum == 1 ) return 10 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSum ( n ) :\n sum = 0\n while ( n > 0 ) :\n sum += ( n % 10 )\n n //= 10\n if ( sum == 1 ) :\n return 10\n return sum\n\n"
},
{
"id": "python-java-NTH_NON_FIBONACCI_NUMBER",
"pair": "python-java",
"Code1": "def nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n",
"Code2": "static int nonFibonacci ( int n ) {\n int prevPrev = 1 , prev = 2 , curr = 3 ;\n while ( n > 0 ) {\n prevPrev = prev ;\n prev = curr ;\n curr = prevPrev + prev ;\n n = n - ( curr - prev - 1 ) ;\n }\n n = n + ( curr - prev - 1 ) ;\n return prev + n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nonFibonacci ( n ) :\n prevPrev = 1\n prev = 2\n curr = 3\n while n > 0 :\n prevPrev = prev\n prev = curr\n curr = prevPrev + prev\n n = n - ( curr - prev - 1 )\n n = n + ( curr - prev - 1 )\n return prev + n\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_3_LONGEST_INCREASING_SUBSEQUENCE_1",
"pair": "python-java",
"Code1": "def lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n int lis [ ] = new int [ n ] ;\n int i , j , max = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) lis [ i ] = 1 ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n n = len ( arr )\n lis = [ 1 ] * n\n for i in range ( 1 , n ) :\n for j in range ( 0 , i ) :\n if arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 :\n lis [ i ] = lis [ j ] + 1\n maximum = 0\n for i in range ( n ) :\n maximum = max ( maximum , lis [ i ] )\n return maximum\n\n"
},
{
"id": "python-java-QUICKLY_FIND_MULTIPLE_LEFT_ROTATIONS_OF_AN_ARRAY",
"pair": "python-java",
"Code1": "def leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n",
"Code2": "static void leftRotate ( int arr [ ] , int n , int k ) {\n for ( int i = k ;\n i < k + n ;\n i ++ ) System . out . print ( arr [ i % n ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef leftRotate ( arr , n , k ) :\n for i in range ( k , k + n ) :\n print ( str ( arr [ i % n ] ) , end = \" \" )\n\n"
},
{
"id": "python-java-C_PROGRAM_CONCATENATE_STRING_GIVEN_NUMBER_TIMES",
"pair": "python-java",
"Code1": "def repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n",
"Code2": "static String repeat ( String s , int n ) {\n String s1 = s ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) s += s1 ;\n return s ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef repeat ( s , n ) :\n s1 = s\n for i in range ( 1 , n ) :\n s += s1\n return s\n\n"
},
{
"id": "python-java-SMALLEST_WINDOW_CONTAINS_CHARACTERS_STRING",
"pair": "python-java",
"Code1": "def findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n",
"Code2": "static String findSubString ( String str ) {\n int n = str . length ( ) ;\n int dist_count = 0 ;\n boolean [ ] visited = new boolean [ MAX_CHARS ] ;\n Arrays . fill ( visited , false ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ str . charAt ( i ) ] == false ) {\n visited [ str . charAt ( i ) ] = true ;\n dist_count ++ ;\n }\n }\n int start = 0 , start_index = - 1 ;\n int min_len = Integer . MAX_VALUE ;\n int count = 0 ;\n int [ ] curr_count = new int [ MAX_CHARS ] ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n curr_count [ str . charAt ( j ) ] ++ ;\n if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ;\n if ( count == dist_count ) {\n while ( curr_count [ str . charAt ( start ) ] > 1 ) {\n if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ;\n start ++ ;\n }\n int len_window = j - start + 1 ;\n if ( min_len > len_window ) {\n min_len = len_window ;\n start_index = start ;\n }\n }\n }\n return str . substring ( start_index , start_index + min_len ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSubString ( str ) :\n n = len ( str )\n dist_count = len ( set ( [ x for x in str ] ) )\n count , start , start_index , min_len = 0 , 0 , - 1 , 9999999999\n curr_count = defaultdict ( lambda : 0 )\n for j in range ( n ) :\n curr_count [ str [ j ] ] += 1\n if curr_count [ str [ j ] ] == 1 :\n count += 1\n if count == dist_count :\n while curr_count [ str [ start ] ] > 1 :\n if curr_count [ str [ start ] ] > 1 :\n curr_count [ str [ start ] ] -= 1\n start += 1\n len_window = j - start + 1\n if min_len > len_window :\n min_len = len_window\n start_index = start\n return str [ start_index : start_index + min_len ]\n\n"
},
{
"id": "python-java-COUNT_WAYS_REACH_NTH_STAIR_USING_STEP_1_2_3",
"pair": "python-java",
"Code1": "def findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n",
"Code2": "public static int findStep ( int n ) {\n if ( n == 1 || n == 0 ) return 1 ;\n else if ( n == 2 ) return 2 ;\n else return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findStep ( n ) :\n if ( n == 1 or n == 0 ) :\n return 1\n elif ( n == 2 ) :\n return 2\n else :\n return findStep ( n - 3 ) + findStep ( n - 2 ) + findStep ( n - 1 )\n\n"
},
{
"id": "python-java-SUBARRAYSUBSTRING_VS_SUBSEQUENCE_AND_PROGRAMS_TO_GENERATE_THEM_1",
"pair": "python-java",
"Code1": "def printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n",
"Code2": "static void printSubsequences ( int n ) {\n int opsize = ( int ) Math . pow ( 2 , n ) ;\n for ( int counter = 1 ;\n counter < opsize ;\n counter ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSubsequences ( arr , n ) :\n opsize = math.pow ( 2 , n )\n for counter in range ( 1 , ( int ) ( opsize ) ) :\n for j in range ( 0 , n ) :\n if ( counter & ( 1 << j ) ) :\n print ( arr [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-MINIMUM_XOR_VALUE_PAIR_1",
"pair": "python-java",
"Code1": "def minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n",
"Code2": "static int minXOR ( int arr [ ] , int n ) {\n Arrays . parallelSort ( arr ) ;\n int minXor = Integer . MAX_VALUE ;\n int val = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n val = arr [ i ] ^ arr [ i + 1 ] ;\n minXor = Math . min ( minXor , val ) ;\n }\n return minXor ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minXOR ( arr , n ) :\n arr.sort ( )\n minXor = int ( sys.float_info.max )\n val = 0\n for i in range ( 0 , n - 1 ) :\n val = arr [ i ] ^ arr [ i + 1 ]\n minXor = min ( minXor , val )\n return minXor\n\n"
},
{
"id": "python-java-DOOLITTLE_ALGORITHM_LU_DECOMPOSITION",
"pair": "python-java",
"Code1": "def luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n",
"Code2": "static void luDecomposition ( int [ ] [ ] mat , int n ) {\n int [ ] [ ] lower = new int [ n ] [ n ] ;\n int [ ] [ ] upper = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int k = i ;\n k < n ;\n k ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] ) ;\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum ;\n }\n for ( int k = i ;\n k < n ;\n k ++ ) {\n if ( i == k ) lower [ i ] [ i ] = 1 ;\n else {\n int sum = 0 ;\n for ( int j = 0 ;\n j < i ;\n j ++ ) sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] ) ;\n lower [ k ] [ i ] = ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] ;\n }\n }\n }\n System . out . println ( setw ( 2 ) + \" Lower Triangular\" + setw ( 10 ) + \"Upper Triangular\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + lower [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\t\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 4 ) + upper [ i ] [ j ] + \"\\t\" ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef luDecomposition ( mat , n ) :\n lower = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n upper = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for k in range ( i , n ) :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ i ] [ j ] * upper [ j ] [ k ] )\n upper [ i ] [ k ] = mat [ i ] [ k ] - sum\n for k in range ( i , n ) :\n if ( i == k ) :\n lower [ i ] [ i ] = 1\n else :\n sum = 0\n for j in range ( i ) :\n sum += ( lower [ k ] [ j ] * upper [ j ] [ i ] )\n lower [ k ] [ i ] = int ( ( mat [ k ] [ i ] - sum ) / upper [ i ] [ i ] )\n print ( \"Lower Triangular\\t\\tUpper Triangular\" )\n for i in range ( n ) :\n for j in range ( n ) :\n print ( lower [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" , end = \"\\t\" )\n for j in range ( n ) :\n print ( upper [ i ] [ j ] , end = \"\\t\" )\n print ( \"\" )\n\n"
},
{
"id": "python-java-BINARY_REPRESENTATION_OF_A_GIVEN_NUMBER_1",
"pair": "python-java",
"Code1": "def bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n",
"Code2": "static void bin ( Integer n ) {\n if ( n > 1 ) bin ( n >> 1 ) ;\n System . out . printf ( \"%d\" , n & 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bin ( n ) :\n if ( n > 1 ) :\n bin ( n >> 1 )\n print ( n & 1 , end = \"\" )\n\n"
},
{
"id": "python-java-COUNT_PALINDROME_SUB_STRINGS_STRING",
"pair": "python-java",
"Code1": "def CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n",
"Code2": "static int CountPS ( char str [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n boolean P [ ] [ ] = new boolean [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) P [ i ] [ i ] = true ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( str [ i ] == str [ i + 1 ] ) {\n P [ i ] [ i + 1 ] = true ;\n dp [ i ] [ i + 1 ] = 1 ;\n }\n }\n for ( int gap = 2 ;\n gap < n ;\n gap ++ ) {\n for ( int i = 0 ;\n i < n - gap ;\n i ++ ) {\n int j = gap + i ;\n if ( str [ i ] == str [ j ] && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ;\n if ( P [ i ] [ j ] == true ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] ;\n }\n }\n return dp [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountPS ( str , n ) :\n dp = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n P = [ [ False for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n P [ i ] [ i ] = True\n for i in range ( n - 1 ) :\n if ( str [ i ] == str [ i + 1 ] ) :\n P [ i ] [ i + 1 ] = True\n dp [ i ] [ i + 1 ] = 1\n for gap in range ( 2 , n ) :\n for i in range ( n - gap ) :\n j = gap + i ;\n if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :\n P [ i ] [ j ] = True\n if ( P [ i ] [ j ] == True ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] + 1 - dp [ i + 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] )\n return dp [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-GIVEN_TWO_NUMBERS_B_FIND_X_X_B",
"pair": "python-java",
"Code1": "def modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n",
"Code2": "static void modularEquation ( int a , int b ) {\n if ( a < b ) {\n System . out . println ( \"No solution possible \" ) ;\n return ;\n }\n if ( a == b ) {\n System . out . println ( \"Infinite Solution possible \" ) ;\n return ;\n }\n int count = 0 ;\n int n = a - b ;\n int y = ( int ) Math . sqrt ( a - b ) ;\n for ( int i = 1 ;\n i <= y ;\n ++ i ) {\n if ( n % i == 0 ) {\n if ( n / i > b ) count ++ ;\n if ( i > b ) count ++ ;\n }\n }\n if ( y * y == n && y > b ) count -- ;\n System . out . println ( count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef modularEquation ( a , b ) :\n if ( a < b ) :\n print ( \"No solution possible \" )\n return\n if ( a == b ) :\n print ( \"Infinite Solution possible \" )\n return\n count = 0\n n = a - b\n y = ( int ) ( math.sqrt ( a - b ) )\n for i in range ( 1 , y + 1 ) :\n if ( n % i == 0 ) :\n if ( n / i > b ) :\n count = count + 1\n if ( i > b ) :\n count = count + 1\n if ( y * y == n and y > b ) :\n count = count - 1\n print ( count )\n\n"
},
{
"id": "python-java-PAPER_CUT_MINIMUM_NUMBER_SQUARES",
"pair": "python-java",
"Code1": "def minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n",
"Code2": "static int minimumSquare ( int a , int b ) {\n int result = 0 , rem = 0 ;\n if ( a < b ) swap ( a , b ) ;\n while ( b > 0 ) {\n result += a / b ;\n rem = a % b ;\n a = b ;\n b = rem ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimumSquare ( a , b ) :\n result = 0\n rem = 0\n if ( a < b ) :\n a , b = b , a\n while ( b > 0 ) :\n result += int ( a / b )\n rem = int ( a % b )\n a = b\n b = rem\n return result\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_PATH_MATRIX_TOP_BOTTOM",
"pair": "python-java",
"Code1": "def maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n",
"Code2": "static int maxSum ( int [ ] [ ] mat , int n ) {\n if ( n == 1 ) return mat [ 0 ] [ 0 ] ;\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n int maxSum = Integer . MIN_VALUE , max ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n max = Integer . MIN_VALUE ;\n if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ;\n if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ;\n dp [ i ] [ j ] = mat [ i ] [ j ] + max ;\n }\n }\n for ( int j = 0 ;\n j < n ;\n j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ;\n return maxSum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( mat , n ) :\n if n == 1 :\n return mat [ 0 ] [ 0 ]\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n maxSum = INT_MIN\n for j in range ( n ) :\n dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n for j in range ( n ) :\n maxi = INT_MIN\n if ( ( ( ( j - 1 ) >= 0 ) and ( maxi < dp [ i + 1 ] [ j - 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j - 1 ]\n if ( ( ( ( j + 1 ) < n ) and ( maxi < dp [ i + 1 ] [ j + 1 ] ) ) ) :\n maxi = dp [ i + 1 ] [ j + 1 ]\n dp [ i ] [ j ] = mat [ i ] [ j ] + maxi\n for j in range ( n ) :\n if ( maxSum < dp [ 0 ] [ j ] ) :\n maxSum = dp [ 0 ] [ j ]\n return maxSum\n\n"
},
{
"id": "python-java-MINIMUM_SUM_ABSOLUTE_DIFFERENCE_PAIRS_TWO_ARRAYS",
"pair": "python-java",
"Code1": "def findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n",
"Code2": "static long findMinSum ( long a [ ] , long b [ ] , long n ) {\n Arrays . sort ( a ) ;\n Arrays . sort ( b ) ;\n long sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum = sum + Math . abs ( a [ i ] - b [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinSum ( a , b , n ) :\n a.sort ( )\n b.sort ( )\n sum = 0\n for i in range ( n ) :\n sum = sum + abs ( a [ i ] - b [ i ] )\n return sum\n\n"
},
{
"id": "python-java-DELETE_ARRAY_ELEMENTS_WHICH_ARE_SMALLER_THAN_NEXT_OR_BECOME_SMALLER",
"pair": "python-java",
"Code1": "def deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n",
"Code2": "static void deleteElements ( int arr [ ] , int n , int k ) {\n Stack < Integer > s = new Stack < > ( ) ;\n s . push ( arr [ 0 ] ) ;\n int count = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n while ( ! s . empty ( ) && s . peek ( ) < arr [ i ] && count < k ) {\n s . pop ( ) ;\n count ++ ;\n }\n s . push ( arr [ i ] ) ;\n }\n int m = s . size ( ) ;\n Integer [ ] v = new Integer [ m ] ;\n while ( ! s . empty ( ) ) {\n v [ -- m ] = s . peek ( ) ;\n s . pop ( ) ;\n }\n for ( Integer x : v ) {\n System . out . print ( x + \" \" ) ;\n }\n ;\n System . out . println ( \"\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef deleteElements ( arr , n , k ) :\n st = [ ]\n st.append ( arr [ 0 ] )\n top = 0\n count = 0\n for i in range ( 1 , n ) :\n while ( len ( st ) != 0 and count < k and st [ top ] < arr [ i ] ) :\n st.pop ( )\n count += 1\n top -= 1\n st.append ( arr [ i ] )\n top += 1\n for i in range ( 0 , len ( st ) ) :\n print ( st [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-java-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE",
"pair": "python-java",
"Code1": "def first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n",
"Code2": "static char first ( String str ) {\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef first ( str ) :\n for i in range ( 0 , len ( str ) ) :\n if ( str [ i ].istitle ( ) ) :\n return str [ i ]\n return 0\n\n"
},
{
"id": "python-java-FIND_THE_MINIMUM_DISTANCE_BETWEEN_TWO_NUMBERS",
"pair": "python-java",
"Code1": "def minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n",
"Code2": "int minDist ( int arr [ ] , int n , int x , int y ) {\n int i , j ;\n int min_dist = Integer . MAX_VALUE ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( ( x == arr [ i ] && y == arr [ j ] || y == arr [ i ] && x == arr [ j ] ) && min_dist > Math . abs ( i - j ) ) min_dist = Math . abs ( i - j ) ;\n }\n }\n return min_dist ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minDist ( arr , n , x , y ) :\n min_dist = 99999999\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( x == arr [ i ] and y == arr [ j ] or y == arr [ i ] and x == arr [ j ] ) and min_dist > abs ( i - j ) :\n min_dist = abs ( i - j )\n return min_dist\n\n"
},
{
"id": "python-java-ARC_LENGTH_ANGLE",
"pair": "python-java",
"Code1": "def arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n",
"Code2": "static double arcLength ( double diameter , double angle ) {\n double pi = 22.0 / 7.0 ;\n double arc ;\n if ( angle >= 360 ) {\n System . out . println ( \"Angle cannot\" + \" be formed\" ) ;\n return 0 ;\n }\n else {\n arc = ( pi * diameter ) * ( angle / 360.0 ) ;\n return arc ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arcLength ( diameter , angle ) :\n if angle >= 360 :\n print ( \"Angle cannot be formed\" )\n return 0\n else :\n arc = ( 3.142857142857143 * diameter ) * ( angle / 360.0 )\n return arc\n\n"
},
{
"id": "python-java-GIVEN_AN_ARRAY_OF_PAIRS_FIND_ALL_SYMMETRIC_PAIRS_IN_IT",
"pair": "python-java",
"Code1": "def findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n",
"Code2": "static void findSymPairs ( int arr [ ] [ ] ) {\n HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n int first = arr [ i ] [ 0 ] ;\n int sec = arr [ i ] [ 1 ] ;\n Integer val = hM . get ( sec ) ;\n if ( val != null && val == first ) System . out . println ( \"(\" + sec + \", \" + first + \")\" ) ;\n else hM . put ( first , sec ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSymPairs ( arr , row ) :\n hM = dict ( )\n for i in range ( row ) :\n first = arr [ i ] [ 0 ]\n sec = arr [ i ] [ 1 ]\n if ( sec in hM.keys ( ) and hM [ sec ] == first ) :\n print ( \"(\" , sec , \",\" , first , \")\" )\n else :\n hM [ first ] = sec\n\n"
},
{
"id": "python-java-CHECK_IF_A_STRING_HAS_ALL_CHARACTERS_WITH_SAME_FREQUENCY_WITH_ONE_VARIATION_ALLOWED",
"pair": "python-java",
"Code1": "def isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n",
"Code2": "static boolean isValidString ( String str ) {\n int freq [ ] = new int [ CHARS ] ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n int i , freq1 = 0 , count_freq1 = 0 ;\n for ( i = 0 ;\n i < CHARS ;\n i ++ ) {\n if ( freq [ i ] != 0 ) {\n freq1 = freq [ i ] ;\n count_freq1 = 1 ;\n break ;\n }\n }\n int j , freq2 = 0 , count_freq2 = 0 ;\n for ( j = i + 1 ;\n j < CHARS ;\n j ++ ) {\n if ( freq [ j ] != 0 ) {\n if ( freq [ j ] == freq1 ) {\n count_freq1 ++ ;\n }\n else {\n count_freq2 = 1 ;\n freq2 = freq [ j ] ;\n break ;\n }\n }\n }\n for ( int k = j + 1 ;\n k < CHARS ;\n k ++ ) {\n if ( freq [ k ] != 0 ) {\n if ( freq [ k ] == freq1 ) {\n count_freq1 ++ ;\n }\n if ( freq [ k ] == freq2 ) {\n count_freq2 ++ ;\n }\n else {\n return false ;\n }\n }\n if ( count_freq1 > 1 && count_freq2 > 1 ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isValidString ( str ) :\n freq = [ 0 ] * CHARS\n for i in range ( len ( str ) ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n freq1 = 0\n count_freq1 = 0\n for i in range ( CHARS ) :\n if ( freq [ i ] != 0 ) :\n freq1 = freq [ i ]\n count_freq1 = 1\n break\n freq2 = 0\n count_freq2 = 0\n for j in range ( i + 1 , CHARS ) :\n if ( freq [ j ] != 0 ) :\n if ( freq [ j ] == freq1 ) :\n count_freq1 += 1\n else :\n count_freq2 = 1\n freq2 = freq [ j ]\n break\n for k in range ( j + 1 , CHARS ) :\n if ( freq [ k ] != 0 ) :\n if ( freq [ k ] == freq1 ) :\n count_freq1 += 1\n if ( freq [ k ] == freq2 ) :\n count_freq2 += 1\n else :\n return False\n if ( count_freq1 > 1 and count_freq2 > 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-PRIME_NUMBERS",
"pair": "python-java",
"Code1": "def isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n",
"Code2": "static boolean isPrime ( int n ) {\n if ( n <= 1 ) return false ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( n % i == 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPrime ( n ) :\n if ( n <= 1 ) :\n return False\n for i in range ( 2 , n ) :\n if ( n % i == 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_AVERAGE_SUBARRAY_OF_K_LENGTH",
"pair": "python-java",
"Code1": "def findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n",
"Code2": "static int findMaxAverage ( int [ ] arr , int n , int k ) {\n if ( k > n ) return - 1 ;\n int [ ] csum = new int [ n ] ;\n csum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) csum [ i ] = csum [ i - 1 ] + arr [ i ] ;\n int max_sum = csum [ k - 1 ] , max_end = k - 1 ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n int curr_sum = csum [ i ] - csum [ i - k ] ;\n if ( curr_sum > max_sum ) {\n max_sum = curr_sum ;\n max_end = i ;\n }\n }\n return max_end - k + 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxAverage ( arr , n , k ) :\n if k > n :\n return - 1\n csum = [ 0 ] * n\n csum [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n csum [ i ] = csum [ i - 1 ] + arr [ i ]\n max_sum = csum [ k - 1 ]\n max_end = k - 1\n for i in range ( k , n ) :\n curr_sum = csum [ i ] - csum [ i - k ]\n if curr_sum > max_sum :\n max_sum = curr_sum\n max_end = i\n return max_end - k + 1\n\n"
},
{
"id": "python-java-DIVIDE_CUBOID_CUBES_SUM_VOLUMES_MAXIMUM",
"pair": "python-java",
"Code1": "def maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n",
"Code2": "static void maximizecube ( int l , int b , int h ) {\n int side = gcd ( l , gcd ( b , h ) ) ;\n int num = l / side ;\n num = ( num * b / side ) ;\n num = ( num * h / side ) ;\n System . out . println ( side + \" \" + num ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximizecube ( l , b , h ) :\n side = gcd ( l , gcd ( b , h ) )\n num = int ( l / side )\n num = int ( num * b / side )\n num = int ( num * h / side )\n print ( side , num )\n\n"
},
{
"id": "python-java-HORNERS_METHOD_POLYNOMIAL_EVALUATION",
"pair": "python-java",
"Code1": "def horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n",
"Code2": "static int horner ( int poly [ ] , int n , int x ) {\n int result = poly [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) result = result * x + poly [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef horner ( poly , n , x ) :\n result = poly [ 0 ]\n for i in range ( 1 , n ) :\n result = result * x + poly [ i ]\n return result\n\n"
},
{
"id": "python-java-C_PROGRAM_CYCLICALLY_ROTATE_ARRAY_ONE",
"pair": "python-java",
"Code1": "def rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n",
"Code2": "static void rotate ( ) {\n int x = arr [ arr . length - 1 ] , i ;\n for ( i = arr . length - 1 ;\n i > 0 ;\n i -- ) arr [ i ] = arr [ i - 1 ] ;\n arr [ 0 ] = x ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rotate ( arr , n ) :\n x = arr [ n - 1 ]\n for i in range ( n - 1 , 0 , - 1 ) :\n arr [ i ] = arr [ i - 1 ]\n arr [ 0 ] = x\n\n"
},
{
"id": "python-java-N_BONACCI_NUMBERS_1",
"pair": "python-java",
"Code1": "def bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "static void bonacciseries ( int n , int m ) {\n int a [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) a [ i ] = 0 ;\n a [ n - 1 ] = 1 ;\n a [ n ] = 1 ;\n for ( int i = n + 1 ;\n i < m ;\n i ++ ) a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bonacciseries ( n , m ) :\n a = [ 0 for i in range ( m ) ]\n a [ n - 1 ] = 1\n a [ n ] = 1\n for i in range ( n + 1 , m ) :\n a [ i ] = 2 * a [ i - 1 ] - a [ i - n - 1 ]\n for i in range ( 0 , m ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-COUNTING_PAIRS_PERSON_CAN_FORM_PAIR_ONE_1",
"pair": "python-java",
"Code1": "def numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n",
"Code2": "static int numberOfWays ( int x ) {\n int dp [ ] = new int [ x + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= x ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ;\n return dp [ x ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfWays ( x ) :\n if x == 0 or x == 1 :\n return 1\n else :\n return ( numberOfWays ( x - 1 ) + ( x - 1 ) * numberOfWays ( x - 2 ) )\n\n"
},
{
"id": "python-java-HOW_TO_PRINT_MAXIMUM_NUMBER_OF_A_USING_GIVEN_FOUR_KEYS",
"pair": "python-java",
"Code1": "def findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n",
"Code2": "static int findoptimal ( int N ) {\n if ( N <= 6 ) return N ;\n int [ ] screen = new int [ N ] ;\n int b ;\n int n ;\n for ( n = 1 ;\n n <= 6 ;\n n ++ ) screen [ n - 1 ] = n ;\n for ( n = 7 ;\n n <= N ;\n n ++ ) {\n screen [ n - 1 ] = Math . max ( 2 * screen [ n - 4 ] , Math . max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;\n }\n return screen [ N - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findoptimal ( N ) :\n if ( N <= 6 ) :\n return N\n screen = [ 0 ] * N\n for n in range ( 1 , 7 ) :\n screen [ n - 1 ] = n\n for n in range ( 7 , N + 1 ) :\n screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) )\n return screen [ N - 1 ]\n\n"
},
{
"id": "python-java-MAXIMUM_DIFFERENCE_SUM_ELEMENTS_TWO_ROWS_MATRIX",
"pair": "python-java",
"Code1": "def maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n",
"Code2": "static int maxRowDiff ( int mat [ ] [ ] , int m , int n ) {\n int rowSum [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) sum += mat [ i ] [ j ] ;\n rowSum [ i ] = sum ;\n }\n int max_diff = rowSum [ 1 ] - rowSum [ 0 ] ;\n int min_element = rowSum [ 0 ] ;\n for ( int i = 1 ;\n i < m ;\n i ++ ) {\n if ( rowSum [ i ] - min_element > max_diff ) max_diff = rowSum [ i ] - min_element ;\n if ( rowSum [ i ] < min_element ) min_element = rowSum [ i ] ;\n }\n return max_diff ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxRowDiff ( mat , m , n ) :\n rowSum = [ 0 ] * m\n for i in range ( 0 , m ) :\n sum = 0\n for j in range ( 0 , n ) :\n sum += mat [ i ] [ j ]\n rowSum [ i ] = sum\n max_diff = rowSum [ 1 ] - rowSum [ 0 ]\n min_element = rowSum [ 0 ]\n for i in range ( 1 , m ) :\n if ( rowSum [ i ] - min_element > max_diff ) :\n max_diff = rowSum [ i ] - min_element\n if ( rowSum [ i ] < min_element ) :\n min_element = rowSum [ i ]\n return max_diff\n\n"
},
{
"id": "python-java-CHECK_VALID_SEQUENCE_DIVISIBLE_M_1",
"pair": "python-java",
"Code1": "def isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n",
"Code2": "static int isPossible ( int n , int index , int modulo , int M , int arr [ ] , int dp [ ] [ ] ) {\n modulo = ( ( modulo % M ) + M ) % M ;\n if ( index == n ) {\n if ( modulo == 0 ) {\n return 1 ;\n }\n return 0 ;\n }\n if ( dp [ index ] [ modulo ] != - 1 ) {\n return dp [ index ] [ modulo ] ;\n }\n int placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp ) ;\n int placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp ) ;\n int res = placeAdd ;\n dp [ index ] [ modulo ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPossible ( n , index , modulo , M , arr , dp ) :\n modulo = ( ( modulo % M ) + M ) % M\n if ( index == n ) :\n if ( modulo == 0 ) :\n return 1\n return 0\n if ( dp [ index ] [ modulo ] != - 1 ) :\n return dp [ index ] [ modulo ]\n placeAdd = isPossible ( n , index + 1 , modulo + arr [ index ] , M , arr , dp )\n placeMinus = isPossible ( n , index + 1 , modulo - arr [ index ] , M , arr , dp )\n res = bool ( placeAdd or placeMinus )\n dp [ index ] [ modulo ] = res\n return res\n\n"
},
{
"id": "python-java-FIND_NTH_FIBONACCI_NUMBER_USING_GOLDEN_RATIO",
"pair": "python-java",
"Code1": "def fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n",
"Code2": "static int fib ( int n ) {\n if ( n < 6 ) return f [ n ] ;\n int t = 5 ;\n int fn = 5 ;\n while ( t < n ) {\n fn = ( int ) Math . round ( fn * PHI ) ;\n t ++ ;\n }\n return fn ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fib ( n ) :\n if n < 6 :\n return f [ n ]\n t = 5\n fn = 5\n while t < n :\n fn = round ( fn * PHI )\n t += 1\n return fn\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_6_MIN_COST_PATH",
"pair": "python-java",
"Code1": "def minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n",
"Code2": "private static int minCost ( int cost [ ] [ ] , int m , int n ) {\n int i , j ;\n int tc [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( i = 1 ;\n i <= m ;\n i ++ ) for ( j = 1 ;\n j <= n ;\n j ++ ) tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return tc [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCost ( cost , m , n ) :\n tc = [ [ 0 for x in range ( C ) ] for x in range ( R ) ]\n tc [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , m + 1 ) :\n tc [ i ] [ 0 ] = tc [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , n + 1 ) :\n tc [ 0 ] [ j ] = tc [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n tc [ i ] [ j ] = min ( tc [ i - 1 ] [ j - 1 ] , tc [ i - 1 ] [ j ] , tc [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return tc [ m ] [ n ]\n\n"
},
{
"id": "python-java-PUT_SPACES_WORDS_STARTING_CAPITAL_LETTERS",
"pair": "python-java",
"Code1": "def amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n",
"Code2": "public static void amendSentence ( String sstr ) {\n char [ ] str = sstr . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str . length ;\n i ++ ) {\n if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) {\n str [ i ] = ( char ) ( str [ i ] + 32 ) ;\n if ( i != 0 ) System . out . print ( \" \" ) ;\n System . out . print ( str [ i ] ) ;\n }\n else System . out . print ( str [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef amendSentence ( string ) :\n string = list ( string )\n for i in range ( len ( string ) ) :\n if string [ i ] >= 'A' and string [ i ] <= 'Z' :\n string [ i ] = chr ( ord ( string [ i ] ) + 32 )\n if i != 0 :\n print ( \"\" , end = \"\" )\n print ( string [ i ] , end = \"\" )\n else :\n print ( string [ i ] , end = \"\" )\n\n"
},
{
"id": "python-java-WAYS_SUM_N_USING_ARRAY_ELEMENTS_REPETITION_ALLOWED",
"pair": "python-java",
"Code1": "def countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n",
"Code2": "static int countWays ( int N ) {\n int count [ ] = new int [ N + 1 ] ;\n count [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) for ( int j = 0 ;\n j < arr . length ;\n j ++ ) if ( i >= arr [ j ] ) count [ i ] += count [ i - arr [ j ] ] ;\n return count [ N ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWays ( arr , m , N ) :\n count = [ 0 for i in range ( N + 1 ) ]\n count [ 0 ] = 1\n for i in range ( 1 , N + 1 ) :\n for j in range ( m ) :\n if ( i >= arr [ j ] ) :\n count [ i ] += count [ i - arr [ j ] ]\n return count [ N ]\n\n"
},
{
"id": "python-java-BREAK_NUMBER_THREE_PARTS",
"pair": "python-java",
"Code1": "def count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n",
"Code2": "static long count_of_ways ( long n ) {\n long count = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) for ( int k = 0 ;\n k <= n ;\n k ++ ) if ( i + j + k == n ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count_of_ways ( n ) :\n count = 0\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , n + 1 ) :\n for k in range ( 0 , n + 1 ) :\n if ( i + j + k == n ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-SUM_SERIES_0_6_0_06_0_006_0_0006_N_TERMS",
"pair": "python-java",
"Code1": "def sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n",
"Code2": "static double sumOfSeries ( int n ) {\n return ( 0.666 ) * ( 1 - 1 / Math . pow ( 10 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumOfSeries ( n ) :\n return ( ( 0.666 ) * ( 1 - 1 / pow ( 10 , n ) ) )\n\n"
},
{
"id": "python-java-PARTITION_NUMBER_TWO_DIVISBLE_PARTS",
"pair": "python-java",
"Code1": "def findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n",
"Code2": "static void findDivision ( String str , int a , int b ) {\n int len = str . length ( ) ;\n int [ ] lr = new int [ len + 1 ] ;\n lr [ 0 ] = ( ( int ) str . charAt ( 0 ) - ( int ) ' 0 ' ) % a ;\n for ( int i = 1 ;\n i < len ;\n i ++ ) lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) ) % a ;\n int [ ] rl = new int [ len + 1 ] ;\n rl [ len - 1 ] = ( ( int ) str . charAt ( len - 1 ) - ( int ) ' 0 ' ) % b ;\n int power10 = 10 ;\n for ( int i = len - 2 ;\n i >= 0 ;\n i -- ) {\n rl [ i ] = ( rl [ i + 1 ] + ( ( int ) str . charAt ( i ) - ( int ) ' 0 ' ) * power10 ) % b ;\n power10 = ( power10 * 10 ) % b ;\n }\n for ( int i = 0 ;\n i < len - 1 ;\n i ++ ) {\n if ( lr [ i ] != 0 ) continue ;\n if ( rl [ i + 1 ] == 0 ) {\n System . out . println ( \"YES\" ) ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n System . out . print ( \", \" ) ;\n for ( int k = i + 1 ;\n k < len ;\n k ++ ) System . out . print ( str . charAt ( k ) ) ;\n return ;\n }\n }\n System . out . println ( \"NO\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDivision ( str , a , b ) :\n lenn = len ( str )\n lr = [ 0 ] * ( lenn + 1 )\n lr [ 0 ] = ( int ( str [ 0 ] ) ) % a\n for i in range ( 1 , lenn ) :\n lr [ i ] = ( ( lr [ i - 1 ] * 10 ) % a + \\ int ( str [ i ] ) ) % a\n rl = [ 0 ] * ( lenn + 1 )\n rl [ lenn - 1 ] = int ( str [ lenn - 1 ] ) % b\n power10 = 10\n for i in range ( lenn - 2 , - 1 , - 1 ) :\n rl [ i ] = ( rl [ i + 1 ] + int ( str [ i ] ) * power10 ) % b\n power10 = ( power10 * 10 ) % b\n for i in range ( 0 , lenn - 1 ) :\n if ( lr [ i ] != 0 ) :\n continue\n if ( rl [ i + 1 ] == 0 ) :\n print ( \"YES\" )\n for k in range ( 0 , i + 1 ) :\n print ( str [ k ] , end = \"\" )\n print ( \",\" , end = \"\" )\n for i in range ( i + 1 , lenn ) :\n print ( str [ k ] , end = \"\" )\n return\n print ( \"NO\" )\n\n"
},
{
"id": "python-java-ROW_WISE_COMMON_ELEMENTS_TWO_DIAGONALS_SQUARE_MATRIX",
"pair": "python-java",
"Code1": "def countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n",
"Code2": "static int countCommon ( int mat [ ] [ ] , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countCommon ( mat , n ) :\n res = 0\n for i in range ( n ) :\n if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :\n res = res + 1\n return res\n\n"
},
{
"id": "python-java-HEXAGONAL_NUMBER",
"pair": "python-java",
"Code1": "def hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n",
"Code2": "int hexagonalNum ( int n ) {\n return n * ( 2 * n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef hexagonalNum ( n ) :\n return n * ( 2 * n - 1 )\n\n"
},
{
"id": "python-java-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY",
"pair": "python-java",
"Code1": "def findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n",
"Code2": "static int findGreatest ( int [ ] arr , int n ) {\n int result = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findGreatest ( arr , n ) :\n result = - 1\n for i in range ( n ) :\n for j in range ( n - 1 ) :\n for k in range ( j + 1 , n ) :\n if ( arr [ j ] * arr [ k ] == arr [ i ] ) :\n result = max ( result , arr [ i ] )\n return result\n\n"
},
{
"id": "python-java-FIND_SQUARE_ROOT_UNDER_MODULO_P_SET_1_WHEN_P_IS_IN_FORM_OF_4I_3",
"pair": "python-java",
"Code1": "def squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n",
"Code2": "static void squareRoot ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) {\n if ( ( x * x ) % p == n ) {\n System . out . println ( \"Square \" + \"root is \" + x ) ;\n return ;\n }\n }\n System . out . println ( \"Square root \" + \"doesn't exist\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef squareRoot ( n , p ) :\n n = n % p\n for x in range ( 2 , p ) :\n if ( ( x * x ) % p == n ) :\n print ( \"Square root is \" , x )\n return\n print ( \"Square root doesn't exist\" )\n\n"
},
{
"id": "python-java-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING_1",
"pair": "python-java",
"Code1": "def count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n",
"Code2": "static int count ( String a , String b ) {\n int m = a . length ( ) ;\n int n = b . length ( ) ;\n int lookup [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n ++ i ) lookup [ 0 ] [ i ] = 0 ;\n for ( int i = 0 ;\n i <= m ;\n ++ i ) lookup [ i ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ] ;\n else lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ] ;\n }\n }\n return lookup [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count ( a , b ) :\n m = len ( a )\n n = len ( b )\n lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( n + 1 ) :\n lookup [ 0 ] [ i ] = 0\n for i in range ( m + 1 ) :\n lookup [ i ] [ 0 ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if a [ i - 1 ] == b [ j - 1 ] :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]\n else :\n lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]\n return lookup [ m ] [ n ]\n\n"
},
{
"id": "python-java-FIND_INDEX_OF_AN_EXTRA_ELEMENT_PRESENT_IN_ONE_SORTED_ARRAY_2",
"pair": "python-java",
"Code1": "def find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n",
"Code2": "static int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) {\n int extra_element = sum ( arrA ) - sum ( arrB ) ;\n return indexOf ( arrA , extra_element ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find_extra_element_index ( arrA , arrB ) :\n extra_element = sum ( arrA ) - sum ( arrB )\n return arrA.index ( extra_element )\n\n"
},
{
"id": "python-java-K_TH_MISSING_ELEMENT_INCREASING_SEQUENCE_NOT_PRESENT_GIVEN_SEQUENCE",
"pair": "python-java",
"Code1": "def find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n",
"Code2": "static int find ( int a [ ] , int b [ ] , int k , int n1 , int n2 ) {\n LinkedHashSet < Integer > s = new LinkedHashSet < > ( ) ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) s . add ( b [ i ] ) ;\n int missing = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n if ( ! s . contains ( a [ i ] ) ) missing ++ ;\n if ( missing == k ) return a [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find ( a , b , k , n1 , n2 ) :\n s = set ( )\n for i in range ( n2 ) :\n s.add ( b [ i ] )\n missing = 0\n for i in range ( n1 ) :\n if a [ i ] not in s :\n missing += 1\n if missing == k :\n return a [ i ]\n return - 1\n\n"
},
{
"id": "python-java-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE_1",
"pair": "python-java",
"Code1": "def sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n",
"Code2": "static double sumNodes ( int l ) {\n double leafNodeCount = Math . pow ( 2 , l - 1 ) ;\n double sumLastLevel = 0 ;\n sumLastLevel = ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 ;\n double sum = sumLastLevel * l ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumNodes ( l ) :\n leafNodeCount = math.pow ( 2 , l - 1 )\n sumLastLevel = 0\n sumLastLevel = ( ( leafNodeCount * ( leafNodeCount + 1 ) ) / 2 )\n sum = sumLastLevel * l\n return int ( sum )\n\n"
},
{
"id": "python-java-LEONARDO_NUMBER_1",
"pair": "python-java",
"Code1": "def leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n",
"Code2": "static int leonardo ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] + 1 ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef leonardo ( n ) :\n dp = [ ]\n dp.append ( 1 )\n dp.append ( 1 )\n for i in range ( 2 , n + 1 ) :\n dp.append ( dp [ i - 1 ] + dp [ i - 2 ] + 1 )\n return dp [ n ]\n\n"
},
{
"id": "python-java-COUNT_NATURAL_NUMBERS_WHOSE_PERMUTATION_GREATER_NUMBER",
"pair": "python-java",
"Code1": "def countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n",
"Code2": "static int countNumber ( int n ) {\n int result = 0 ;\n for ( int i = 1 ;\n i <= 9 ;\n i ++ ) {\n Stack < Integer > s = new Stack < > ( ) ;\n if ( i <= n ) {\n s . push ( i ) ;\n result ++ ;\n }\n while ( ! s . empty ( ) ) {\n int tp = s . peek ( ) ;\n s . pop ( ) ;\n for ( int j = tp % 10 ;\n j <= 9 ;\n j ++ ) {\n int x = tp * 10 + j ;\n if ( x <= n ) {\n s . push ( x ) ;\n result ++ ;\n }\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNumber ( n ) :\n result = 0\n for i in range ( 1 , 10 ) :\n s = [ ]\n if ( i <= n ) :\n s.append ( i )\n result += 1\n while len ( s ) != 0 :\n tp = s [ - 1 ]\n s.pop ( )\n for j in range ( tp % 10 , 10 ) :\n x = tp * 10 + j\n if ( x <= n ) :\n s.append ( x )\n result += 1\n return result\n\n"
},
{
"id": "python-java-CHECK_WHETHER_GIVEN_DEGREES_VERTICES_REPRESENT_GRAPH_TREE",
"pair": "python-java",
"Code1": "def check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n",
"Code2": "static boolean check ( int degree [ ] , int n ) {\n int deg_sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n deg_sum += degree [ i ] ;\n }\n return ( 2 * ( n - 1 ) == deg_sum ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( degree , n ) :\n deg_sum = sum ( degree )\n if ( 2 * ( n - 1 ) == deg_sum ) :\n return True\n else :\n return False\n\n"
},
{
"id": "python-java-FIND_SUM_EVEN_INDEX_BINOMIAL_COEFFICIENTS_1",
"pair": "python-java",
"Code1": "def evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n",
"Code2": "static int evenbinomialCoeffSum ( int n ) {\n return ( 1 << ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evenbinomialCoeffSum ( n ) :\n return ( 1 << ( n - 1 ) )\n\n"
},
{
"id": "python-java-FIND_MINIMUM_ELEMENT_IN_A_SORTED_AND_ROTATED_ARRAY",
"pair": "python-java",
"Code1": "def findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n",
"Code2": "static int findMin ( int arr [ ] , int low , int high ) {\n if ( high < low ) return arr [ 0 ] ;\n if ( high == low ) return arr [ low ] ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return arr [ mid + 1 ] ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return arr [ mid ] ;\n if ( arr [ high ] > arr [ mid ] ) return findMin ( arr , low , mid - 1 ) ;\n return findMin ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMin ( arr , low , high ) :\n if high < low :\n return arr [ 0 ]\n if high == low :\n return arr [ low ]\n mid = int ( ( low + high ) / 2 )\n if mid < high and arr [ mid + 1 ] < arr [ mid ] :\n return arr [ mid + 1 ]\n if mid > low and arr [ mid ] < arr [ mid - 1 ] :\n return arr [ mid ]\n if arr [ high ] > arr [ mid ] :\n return findMin ( arr , low , mid - 1 )\n return findMin ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-java-SQUARE_PYRAMIDAL_NUMBER_SUM_SQUARES",
"pair": "python-java",
"Code1": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"Code2": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n\n"
},
{
"id": "python-java-RETURN_MAXIMUM_OCCURRING_CHARACTER_IN_THE_INPUT_STRING",
"pair": "python-java",
"Code1": "def getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n",
"Code2": "static char getMaxOccuringChar ( String str ) {\n int count [ ] = new int [ ASCII_SIZE ] ;\n int len = str . length ( ) ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) count [ str . charAt ( i ) ] ++ ;\n int max = - 1 ;\n char result = ' ▁ ' ;\n for ( int i = 0 ;\n i < len ;\n i ++ ) {\n if ( max < count [ str . charAt ( i ) ] ) {\n max = count [ str . charAt ( i ) ] ;\n result = str . charAt ( i ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMaxOccuringChar ( str ) :\n count = [ 0 ] * ASCII_SIZE\n max = - 1\n c = ''\n for i in str :\n count [ ord ( i ) ] += 1 ;\n for i in str :\n if max < count [ ord ( i ) ] :\n max = count [ ord ( i ) ]\n c = i\n return c\n\n"
},
{
"id": "python-java-COUNT_STRINGS_CAN_FORMED_USING_B_C_GIVEN_CONSTRAINTS_1",
"pair": "python-java",
"Code1": "def countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n",
"Code2": "static int countStr ( int n ) {\n return 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countStr ( n ) :\n return ( 1 + ( n * 2 ) + ( n * ( ( n * n ) - 1 ) // 2 ) )\n\n"
},
{
"id": "python-java-GIVEN_N_X_N_SQUARE_MATRIX_FIND_SUM_SUB_SQUARES_SIZE_K_X_K",
"pair": "python-java",
"Code1": "def printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n",
"Code2": "static void printSumSimple ( int mat [ ] [ ] , int k ) {\n if ( k > n ) return ;\n for ( int i = 0 ;\n i < n - k + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n - k + 1 ;\n j ++ ) {\n int sum = 0 ;\n for ( int p = i ;\n p < k + i ;\n p ++ ) for ( int q = j ;\n q < k + j ;\n q ++ ) sum += mat [ p ] [ q ] ;\n System . out . print ( sum + \" \" ) ;\n }\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSumSimple ( mat , k ) :\n if ( k > n ) :\n return\n for i in range ( n - k + 1 ) :\n for j in range ( n - k + 1 ) :\n sum = 0\n for p in range ( i , k + i ) :\n for q in range ( j , k + j ) :\n sum += mat [ p ] [ q ]\n print ( sum , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-COUNT_OF_N_DIGIT_NUMBERS_WHOSE_SUM_OF_DIGITS_EQUALS_TO_GIVEN_SUM",
"pair": "python-java",
"Code1": "def findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n",
"Code2": "private static void findCount ( int n , int sum ) {\n int start = ( int ) Math . pow ( 10 , n - 1 ) ;\n int end = ( int ) Math . pow ( 10 , n ) - 1 ;\n int count = 0 ;\n int i = start ;\n while ( i < end ) {\n int cur = 0 ;\n int temp = i ;\n while ( temp != 0 ) {\n cur += temp % 10 ;\n temp = temp / 10 ;\n }\n if ( cur == sum ) {\n count ++ ;\n i += 9 ;\n }\n else i ++ ;\n }\n System . out . println ( count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findCount ( n , sum ) :\n start = math.pow ( 10 , n - 1 )\n end = math.pow ( 10 , n ) - 1\n count = 0\n i = start\n while ( i <= end ) :\n cur = 0\n temp = i\n while ( temp != 0 ) :\n cur += temp % 10\n temp = temp // 10\n if ( cur == sum ) :\n count = count + 1\n i += 9\n else :\n i = i + 1\n print ( count )\n\n"
},
{
"id": "python-java-COUNT_GROUPINGS_NUMBER_SUM_DIGITS_EVERY_SUB_GROUP_LESS_EQUALS_IMMEDIATE_RIGHT_SUB_GROUP_1",
"pair": "python-java",
"Code1": "def countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n",
"Code2": "static int countGroups ( int position , int previous_sum , int length , char [ ] num ) {\n if ( position == length ) return 1 ;\n if ( dp [ position ] [ previous_sum ] != - 1 ) return dp [ position ] [ previous_sum ] ;\n dp [ position ] [ previous_sum ] = 0 ;\n int res = 0 ;\n int sum = 0 ;\n for ( int i = position ;\n i < length ;\n i ++ ) {\n sum += ( num [ i ] - ' 0 ' ) ;\n if ( sum >= previous_sum ) res += countGroups ( i + 1 , sum , length , num ) ;\n }\n dp [ position ] [ previous_sum ] = res ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countGroups ( position , previous_sum , length , num ) :\n if ( position == length ) :\n return 1\n if ( dp [ position ] [ previous_sum ] != - 1 ) :\n return dp [ position ] [ previous_sum ]\n dp [ position ] [ previous_sum ] = 0\n res = 0\n sum = 0\n for i in range ( position , length ) :\n sum += ( ord ( num [ i ] ) - ord ( '0' ) )\n if ( sum >= previous_sum ) :\n res += countGroups ( i + 1 , sum , length , num )\n dp [ position ] [ previous_sum ] = res\n return res\n\n"
},
{
"id": "python-java-MAXIMUM_POINTS_INTERSECTION_N_CIRCLES",
"pair": "python-java",
"Code1": "def intersection ( n ) :\n return n * ( n - 1 )\n",
"Code2": "static int intersection ( int n ) {\n return n * ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef intersection ( n ) :\n return n * ( n - 1 )\n\n"
},
{
"id": "python-java-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS_2",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n",
"Code2": "static int findSum ( int n ) {\n n -- ;\n int sum = 0 ;\n sum += ( n * ( n + 1 ) ) / 2 ;\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6 ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n n -= 1\n sum = 0\n sum += ( n * ( n + 1 ) ) / 2\n sum += ( n * ( n + 1 ) * ( 2 * n + 1 ) ) / 6\n return int ( sum )\n\n"
},
{
"id": "python-java-FIND_REPEATING_ELEMENT_SORTED_ARRAY_SIZE_N",
"pair": "python-java",
"Code1": "def findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n",
"Code2": "static int findRepeatingElement ( int arr [ ] , int low , int high ) {\n if ( low > high ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( arr [ mid ] != mid + 1 ) {\n if ( mid > 0 && arr [ mid ] == arr [ mid - 1 ] ) return mid ;\n return findRepeatingElement ( arr , low , mid - 1 ) ;\n }\n return findRepeatingElement ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRepeatingElement ( arr , low , high ) :\n if low > high :\n return - 1\n mid = ( low + high ) / 2\n if ( arr [ mid ] != mid + 1 ) :\n if ( mid > 0 and arr [ mid ] == arr [ mid - 1 ] ) :\n return mid\n return findRepeatingElement ( arr , low , mid - 1 )\n return findRepeatingElement ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-java-SMALLEST_OF_THREE_INTEGERS_WITHOUT_COMPARISON_OPERATORS",
"pair": "python-java",
"Code1": "def smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n",
"Code2": "static int smallest ( int x , int y , int z ) {\n int c = 0 ;\n while ( x != 0 && y != 0 && z != 0 ) {\n x -- ;\n y -- ;\n z -- ;\n c ++ ;\n }\n return c ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef smallest ( x , y , z ) :\n c = 0\n while ( x and y and z ) :\n x = x - 1\n y = y - 1\n z = z - 1\n c = c + 1\n return c\n\n"
},
{
"id": "python-java-PATH_MAXIMUM_AVERAGE_VALUE",
"pair": "python-java",
"Code1": "def maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n",
"Code2": "public static double maxAverageOfPath ( int cost [ ] [ ] , int N ) {\n int dp [ ] [ ] = new int [ N + 1 ] [ N + 1 ] ;\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ] ;\n for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ] ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 1 ;\n j < N ;\n j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ] ;\n return ( double ) dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxAverageOfPath ( cost , N ) :\n dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( N + 1 ) ]\n dp [ 0 ] [ 0 ] = cost [ 0 ] [ 0 ]\n for i in range ( 1 , N ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + cost [ i ] [ 0 ]\n for j in range ( 1 , N ) :\n dp [ 0 ] [ j ] = dp [ 0 ] [ j - 1 ] + cost [ 0 ] [ j ]\n for i in range ( 1 , N ) :\n for j in range ( 1 , N ) :\n dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) + cost [ i ] [ j ]\n return dp [ N - 1 ] [ N - 1 ] / ( 2 * N - 1 )\n\n"
},
{
"id": "python-java-COUNT_PAIRS_DIFFERENCE_EQUAL_K",
"pair": "python-java",
"Code1": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n",
"Code2": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] - arr [ j ] == k || arr [ j ] - arr [ i ] == k ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairsWithDiffK ( arr , n , k ) :\n count = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] - arr [ j ] == k or arr [ j ] - arr [ i ] == k :\n count += 1\n return count\n\n"
},
{
"id": "python-java-LONGEST_SUBSEQUENCE_DIFFERENCE_ADJACENTS_ONE_SET_2",
"pair": "python-java",
"Code1": "def longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n",
"Code2": "static int longLenSub ( int [ ] arr , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int longLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int len = 0 ;\n if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ;\n if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ;\n um . put ( arr [ i ] , len + 1 ) ;\n if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ;\n }\n return longLen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longLenSub ( arr , n ) :\n um = defaultdict ( lambda : 0 )\n longLen = 0\n for i in range ( n ) :\n len1 = 0\n if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :\n len1 = um [ arr [ i ] - 1 ]\n if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :\n len1 = um [ arr [ i ] + 1 ]\n um [ arr [ i ] ] = len1 + 1\n if longLen < um [ arr [ i ] ] :\n longLen = um [ arr [ i ] ]\n return longLen\n\n"
},
{
"id": "python-java-RECURSIVE_PROGRAM_PRIME_NUMBER",
"pair": "python-java",
"Code1": "def isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n",
"Code2": "static boolean isPrime ( int n , int i ) {\n if ( n <= 2 ) return ( n == 2 ) ? true : false ;\n if ( n % i == 0 ) return false ;\n if ( i * i > n ) return true ;\n return isPrime ( n , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPrime ( n , i = 2 ) :\n if ( n <= 2 ) :\n return True if ( n == 2 ) else False\n if ( n % i == 0 ) :\n return False\n if ( i * i > n ) :\n return true\n return isPrime ( n , i + 1 )\n\n"
},
{
"id": "python-java-FIND_LAST_DIGIT_FACTORIAL_DIVIDES_FACTORIAL_B",
"pair": "python-java",
"Code1": "def computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n",
"Code2": "static int computeLastDigit ( long A , long B ) {\n int variable = 1 ;\n if ( A == B ) return 1 ;\n else if ( ( B - A ) >= 5 ) return 0 ;\n else {\n for ( long i = A + 1 ;\n i <= B ;\n i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ;\n return variable % 10 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef computeLastDigit ( A , B ) :\n variable = 1\n if ( A == B ) :\n return 1\n elif ( ( B - A ) >= 5 ) :\n return 0\n else :\n for i in range ( A + 1 , B + 1 ) :\n variable = ( variable * ( i % 10 ) ) % 10\n return variable % 10\n\n"
},
{
"id": "python-java-MINIMUM_OPERATIONS_REQUIRED_SET_ELEMENTS_BINARY_MATRIX",
"pair": "python-java",
"Code1": "def minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n",
"Code2": "static int minOperation ( boolean arr [ ] [ ] ) {\n int ans = 0 ;\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = M - 1 ;\n j >= 0 ;\n j -- ) {\n if ( arr [ i ] [ j ] == false ) {\n ans ++ ;\n for ( int k = 0 ;\n k <= i ;\n k ++ ) {\n for ( int h = 0 ;\n h <= j ;\n h ++ ) {\n if ( arr [ k ] [ h ] == true ) {\n arr [ k ] [ h ] = false ;\n }\n else {\n arr [ k ] [ h ] = true ;\n }\n }\n }\n }\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minOperation ( arr ) :\n ans = 0\n for i in range ( N - 1 , - 1 , - 1 ) :\n for j in range ( M - 1 , - 1 , - 1 ) :\n if ( arr [ i ] [ j ] == 0 ) :\n ans += 1\n for k in range ( i + 1 ) :\n for h in range ( j + 1 ) :\n if ( arr [ k ] [ h ] == 1 ) :\n arr [ k ] [ h ] = 0\n else :\n arr [ k ] [ h ] = 1\n return ans\n\n"
},
{
"id": "python-java-NEXT_POWER_OF_2_1",
"pair": "python-java",
"Code1": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n\n"
},
{
"id": "python-java-MINIMIZE_THE_MAXIMUM_DIFFERENCE_BETWEEN_THE_HEIGHTS",
"pair": "python-java",
"Code1": "def getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n",
"Code2": "static int getMinDiff ( int arr [ ] , int n , int k ) {\n if ( n == 1 ) return 0 ;\n Arrays . sort ( arr ) ;\n int ans = arr [ n - 1 ] - arr [ 0 ] ;\n int small = arr [ 0 ] + k ;\n int big = arr [ n - 1 ] - k ;\n int temp = 0 ;\n if ( small > big ) {\n temp = small ;\n small = big ;\n big = temp ;\n }\n for ( int i = 1 ;\n i < n - 1 ;\n i ++ ) {\n int subtract = arr [ i ] - k ;\n int add = arr [ i ] + k ;\n if ( subtract >= small || add <= big ) continue ;\n if ( big - subtract <= add - small ) small = subtract ;\n else big = add ;\n }\n return Math . min ( ans , big - small ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMinDiff ( arr , n , k ) :\n if ( n == 1 ) :\n return 0\n arr.sort ( )\n ans = arr [ n - 1 ] - arr [ 0 ]\n small = arr [ 0 ] + k\n big = arr [ n - 1 ] - k\n if ( small > big ) :\n small , big = big , small\n for i in range ( 1 , n - 1 ) :\n subtract = arr [ i ] - k\n add = arr [ i ] + k\n if ( subtract >= small or add <= big ) :\n continue\n if ( big - subtract <= add - small ) :\n small = subtract\n else :\n big = add\n return min ( ans , big - small )\n\n"
},
{
"id": "python-java-DIFFERENT_WAYS_SUM_N_USING_NUMBERS_GREATER_EQUAL_M",
"pair": "python-java",
"Code1": "def numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n",
"Code2": "static int numberofways ( int n , int m ) {\n int dp [ ] [ ] = new int [ n + 2 ] [ n + 2 ] ;\n dp [ 0 ] [ n + 1 ] = 1 ;\n for ( int k = n ;\n k >= m ;\n k -- ) {\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ] ;\n if ( i - k >= 0 ) dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] ) ;\n }\n }\n return dp [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberofways ( n , m ) :\n dp = np.zeros ( ( n + 2 , n + 2 ) )\n dp [ 0 ] [ n + 1 ] = 1\n for k in range ( n , m - 1 , - 1 ) :\n for i in range ( n + 1 ) :\n dp [ i ] [ k ] = dp [ i ] [ k + 1 ]\n if ( i - k >= 0 ) :\n dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )\n return dp [ n ] [ m ]\n\n"
},
{
"id": "python-java-FIND_WHETHER_GIVEN_INTEGER_POWER_3_NOT",
"pair": "python-java",
"Code1": "def check ( n ) :\n return 1162261467 % n == 0\n",
"Code2": "static boolean check ( int n ) {\n return 1162261467 % n == 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( n ) :\n return 1162261467 % n == 0\n\n"
},
{
"id": "python-java-NEWMAN_CONWAY_SEQUENCE",
"pair": "python-java",
"Code1": "def sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n",
"Code2": "static int sequence ( int n ) {\n if ( n == 1 || n == 2 ) return 1 ;\n else return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n if n == 1 or n == 2 :\n return 1\n else :\n return sequence ( sequence ( n - 1 ) ) + sequence ( n - sequence ( n - 1 ) ) ;\n\n"
},
{
"id": "python-java-SMALLEST_DERANGEMENT_SEQUENCE",
"pair": "python-java",
"Code1": "def generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n",
"Code2": "static void generate_derangement ( int N ) {\n int S [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) S [ i ] = i ;\n int D [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i += 2 ) {\n if ( i == N ) {\n D [ N ] = S [ N - 1 ] ;\n D [ N - 1 ] = S [ N ] ;\n }\n else {\n D [ i ] = i + 1 ;\n D [ i + 1 ] = i ;\n }\n }\n for ( int i = 1 ;\n i <= N ;\n i ++ ) System . out . print ( D [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef generate_derangement ( N ) :\n S = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n S [ i ] = i\n D = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 , 2 ) :\n if i == N :\n D [ N ] = S [ N - 1 ]\n D [ N - 1 ] = S [ N ]\n else :\n D [ i ] = i + 1\n D [ i + 1 ] = i\n for i in range ( 1 , N + 1 ) :\n print ( D [ i ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-NUMBER_OF_TRIANGLES_IN_DIRECTED_AND_UNDIRECTED_GRAPHS",
"pair": "python-java",
"Code1": "def countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n",
"Code2": "int countTriangle ( int graph [ ] [ ] , boolean isDirected ) {\n int count_Triangle = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n for ( int j = 0 ;\n j < V ;\n j ++ ) {\n for ( int k = 0 ;\n k < V ;\n k ++ ) {\n if ( graph [ i ] [ j ] == 1 && graph [ j ] [ k ] == 1 && graph [ k ] [ i ] == 1 ) count_Triangle ++ ;\n }\n }\n }\n if ( isDirected == true ) {\n count_Triangle /= 3 ;\n }\n else {\n count_Triangle /= 6 ;\n }\n return count_Triangle ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countTriangle ( g , isDirected ) :\n nodes = len ( g )\n count_Triangle = 0\n for i in range ( nodes ) :\n for j in range ( nodes ) :\n for k in range ( nodes ) :\n if ( i != j and i != k and j != k and g [ i ] [ j ] and g [ j ] [ k ] and g [ k ] [ i ] ) :\n count_Triangle += 1\n return count_Triangle / 3 if isDirected else count_Triangle / 6\n\n"
},
{
"id": "python-java-HEIGHT_N_ARY_TREE_PARENT_ARRAY_GIVEN",
"pair": "python-java",
"Code1": "def findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n",
"Code2": "static int findHeight ( int [ ] parent , int n ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int p = i , current = 1 ;\n while ( parent [ p ] != - 1 ) {\n current ++ ;\n p = parent [ p ] ;\n }\n res = Math . max ( res , current ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findHeight ( parent , n ) :\n res = 0\n for i in range ( n ) :\n p = i\n current = 1\n while ( parent [ p ] != - 1 ) :\n current += 1\n p = parent [ p ]\n res = max ( res , current )\n return res\n\n"
},
{
"id": "python-java-LEONARDO_NUMBER",
"pair": "python-java",
"Code1": "def leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n",
"Code2": "static int leonardo ( int n ) {\n if ( n == 0 || n == 1 ) return 1 ;\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef leonardo ( n ) :\n if ( n == 0 or n == 1 ) :\n return 1\n return ( leonardo ( n - 1 ) + leonardo ( n - 2 ) + 1 )\n\n"
},
{
"id": "python-java-FIND_SIZE_OF_THE_LARGEST_FORMED_BY_ALL_ONES_IN_A_BINARY_MATRIX",
"pair": "python-java",
"Code1": "def findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n",
"Code2": "static int findLargestPlus ( int mat [ ] [ ] ) {\n int left [ ] [ ] = new int [ N ] [ N ] ;\n int right [ ] [ ] = new int [ N ] [ N ] ;\n int top [ ] [ ] = new int [ N ] [ N ] ;\n int bottom [ ] [ ] = new int [ N ] [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n top [ 0 ] [ i ] = mat [ 0 ] [ i ] ;\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ] ;\n left [ i ] [ 0 ] = mat [ i ] [ 0 ] ;\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ] ;\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 1 ;\n j < N ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1 ;\n else left [ i ] [ j ] = 0 ;\n if ( mat [ j ] [ i ] == 1 ) top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1 ;\n else top [ j ] [ i ] = 0 ;\n j = N - 1 - j ;\n if ( mat [ j ] [ i ] == 1 ) bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1 ;\n else bottom [ j ] [ i ] = 0 ;\n if ( mat [ i ] [ j ] == 1 ) right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1 ;\n else right [ i ] [ j ] = 0 ;\n j = N - 1 - j ;\n }\n }\n int n = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n int len = Math . min ( Math . min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , Math . min ( left [ i ] [ j ] , right [ i ] [ j ] ) ) ;\n if ( len > n ) n = len ;\n }\n }\n if ( n > 0 ) return 4 * ( n - 1 ) + 1 ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLargestPlus ( mat ) :\n left = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n right = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n top = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n bottom = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n for i in range ( N ) :\n top [ 0 ] [ i ] = mat [ 0 ] [ i ]\n bottom [ N - 1 ] [ i ] = mat [ N - 1 ] [ i ]\n left [ i ] [ 0 ] = mat [ i ] [ 0 ]\n right [ i ] [ N - 1 ] = mat [ i ] [ N - 1 ]\n for i in range ( N ) :\n for j in range ( 1 , N ) :\n if ( mat [ i ] [ j ] == 1 ) :\n left [ i ] [ j ] = left [ i ] [ j - 1 ] + 1\n else :\n left [ i ] [ j ] = 0\n if ( mat [ j ] [ i ] == 1 ) :\n top [ j ] [ i ] = top [ j - 1 ] [ i ] + 1\n else :\n top [ j ] [ i ] = 0\n j = N - 1 - j\n if ( mat [ j ] [ i ] == 1 ) :\n bottom [ j ] [ i ] = bottom [ j + 1 ] [ i ] + 1\n else :\n bottom [ j ] [ i ] = 0\n if ( mat [ i ] [ j ] == 1 ) :\n right [ i ] [ j ] = right [ i ] [ j + 1 ] + 1\n else :\n right [ i ] [ j ] = 0\n j = N - 1 - j\n n = 0\n for i in range ( N ) :\n for j in range ( N ) :\n l = min ( min ( top [ i ] [ j ] , bottom [ i ] [ j ] ) , min ( left [ i ] [ j ] , right [ i ] [ j ] ) )\n if ( l > n ) :\n n = l\n if ( n ) :\n return 4 * ( n - 1 ) + 1\n return 0\n\n"
},
{
"id": "python-java-CENTER_ELEMENT_OF_MATRIX_EQUALS_SUMS_OF_HALF_DIAGONALS",
"pair": "python-java",
"Code1": "def HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n",
"Code2": "static boolean HalfDiagonalSums ( int mat [ ] [ ] , int n ) {\n int diag1_left = 0 , diag1_right = 0 ;\n int diag2_left = 0 , diag2_right = 0 ;\n for ( int i = 0 , j = n - 1 ;\n i < n ;\n i ++ , j -- ) {\n if ( i < n / 2 ) {\n diag1_left += mat [ i ] [ i ] ;\n diag2_left += mat [ j ] [ i ] ;\n }\n else if ( i > n / 2 ) {\n diag1_right += mat [ i ] [ i ] ;\n diag2_right += mat [ j ] [ i ] ;\n }\n }\n return ( diag1_left == diag2_right && diag2_right == diag2_left && diag1_right == diag2_left && diag2_right == mat [ n / 2 ] [ n / 2 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef HalfDiagonalSums ( mat , n ) :\n diag1_left = 0\n diag1_right = 0\n diag2_left = 0\n diag2_right = 0\n i = 0\n j = n - 1\n while i < n :\n if ( i < n // 2 ) :\n diag1_left += mat [ i ] [ i ]\n diag2_left += mat [ j ] [ i ]\n elif ( i > n // 2 ) :\n diag1_right += mat [ i ] [ i ]\n diag2_right += mat [ j ] [ i ]\n i += 1\n j -= 1\n return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )\n\n"
},
{
"id": "python-java-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING",
"pair": "python-java",
"Code1": "def sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n",
"Code2": "static int sumAtKthLevel ( String tree , int k ) {\n int level = - 1 ;\n int sum = 0 ;\n int n = tree . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( tree . charAt ( i ) == ' ( ' ) level ++ ;\n else if ( tree . charAt ( i ) == ' ) ' ) level -- ;\n else {\n if ( level == k ) sum += ( tree . charAt ( i ) - ' 0 ' ) ;\n }\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumAtKthLevel ( tree , k ) :\n level = - 1\n sum = 0\n n = len ( tree )\n for i in range ( n ) :\n if ( tree [ i ] == '(' ) :\n level += 1\n elif ( tree [ i ] == ')' ) :\n level -= 1\n else :\n if ( level == k ) :\n sum += ( ord ( tree [ i ] ) - ord ( '0' ) )\n return sum\n\n"
},
{
"id": "python-java-LEIBNIZ_HARMONIC_TRIANGLE",
"pair": "python-java",
"Code1": "def LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n",
"Code2": "static void LeibnizHarmonicTriangle ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= i ;\n j ++ ) System . out . print ( \"1/\" + i * C [ i - 1 ] [ j - 1 ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef LeibnizHarmonicTriangle ( n ) :\n C = [ [ 0 for x in range ( n + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , i + 1 ) :\n print ( \"1/\" , end = \"\" )\n print ( i * C [ i - 1 ] [ j - 1 ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-WAYS_SPLIT_STRING_PARTITION_STARTS_DISTINCT_CHARACTER",
"pair": "python-java",
"Code1": "def countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n",
"Code2": "static int countWays ( String s ) {\n int count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( 0 ) - ' a ' ] = 1 ;\n int ans = 1 ;\n for ( int i = 0 ;\n i < 26 ;\n ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWays ( s ) :\n count = [ 0 ] * 26\n for x in s :\n count [ ord ( x ) - ord ( 'a' ) ] = ( count [ ord ( x ) - ord ( 'a' ) ] ) + 1\n count [ ord ( s [ 0 ] ) - ord ( 'a' ) ] = 1\n ans = 1\n for i in range ( 26 ) :\n if ( count [ i ] != 0 ) :\n ans *= count [ i ]\n return ans\n\n"
},
{
"id": "python-java-COUNT_NUMBER_WAYS_TILE_FLOOR_SIZE_N_X_M_USING_1_X_M_SIZE_TILES",
"pair": "python-java",
"Code1": "def countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n",
"Code2": "static int countWays ( int n , int m ) {\n int count [ ] = new int [ n + 1 ] ;\n count [ 0 ] = 0 ;\n int i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ;\n else if ( i < m ) count [ i ] = 1 ;\n else count [ i ] = 2 ;\n }\n return count [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWays ( n , m ) :\n count = [ ]\n for i in range ( n + 2 ) :\n count.append ( 0 )\n count [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n if ( i > m ) :\n count [ i ] = count [ i - 1 ] + count [ i - m ]\n elif ( i < m ) :\n count [ i ] = 1\n else :\n count [ i ] = 2\n return count [ n ]\n\n"
},
{
"id": "python-java-COMMON_ELEMENTS_IN_ALL_ROWS_OF_A_GIVEN_MATRIX",
"pair": "python-java",
"Code1": "def printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n",
"Code2": "static void printCommonElements ( int mat [ ] [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int j = 0 ;\n j < N ;\n j ++ ) mp . put ( mat [ 0 ] [ j ] , 1 ) ;\n for ( int i = 1 ;\n i < M ;\n i ++ ) {\n for ( int j = 0 ;\n j < N ;\n j ++ ) {\n if ( mp . get ( mat [ i ] [ j ] ) != null && mp . get ( mat [ i ] [ j ] ) == i ) {\n mp . put ( mat [ i ] [ j ] , i + 1 ) ;\n if ( i == M - 1 ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printCommonElements ( mat ) :\n mp = dict ( )\n for j in range ( N ) :\n mp [ mat [ 0 ] [ j ] ] = 1\n for i in range ( 1 , M ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] in mp.keys ( ) and mp [ mat [ i ] [ j ] ] == i ) :\n mp [ mat [ i ] [ j ] ] = i + 1\n if i == M - 1 :\n print ( mat [ i ] [ j ] , end = \" \" )\n\n"
},
{
"id": "python-java-FLOOR_IN_A_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n",
"Code2": "static int floorSearch ( int arr [ ] , int n , int x ) {\n if ( x >= arr [ n - 1 ] ) return n - 1 ;\n if ( x < arr [ 0 ] ) return - 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > x ) return ( i - 1 ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef floorSearch ( arr , low , high , x ) :\n if ( low > high ) :\n return - 1\n if ( x >= arr [ high ] ) :\n return high\n mid = int ( ( low + high ) / 2 )\n if ( arr [ mid ] == x ) :\n return mid\n if ( mid > 0 and arr [ mid - 1 ] <= x and x < arr [ mid ] ) :\n return mid - 1\n if ( x < arr [ mid ] ) :\n return floorSearch ( arr , low , mid - 1 , x )\n return floorSearch ( arr , mid + 1 , high , x )\n\n"
},
{
"id": "python-java-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_1",
"pair": "python-java",
"Code1": "def nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int p = 1 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( p < n ) p <<= 1 ;\n return p ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n p = 1\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( p < n ) :\n p <<= 1\n return p\n\n"
},
{
"id": "python-java-KTH_ADJACENT_NODE_GRAPH_VERTEX_WEIGHT",
"pair": "python-java",
"Code1": "def printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n",
"Code2": "static void printkthnode ( Vector < pair > adj [ ] , int wt [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) Collections . sort ( adj [ i ] , new Comparator < pair > ( ) {\n public int compare ( pair p1 , pair p2 ) {\n return p1 . first - p2 . first ;\n }\n }\n ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( adj [ i ] . size ( ) >= k ) System . out . print ( adj [ i ] . get ( adj [ i ] . size ( ) - k ) . second + \" \" ) ;\n else System . out . print ( \"-1\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printkthnode ( adj , wt , n , k ) :\n for i in range ( n ) :\n adj [ i ].sort ( )\n for i in range ( n ) :\n if ( len ( adj [ i ] ) >= k ) :\n print ( adj [ i ] [ len ( adj [ i ] ) - k ] [ 1 ] , end = \" \" )\n else :\n print ( \"-1\" , end = \" \" )\n\n"
},
{
"id": "python-java-LONGEST_SUBARRAY_NOT_K_DISTINCT_ELEMENTS",
"pair": "python-java",
"Code1": "def longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "static void longest ( int a [ ] , int n , int k ) {\n int [ ] freq = new int [ 7 ] ;\n int start = 0 , end = 0 , now = 0 , l = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ a [ i ] ] ++ ;\n if ( freq [ a [ i ] ] == 1 ) now ++ ;\n while ( now > k ) {\n freq [ a [ l ] ] -- ;\n if ( freq [ a [ l ] ] == 0 ) now -- ;\n l ++ ;\n }\n if ( i - l + 1 >= end - start + 1 ) {\n end = i ;\n start = l ;\n }\n }\n for ( int i = start ;\n i <= end ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longest ( a , n , k ) :\n freq = [ 0 ] * n\n start = 0\n end = 0\n now = 0\n l = 0\n for i in range ( n ) :\n freq [ a [ i ] ] += 1\n if ( freq [ a [ i ] ] == 1 ) :\n now += 1\n while ( now > k ) :\n freq [ a [ l ] ] -= 1\n if ( freq [ a [ l ] ] == 0 ) :\n now -= 1\n l += 1\n if ( i - l + 1 >= end - start + 1 ) :\n end = i\n start = l\n for i in range ( start , end + 1 ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-MINIMUM_FLIP_REQUIRED_MAKE_BINARY_MATRIX_SYMMETRIC_1",
"pair": "python-java",
"Code1": "def minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n",
"Code2": "static int minimumflip ( int mat [ ] [ ] , int n ) {\n int flip = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) flip ++ ;\n return flip ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minimumflip ( mat , n ) :\n flip = 0\n for i in range ( n ) :\n for j in range ( i ) :\n if mat [ i ] [ j ] != mat [ j ] [ i ] :\n flip += 1\n return flip\n\n"
},
{
"id": "python-java-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM",
"pair": "python-java",
"Code1": "def breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n",
"Code2": "static int breakSum ( int n ) {\n if ( n == 0 || n == 1 ) return n ;\n return Math . max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef breakSum ( n ) :\n if ( n == 0 or n == 1 ) :\n return n\n return max ( ( breakSum ( n // 2 ) + breakSum ( n // 3 ) + breakSum ( n // 4 ) ) , n )\n\n"
},
{
"id": "python-java-COUNT_PAIRS_TWO_SORTED_ARRAYS_WHOSE_SUM_EQUAL_GIVEN_VALUE_X",
"pair": "python-java",
"Code1": "def countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n",
"Code2": "static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr1 , arr2 , m , n , x ) :\n count = 0\n for i in range ( m ) :\n for j in range ( n ) :\n if arr1 [ i ] + arr2 [ j ] == x :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-LONGEST_ALTERNATING_SUB_ARRAY_STARTING_EVERY_INDEX_BINARY_ARRAY",
"pair": "python-java",
"Code1": "def alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n",
"Code2": "static void alternateSubarray ( boolean arr [ ] , int n ) {\n int len [ ] = new int [ n ] ;\n len [ n - 1 ] = 1 ;\n for ( int i = n - 2 ;\n i >= 0 ;\n -- i ) {\n if ( arr [ i ] ^ arr [ i + 1 ] == true ) len [ i ] = len [ i + 1 ] + 1 ;\n else len [ i ] = 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n ++ i ) System . out . print ( len [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef alternateSubarray ( arr , n ) :\n len = [ ]\n for i in range ( n + 1 ) :\n len.append ( 0 )\n len [ n - 1 ] = 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] ^ arr [ i + 1 ] == True ) :\n len [ i ] = len [ i + 1 ] + 1\n else :\n len [ i ] = 1\n for i in range ( n ) :\n print ( len [ i ] , \"\" , end = \"\" )\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_LARGEST_SUBSEQUENCE_EVERY_CHARACTER_OCCURS_LEAST_K_TIMES",
"pair": "python-java",
"Code1": "def subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n",
"Code2": "static void subsequence ( char s [ ] , char t [ ] , int n , int k ) {\n int last = 0 , cnt = 0 , new_last = 0 , size = 0 ;\n for ( char ch = ' z ' ;\n ch >= ' a ' ;\n ch -- ) {\n cnt = 0 ;\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) cnt ++ ;\n }\n if ( cnt >= k ) {\n for ( int i = last ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == ch ) {\n t [ size ++ ] = ch ;\n new_last = i ;\n }\n }\n last = new_last ;\n }\n }\n t [ size ] = ' \\0 ' ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subsequence ( s , t , n , k ) :\n last = 0\n cnt = 0\n new_last = 0\n size = 0\n string = 'zyxwvutsrqponmlkjihgfedcba'\n for ch in string :\n cnt = 0\n for i in range ( last , n ) :\n if s [ i ] == ch :\n cnt += 1\n if cnt >= k :\n for i in range ( last , n ) :\n if s [ i ] == ch :\n t [ size ] = ch\n new_last = i\n size += 1\n last = new_last\n\n"
},
{
"id": "python-java-FIND_THE_LARGEST_SUBARRAY_WITH_0_SUM",
"pair": "python-java",
"Code1": "def maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n",
"Code2": "static int maxLen ( int arr [ ] , int n ) {\n int max_len = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int curr_sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n curr_sum += arr [ j ] ;\n if ( curr_sum == 0 ) max_len = Math . max ( max_len , j - i + 1 ) ;\n }\n }\n return max_len ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLen ( arr ) :\n max_len = 0\n for i in range ( len ( arr ) ) :\n curr_sum = 0\n for j in range ( i , len ( arr ) ) :\n curr_sum += arr [ j ]\n if curr_sum == 0 :\n max_len = max ( max_len , j - i + 1 )\n return max_len\n\n"
},
{
"id": "python-java-DICE_THROW_PROBLEM",
"pair": "python-java",
"Code1": "def findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n",
"Code2": "public static long findWays ( int m , int n , int x ) {\n long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ;\n for ( int j = 1 ;\n j <= m && j <= x ;\n j ++ ) table [ 1 ] [ j ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= x ;\n j ++ ) {\n for ( int k = 1 ;\n k < j && k <= m ;\n k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ;\n }\n }\n return table [ n ] [ x ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findWays ( m , n , x ) :\n table = [ [ 0 ] * ( x + 1 ) for i in range ( n + 1 ) ]\n for j in range ( 1 , min ( m + 1 , x + 1 ) ) :\n table [ 1 ] [ j ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , x + 1 ) :\n for k in range ( 1 , min ( m + 1 , j ) ) :\n table [ i ] [ j ] += table [ i - 1 ] [ j - k ]\n return table [ - 1 ] [ - 1 ]\n\n"
},
{
"id": "python-java-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER_1",
"pair": "python-java",
"Code1": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n",
"Code2": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count [ s . charAt ( i ) - ' a ' ] ++ ;\n count [ s . charAt ( j ) - ' a ' ] -- ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count [ i ] != 0 ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while i < j :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count [ ord ( s [ j ] ) - ord ( 'a' ) ] -= 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count [ i ] != 0 :\n return False\n return True\n\n"
},
{
"id": "python-java-FIND_NUMBER_OF_TRIANGLES_POSSIBLE",
"pair": "python-java",
"Code1": "def findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n",
"Code2": "static int findNumberOfTriangles ( int arr [ ] ) {\n int n = arr . length ;\n Arrays . sort ( arr ) ;\n int count = 0 ;\n for ( int i = 0 ;\n i < n - 2 ;\n ++ i ) {\n int k = i + 2 ;\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ;\n if ( k > j ) count += k - j - 1 ;\n }\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findnumberofTriangles ( arr ) :\n n = len ( arr )\n arr.sort ( )\n count = 0\n for i in range ( 0 , n - 2 ) :\n k = i + 2\n for j in range ( i + 1 , n ) :\n while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) :\n k += 1\n if ( k > j ) :\n count += k - j - 1\n return count\n\n"
},
{
"id": "python-java-TILING_WITH_DOMINOES",
"pair": "python-java",
"Code1": "def countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n",
"Code2": "static int countWays ( int n ) {\n int [ ] A = new int [ n + 1 ] ;\n int [ ] B = new int [ n + 1 ] ;\n A [ 0 ] = 1 ;\n A [ 1 ] = 0 ;\n B [ 0 ] = 0 ;\n B [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ] ;\n B [ i ] = A [ i - 1 ] + B [ i - 2 ] ;\n }\n return A [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWays ( n ) :\n A = [ 0 ] * ( n + 1 )\n B = [ 0 ] * ( n + 1 )\n A [ 0 ] = 1\n A [ 1 ] = 0\n B [ 0 ] = 0\n B [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n A [ i ] = A [ i - 2 ] + 2 * B [ i - 1 ]\n B [ i ] = A [ i - 1 ] + B [ i - 2 ]\n return A [ n ]\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_4_LONGEST_COMMON_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"Code2": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n\n"
},
{
"id": "python-java-MINIMIZE_SUM_PRODUCT_TWO_ARRAYS_PERMUTATIONS_ALLOWED",
"pair": "python-java",
"Code1": "def minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n",
"Code2": "static int minValue ( int A [ ] , int B [ ] , int n ) {\n Arrays . sort ( A ) ;\n Arrays . sort ( B ) ;\n int result = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) result += ( A [ i ] * B [ n - i - 1 ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minValue ( A , B , n ) :\n sorted ( A )\n sorted ( B )\n result = 0\n for i in range ( n ) :\n result += ( A [ i ] * B [ n - i - 1 ] )\n return result\n\n"
},
{
"id": "python-java-CHANGE_BITS_CAN_MADE_ONE_FLIP_1",
"pair": "python-java",
"Code1": "def isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n",
"Code2": "static boolean isOneFlip ( String str ) {\n int sum = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += str . charAt ( i ) - ' 0 ' ;\n return ( sum == n - 1 || sum == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isOneFlip ( str ) :\n sum = 0\n n = len ( str )\n for i in range ( 0 , n ) :\n sum += int ( str [ i ] ) - int ( '0' )\n return ( sum == n - 1 or sum == 1 )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_8_MATRIX_CHAIN_MULTIPLICATION",
"pair": "python-java",
"Code1": "def MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n",
"Code2": "static int MatrixChainOrder ( int p [ ] , int i , int j ) {\n if ( i == j ) return 0 ;\n int min = Integer . MAX_VALUE ;\n for ( int k = i ;\n k < j ;\n k ++ ) {\n int count = MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] ;\n if ( count < min ) min = count ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MatrixChainOrder ( p , i , j ) :\n if i == j :\n return 0\n _min = sys.maxsize\n for k in range ( i , j ) :\n count = ( MatrixChainOrder ( p , i , k ) + MatrixChainOrder ( p , k + 1 , j ) + p [ i - 1 ] * p [ k ] * p [ j ] )\n if count < _min :\n _min = count\n return _min\n\n"
},
{
"id": "python-java-MULTIPLY_TWO_NUMBERS_WITHOUT_USING_MULTIPLY_DIVISION_BITWISE_OPERATORS_AND_NO_LOOPS",
"pair": "python-java",
"Code1": "def multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n",
"Code2": "static int multiply ( int x , int y ) {\n if ( y == 0 ) return 0 ;\n if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ;\n if ( y < 0 ) return - multiply ( x , - y ) ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef multiply ( x , y ) :\n if ( y == 0 ) :\n return 0\n if ( y > 0 ) :\n return ( x + multiply ( x , y - 1 ) )\n if ( y < 0 ) :\n return - multiply ( x , - y )\n\n"
},
{
"id": "python-java-COUNT_NUMBER_OF_WAYS_TO_PARTITION_A_SET_INTO_K_SUBSETS_1",
"pair": "python-java",
"Code1": "def countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n",
"Code2": "static int countP ( int n , int k ) {\n int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 0 ;\n i <= k ;\n i ++ ) dp [ 0 ] [ k ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = 1 ;\n j <= k ;\n j ++ ) if ( j == 1 || i == j ) dp [ i ] [ j ] = 1 ;\n else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ;\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countP ( n , k ) :\n dp = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( k + 1 ) :\n dp [ 0 ] [ k ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n if ( j == 1 or i == j ) :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = ( j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-java-PROGRAM_WORST_FIT_ALGORITHM_MEMORY_MANAGEMENT",
"pair": "python-java",
"Code1": "def worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n",
"Code2": "static void worstFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) {\n int allocation [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < allocation . length ;\n i ++ ) allocation [ i ] = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int wstIdx = - 1 ;\n for ( int j = 0 ;\n j < m ;\n j ++ ) {\n if ( blockSize [ j ] >= processSize [ i ] ) {\n if ( wstIdx == - 1 ) wstIdx = j ;\n else if ( blockSize [ wstIdx ] < blockSize [ j ] ) wstIdx = j ;\n }\n }\n if ( wstIdx != - 1 ) {\n allocation [ i ] = wstIdx ;\n blockSize [ wstIdx ] -= processSize [ i ] ;\n }\n }\n System . out . println ( \"\\nProcess No.\\tProcess Size\\tBlock no.\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( \" \" + ( i + 1 ) + \"\\t\\t\" + processSize [ i ] + \"\\t\\t\" ) ;\n if ( allocation [ i ] != - 1 ) System . out . print ( allocation [ i ] + 1 ) ;\n else System . out . print ( \"Not Allocated\" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef worstFit ( blockSize , m , processSize , n ) :\n allocation = [ - 1 ] * n\n for i in range ( n ) :\n wstIdx = - 1\n for j in range ( m ) :\n if blockSize [ j ] >= processSize [ i ] :\n if wstIdx == - 1 :\n wstIdx = j\n elif blockSize [ wstIdx ] < blockSize [ j ] :\n wstIdx = j\n if wstIdx != - 1 :\n allocation [ i ] = wstIdx\n blockSize [ wstIdx ] -= processSize [ i ]\n print ( \"Process No.Process Size Block no.\" )\n for i in range ( n ) :\n print ( i + 1 , \" \" , processSize [ i ] , end = \" \" )\n if allocation [ i ] != - 1 :\n print ( allocation [ i ] + 1 )\n else :\n print ( \"Not Allocated\" )\n\n"
},
{
"id": "python-java-MAXIMIZE_VOLUME_CUBOID_GIVEN_SUM_SIDES_1",
"pair": "python-java",
"Code1": "def maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n",
"Code2": "static int maxvolume ( int s ) {\n int length = s / 3 ;\n s -= length ;\n int breadth = s / 2 ;\n int height = s - breadth ;\n return length * breadth * height ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxvolume ( s ) :\n length = int ( s / 3 )\n s -= length\n breadth = s / 2\n height = s - breadth\n return int ( length * breadth * height )\n\n"
},
{
"id": "python-java-LONGEST_EVEN_LENGTH_SUBSTRING_SUM_FIRST_SECOND_HALF_1",
"pair": "python-java",
"Code1": "def findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n",
"Code2": "static int findLength ( String str ) {\n int n = str . length ( ) ;\n int maxlen = 0 ;\n int sum [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum [ i ] [ i ] = str . charAt ( i ) - ' 0 ' ;\n for ( int len = 2 ;\n len <= n ;\n len ++ ) {\n for ( int i = 0 ;\n i < n - len + 1 ;\n i ++ ) {\n int j = i + len - 1 ;\n int k = len / 2 ;\n sum [ i ] [ j ] = sum [ i ] [ j - k ] + sum [ j - k + 1 ] [ j ] ;\n if ( len % 2 == 0 && sum [ i ] [ j - k ] == sum [ ( j - k + 1 ) ] [ j ] && len > maxlen ) maxlen = len ;\n }\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLength ( string ) :\n n = len ( string )\n maxlen = 0\n Sum = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( 0 , n ) :\n Sum [ i ] [ i ] = int ( string [ i ] )\n for length in range ( 2 , n + 1 ) :\n for i in range ( 0 , n - length + 1 ) :\n j = i + length - 1\n k = length // 2\n Sum [ i ] [ j ] = ( Sum [ i ] [ j - k ] + Sum [ j - k + 1 ] [ j ] )\n if ( length % 2 == 0 and Sum [ i ] [ j - k ] == Sum [ ( j - k + 1 ) ] [ j ] and length > maxlen ) :\n maxlen = length\n return maxlen\n\n"
},
{
"id": "python-java-FIND_SUBARRAY_WITH_GIVEN_SUM_1",
"pair": "python-java",
"Code1": "def subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n",
"Code2": "int subArraySum ( int arr [ ] , int n , int sum ) {\n int curr_sum = arr [ 0 ] , start = 0 , i ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n while ( curr_sum > sum && start < i - 1 ) {\n curr_sum = curr_sum - arr [ start ] ;\n start ++ ;\n }\n if ( curr_sum == sum ) {\n int p = i - 1 ;\n System . out . println ( \"Sum found between indexes \" + start + \" and \" + p ) ;\n return 1 ;\n }\n if ( i < n ) curr_sum = curr_sum + arr [ i ] ;\n }\n System . out . println ( \"No subarray found\" ) ;\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef subArraySum ( arr , n , sum ) :\n curr_sum = arr [ 0 ]\n start = 0\n i = 1\n while i <= n :\n while curr_sum > sum and start < i - 1 :\n curr_sum = curr_sum - arr [ start ]\n start += 1\n if curr_sum == sum :\n print ( \"Sum found between indexes\" )\n print ( \"%d and %d\" % ( start , i - 1 ) )\n return 1\n if i < n :\n curr_sum = curr_sum + arr [ i ]\n i += 1\n print ( \"No subarray found\" )\n return 0\n\n"
},
{
"id": "python-java-COMMON_CHARACTERS_N_STRINGS",
"pair": "python-java",
"Code1": "def commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n",
"Code2": "public static void commonCharacters ( String str [ ] , int n ) {\n Boolean [ ] prim = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( prim , new Boolean ( true ) ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Boolean [ ] sec = new Boolean [ MAX_CHAR ] ;\n Arrays . fill ( sec , new Boolean ( false ) ) ;\n for ( int j = 0 ;\n j < str [ i ] . length ( ) ;\n j ++ ) {\n if ( prim [ str [ i ] . charAt ( j ) - ' a ' ] ) sec [ str [ i ] . charAt ( j ) - ' a ' ] = true ;\n }\n System . arraycopy ( sec , 0 , prim , 0 , MAX_CHAR ) ;\n }\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) if ( prim [ i ] ) {\n System . out . print ( Character . toChars ( i + 97 ) ) ;\n System . out . print ( \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef commonCharacters ( strings , n ) :\n prim = [ True ] * MAX_CHAR\n for i in range ( n ) :\n sec = [ False ] * MAX_CHAR\n for j in range ( len ( strings [ i ] ) ) :\n if ( prim [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] ) :\n sec [ ord ( strings [ i ] [ j ] ) - ord ( 'a' ) ] = True\n for i in range ( MAX_CHAR ) :\n prim [ i ] = sec [ i ]\n for i in range ( 26 ) :\n if ( prim [ i ] ) :\n print ( \"%c \" % ( i + ord ( 'a' ) ) , end = \"\" )\n\n"
},
{
"id": "python-java-CHECK_WHETHER_SECOND_STRING_CAN_FORMED_FIRST_STRING_USING_COUNT_ARRAY",
"pair": "python-java",
"Code1": "def canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n",
"Code2": "static boolean canMakeStr2 ( String str1 , String str2 ) {\n int [ ] count = new int [ MAX ] ;\n char [ ] str3 = str1 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str3 . length ;\n i ++ ) count [ str3 [ i ] ] ++ ;\n char [ ] str4 = str2 . toCharArray ( ) ;\n for ( int i = 0 ;\n i < str4 . length ;\n i ++ ) {\n if ( count [ str4 [ i ] ] == 0 ) return false ;\n count [ str4 [ i ] ] -- ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef canMakeStr2 ( s1 , s2 ) :\n count = { s1 [ i ] : 0 for i in range ( len ( s1 ) ) }\n for i in range ( len ( s1 ) ) :\n count [ s1 [ i ] ] += 1\n for i in range ( len ( s2 ) ) :\n if count [ s2 [ i ] ] == 0 :\n return False\n count [ s2 [ i ] ] -= 1\n return True\n\n"
},
{
"id": "python-java-MAGIC_SQUARE",
"pair": "python-java",
"Code1": "def generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n",
"Code2": "static void generateSquare ( int n ) {\n int [ ] [ ] magicSquare = new int [ n ] [ n ] ;\n int i = n / 2 ;\n int j = n - 1 ;\n for ( int num = 1 ;\n num <= n * n ;\n ) {\n if ( i == - 1 && j == n ) {\n j = n - 2 ;\n i = 0 ;\n }\n else {\n if ( j == n ) j = 0 ;\n if ( i < 0 ) i = n - 1 ;\n }\n if ( magicSquare [ i ] [ j ] != 0 ) {\n j -= 2 ;\n i ++ ;\n continue ;\n }\n else magicSquare [ i ] [ j ] = num ++ ;\n j ++ ;\n i -- ;\n }\n System . out . println ( \"The Magic Square for \" + n + \":\" ) ;\n System . out . println ( \"Sum of each row or column \" + n * ( n * n + 1 ) / 2 + \":\" ) ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n for ( j = 0 ;\n j < n ;\n j ++ ) System . out . print ( magicSquare [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef generateSquare ( n ) :\n magicSquare = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n i = n / 2\n j = n - 1\n num = 1\n while num <= ( n * n ) :\n if i == - 1 and j == n :\n j = n - 2\n i = 0\n else :\n if j == n :\n j = 0\n if i < 0 :\n i = n - 1\n if magicSquare [ int ( i ) ] [ int ( j ) ] :\n j = j - 2\n i = i + 1\n continue\n else :\n magicSquare [ int ( i ) ] [ int ( j ) ] = num\n num = num + 1\n j = j + 1\n i = i - 1\n print ( \"Magic Squre for n =\" , n )\n print ( \"Sum of each row or column\" , n * ( n * n + 1 ) / 2 , \"\\n\" )\n for i in range ( 0 , n ) :\n for j in range ( 0 , n ) :\n print ( '%2d ' % ( magicSquare [ i ] [ j ] ) , end = '' )\n if j == n - 1 :\n print ( )\n\n"
},
{
"id": "python-java-FIND_NUMBER_TIMES_STRING_OCCURS_GIVEN_STRING",
"pair": "python-java",
"Code1": "def count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n",
"Code2": "static int count ( String a , String b , int m , int n ) {\n if ( ( m == 0 && n == 0 ) || n == 0 ) return 1 ;\n if ( m == 0 ) return 0 ;\n if ( a . charAt ( m - 1 ) == b . charAt ( n - 1 ) ) return count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) ;\n else return count ( a , b , m - 1 , n ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count ( a , b , m , n ) :\n if ( ( m == 0 and n == 0 ) or n == 0 ) :\n return 1\n if ( m == 0 ) :\n return 0\n if ( a [ m - 1 ] == b [ n - 1 ] ) :\n return ( count ( a , b , m - 1 , n - 1 ) + count ( a , b , m - 1 , n ) )\n else :\n return count ( a , b , m - 1 , n )\n\n"
},
{
"id": "python-java-COUNT_ARRAYS_ADJACENT_ELEMENTS_ONE_DIVIDE_ANOTHER",
"pair": "python-java",
"Code1": "def numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n",
"Code2": "static int numofArray ( int n , int m ) {\n int [ ] [ ] dp = new int [ MAX ] [ MAX ] ;\n Vector < Integer > [ ] di = new Vector [ MAX ] ;\n Vector < Integer > [ ] mu = new Vector [ MAX ] ;\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n for ( int j = 0 ;\n j < MAX ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n }\n }\n for ( int i = 0 ;\n i < MAX ;\n i ++ ) {\n di [ i ] = new Vector < > ( ) ;\n mu [ i ] = new Vector < > ( ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 2 * i ;\n j <= m ;\n j += i ) {\n di [ j ] . add ( i ) ;\n mu [ i ] . add ( j ) ;\n }\n di [ i ] . add ( i ) ;\n }\n for ( int i = 1 ;\n i <= m ;\n i ++ ) dp [ 1 ] [ i ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n dp [ i ] [ j ] = 0 ;\n for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n ans += dp [ n ] [ i ] ;\n di [ i ] . clear ( ) ;\n mu [ i ] . clear ( ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numofArray ( n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]\n di = [ [ ] for i in range ( MAX ) ]\n mu = [ [ ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 2 * i , m + 1 , i ) :\n di [ j ].append ( i )\n mu [ i ].append ( j )\n di [ i ].append ( i )\n for i in range ( 1 , m + 1 ) :\n dp [ 1 ] [ i ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n dp [ i ] [ j ] = 0\n for x in di [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n for x in mu [ j ] :\n dp [ i ] [ j ] += dp [ i - 1 ] [ x ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans += dp [ n ] [ i ]\n di [ i ].clear ( )\n mu [ i ].clear ( )\n return ans\n\n"
},
{
"id": "python-java-COUNT_1S_SORTED_BINARY_ARRAY",
"pair": "python-java",
"Code1": "def countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n",
"Code2": "int countOnes ( bool arr [ ] , int low , int high ) {\n if ( high >= low ) {\n int mid = low + ( high - low ) / 2 ;\n if ( ( mid == high || arr [ mid + 1 ] == 0 ) && ( arr [ mid ] == 1 ) ) return mid + 1 ;\n if ( arr [ mid ] == 1 ) return countOnes ( arr , ( mid + 1 ) , high ) ;\n return countOnes ( arr , low , ( mid - 1 ) ) ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOnes ( arr , low , high ) :\n if high >= low :\n mid = low + ( high - low ) / 2\n if ( ( mid == high or arr [ mid + 1 ] == 0 ) and ( arr [ mid ] == 1 ) ) :\n return mid + 1\n if arr [ mid ] == 1 :\n return countOnes ( arr , ( mid + 1 ) , high )\n return countOnes ( arr , low , mid - 1 )\n return 0\n\n"
},
{
"id": "python-java-CEILING_IN_A_SORTED_ARRAY_1",
"pair": "python-java",
"Code1": "def ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n",
"Code2": "static int ceilSearch ( int arr [ ] , int low , int high , int x ) {\n int mid ;\n if ( x <= arr [ low ] ) return low ;\n if ( x > arr [ high ] ) return - 1 ;\n mid = ( low + high ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n else if ( arr [ mid ] < x ) {\n if ( mid + 1 <= high && x <= arr [ mid + 1 ] ) return mid + 1 ;\n else return ceilSearch ( arr , mid + 1 , high , x ) ;\n }\n else {\n if ( mid - 1 >= low && x > arr [ mid - 1 ] ) return mid ;\n else return ceilSearch ( arr , low , mid - 1 , x ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef ceilSearch ( arr , low , high , x ) :\n if x <= arr [ low ] :\n return low\n if x > arr [ high ] :\n return - 1\n mid = ( low + high ) / 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n if mid + 1 <= high and x <= arr [ mid + 1 ] :\n return mid + 1\n else :\n return ceilSearch ( arr , mid + 1 , high , x )\n else :\n if mid - 1 >= low and x > arr [ mid - 1 ] :\n return mid\n else :\n return ceilSearch ( arr , low , mid - 1 , x )\n\n"
},
{
"id": "python-java-DECIMAL_BINARY_CONVERSION_WITHOUT_USING_ARITHMETIC_OPERATORS",
"pair": "python-java",
"Code1": "def decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n",
"Code2": "static String decToBin ( int n ) {\n if ( n == 0 ) return \"0\" ;\n String bin = \"\" ;\n while ( n > 0 ) {\n bin = ( ( n & 1 ) == 0 ? ' 0 ' : ' 1 ' ) + bin ;\n n >>= 1 ;\n }\n return bin ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decToBin ( n ) :\n if ( n == 0 ) :\n return \"0\"\n bin = \"\"\n while ( n > 0 ) :\n if ( n & 1 == 0 ) :\n bin = '0' + bin\n else :\n bin = '1' + bin\n n = n >> 1\n return bin\n\n"
},
{
"id": "python-java-HOW_WILL_YOU_PRINT_NUMBERS_FROM_1_TO_200_WITHOUT_USING_LOOP",
"pair": "python-java",
"Code1": "def printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n",
"Code2": "static void printNos ( int n ) {\n if ( n > 0 ) {\n printNos ( n - 1 ) ;\n System . out . print ( n + \" \" ) ;\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printNos ( n ) :\n if n > 0 :\n printNos ( n - 1 )\n print ( n , end = ' ' )\n\n"
},
{
"id": "python-java-PREFIX_SUM_2D_ARRAY",
"pair": "python-java",
"Code1": "def prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "public static void prefixSum2D ( int a [ ] [ ] ) {\n int R = a . length ;\n int C = a [ 0 ] . length ;\n int psa [ ] [ ] = new int [ R ] [ C ] ;\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ] ;\n for ( int i = 1 ;\n i < C ;\n i ++ ) psa [ 0 ] [ i ] = psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) psa [ i ] [ 0 ] = psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] ;\n for ( int i = 1 ;\n i < R ;\n i ++ ) for ( int j = 1 ;\n j < C ;\n j ++ ) psa [ i ] [ j ] = psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] ;\n for ( int i = 0 ;\n i < R ;\n i ++ ) {\n for ( int j = 0 ;\n j < C ;\n j ++ ) System . out . print ( psa [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef prefixSum2D ( a ) :\n global C , R\n psa = [ [ 0 for x in range ( C ) ] for y in range ( R ) ]\n psa [ 0 ] [ 0 ] = a [ 0 ] [ 0 ]\n for i in range ( 1 , C ) :\n psa [ 0 ] [ i ] = ( psa [ 0 ] [ i - 1 ] + a [ 0 ] [ i ] )\n for i in range ( 0 , R ) :\n psa [ i ] [ 0 ] = ( psa [ i - 1 ] [ 0 ] + a [ i ] [ 0 ] )\n for i in range ( 1 , R ) :\n for j in range ( 1 , C ) :\n psa [ i ] [ j ] = ( psa [ i - 1 ] [ j ] + psa [ i ] [ j - 1 ] - psa [ i - 1 ] [ j - 1 ] + a [ i ] [ j ] )\n for i in range ( 0 , R ) :\n for j in range ( 0 , C ) :\n print ( psa [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-EULERIAN_NUMBER",
"pair": "python-java",
"Code1": "def eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n",
"Code2": "public static int eulerian ( int n , int m ) {\n if ( m >= n || n == 0 ) return 0 ;\n if ( m == 0 ) return 1 ;\n return ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef eulerian ( n , m ) :\n if ( m >= n or n == 0 ) :\n return 0\n if ( m == 0 ) :\n return 1\n return ( ( n - m ) * eulerian ( n - 1 , m - 1 ) + ( m + 1 ) * eulerian ( n - 1 , m ) )\n\n"
},
{
"id": "python-java-FIND_SUM_UNIQUE_SUB_ARRAY_SUM_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n",
"Code2": "static int findSubarraySum ( int [ ] arr , int n ) {\n int res = 0 ;\n HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int sum = 0 ;\n for ( int j = i ;\n j < n ;\n j ++ ) {\n sum += arr [ j ] ;\n if ( m . containsKey ( sum ) ) {\n m . put ( sum , m . get ( sum ) + 1 ) ;\n }\n else {\n m . put ( sum , 1 ) ;\n }\n }\n }\n for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) if ( x . getValue ( ) == 1 ) res += x . getKey ( ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSubarraySum ( arr , n ) :\n res = 0\n m = dict ( )\n for i in range ( n ) :\n Sum = 0\n for j in range ( i , n ) :\n Sum += arr [ j ]\n m [ Sum ] = m.get ( Sum , 0 ) + 1\n for x in m :\n if m [ x ] == 1 :\n res += x\n return res\n\n"
},
{
"id": "python-java-WRITE_AN_EFFICIENT_METHOD_TO_CHECK_IF_A_NUMBER_IS_MULTIPLE_OF_3",
"pair": "python-java",
"Code1": "def isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n",
"Code2": "static int isMultipleOf3 ( int n ) {\n int odd_count = 0 ;\n int even_count = 0 ;\n if ( n < 0 ) n = - n ;\n if ( n == 0 ) return 1 ;\n if ( n == 1 ) return 0 ;\n while ( n != 0 ) {\n if ( ( n & 1 ) != 0 ) odd_count ++ ;\n if ( ( n & 2 ) != 0 ) even_count ++ ;\n n = n >> 2 ;\n }\n return isMultipleOf3 ( Math . abs ( odd_count - even_count ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isMultipleOf3 ( n ) :\n odd_count = 0\n even_count = 0\n if ( n < 0 ) :\n n = - n\n if ( n == 0 ) :\n return 1\n if ( n == 1 ) :\n return 0\n while ( n ) :\n if ( n & 1 ) :\n odd_count += 1\n if ( n & 2 ) :\n even_count += 1\n n = n >> 2\n return isMultipleOf3 ( abs ( odd_count - even_count ) )\n\n"
},
{
"id": "python-java-LCS_FORMED_CONSECUTIVE_SEGMENTS_LEAST_LENGTH_K",
"pair": "python-java",
"Code1": "def longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n",
"Code2": "static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) {\n int n = s1 . length ( ) ;\n int m = s2 . length ( ) ;\n int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= m ;\n j ++ ) {\n lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ;\n if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ;\n if ( cnt [ i ] [ j ] >= k ) {\n for ( int a = k ;\n a <= cnt [ i ] [ j ] ;\n a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ;\n }\n }\n }\n return lcs [ n ] [ m ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestSubsequenceCommonSegment ( k , s1 , s2 ) :\n n = len ( s1 )\n m = len ( s2 )\n lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , m + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] )\n if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) :\n cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1\n if ( cnt [ i ] [ j ] >= k ) :\n for a in range ( k , cnt [ i ] [ j ] + 1 ) :\n lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a )\n return lcs [ n ] [ m ]\n\n"
},
{
"id": "python-java-PROGRAM_AREA_SQUARE",
"pair": "python-java",
"Code1": "def areaSquare ( side ) :\n area = side * side\n return area\n",
"Code2": "static int areaSquare ( int side ) {\n int area = side * side ;\n return area ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef areaSquare ( side ) :\n area = side * side\n return area\n\n"
},
{
"id": "python-java-EULERIAN_PATH_UNDIRECTED_GRAPH",
"pair": "python-java",
"Code1": "def findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n",
"Code2": "static void findpath ( int [ ] [ ] graph , int n ) {\n Vector < Integer > numofadj = new Vector < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) numofadj . add ( accumulate ( graph [ i ] , 0 ) ) ;\n int startPoint = 0 , numofodd = 0 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( numofadj . elementAt ( i ) % 2 == 1 ) {\n numofodd ++ ;\n startPoint = i ;\n }\n }\n if ( numofodd > 2 ) {\n System . out . println ( \"No Solution\" ) ;\n return ;\n }\n Stack < Integer > stack = new Stack < > ( ) ;\n Vector < Integer > path = new Vector < > ( ) ;\n int cur = startPoint ;\n while ( ! stack . isEmpty ( ) || accumulate ( graph [ cur ] , 0 ) != 0 ) {\n if ( accumulate ( graph [ cur ] , 0 ) == 0 ) {\n path . add ( cur ) ;\n cur = stack . pop ( ) ;\n }\n else {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( graph [ cur ] [ i ] == 1 ) {\n stack . add ( cur ) ;\n graph [ cur ] [ i ] = 0 ;\n graph [ i ] [ cur ] = 0 ;\n cur = i ;\n break ;\n }\n }\n }\n }\n for ( int ele : path ) System . out . print ( ele + \" -> \" ) ;\n System . out . println ( cur ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findpath ( graph ) :\n n = len ( graph )\n numofadj = list ( )\n for i in range ( n ) :\n numofadj.append ( sum ( graph [ i ] ) )\n startpoint = 0\n numofodd = 0\n for i in range ( n - 1 , - 1 , - 1 ) :\n if ( numofadj [ i ] % 2 == 1 ) :\n numofodd += 1\n startpoint = i\n if ( numofodd > 2 ) :\n print ( \"No Solution\" )\n return\n stack = list ( )\n path = list ( )\n cur = startpoint\n while ( stack != [ ] or sum ( graph [ cur ] ) != 0 ) :\n if ( sum ( graph [ cur ] ) == 0 ) :\n path.append ( cur + 1 )\n cur = stack.pop ( - 1 )\n else :\n for i in range ( n ) :\n if graph [ cur ] [ i ] == 1 :\n stack.append ( cur )\n graph [ cur ] [ i ] = 0\n graph [ i ] [ cur ] = 0\n cur = i\n break\n for ele in path :\n print ( ele , \"-> \" , end = '' )\n print ( cur + 1 )\n\n"
},
{
"id": "python-java-LCS_LONGEST_COMMON_SUBSEQUENCE_THREE_STRINGS_1",
"pair": "python-java",
"Code1": "def lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n",
"Code2": "static int lcsOf3 ( int i , int j , int k ) {\n if ( i == - 1 || j == - 1 || k == - 1 ) {\n return 0 ;\n }\n if ( dp [ i ] [ j ] [ k ] != - 1 ) {\n return dp [ i ] [ j ] [ k ] ;\n }\n if ( X . charAt ( i ) == Y . charAt ( j ) && Y . charAt ( j ) == Z . charAt ( k ) ) {\n return dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 ) ;\n }\n else {\n return dp [ i ] [ j ] [ k ] = Math . max ( Math . max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lcsOf3 ( i , j , k ) :\n if ( i == - 1 or j == - 1 or k == - 1 ) :\n return 0\n if ( dp [ i ] [ j ] [ k ] != - 1 ) :\n return dp [ i ] [ j ] [ k ]\n if ( X [ i ] == Y [ j ] and Y [ j ] == Z [ k ] ) :\n dp [ i ] [ j ] [ k ] = 1 + lcsOf3 ( i - 1 , j - 1 , k - 1 )\n return dp [ i ] [ j ] [ k ]\n else :\n dp [ i ] [ j ] [ k ] = max ( max ( lcsOf3 ( i - 1 , j , k ) , lcsOf3 ( i , j - 1 , k ) ) , lcsOf3 ( i , j , k - 1 ) )\n return dp [ i ] [ j ] [ k ]\n\n"
},
{
"id": "python-java-FIND_ELEMENTS_LARGER_HALF_ELEMENTS_ARRAY",
"pair": "python-java",
"Code1": "def findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n",
"Code2": "static void findLarger ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i >= n / 2 ;\n i -- ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLarger ( arr , n ) :\n x = sorted ( arr )\n for i in range ( n / 2 , n ) :\n print ( x [ i ] ) ,\n\n"
},
{
"id": "python-java-SUM_DIAGONALS_SPIRAL_ODD_ORDER_SQUARE_MATRIX",
"pair": "python-java",
"Code1": "def spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n",
"Code2": "static int spiralDiaSum ( int n ) {\n if ( n == 1 ) return 1 ;\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef spiralDiaSum ( n ) :\n if n == 1 :\n return 1\n return ( 4 * n * n - 6 * n + 6 + spiralDiaSum ( n - 2 ) )\n\n"
},
{
"id": "python-java-COUNT_NUMBER_OF_OCCURRENCES_OR_FREQUENCY_IN_A_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n",
"Code2": "static int countOccurrences ( int arr [ ] , int n , int x ) {\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( x == arr [ i ] ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOccurrences ( arr , n , x ) :\n res = 0\n for i in range ( n ) :\n if x == arr [ i ] :\n res += 1\n return res\n\n"
},
{
"id": "python-java-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS",
"pair": "python-java",
"Code1": "def sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n",
"Code2": "static int sumBetweenTwoKth ( int arr [ ] , int k1 , int k2 ) {\n Arrays . sort ( arr ) ;\n int result = 0 ;\n for ( int i = k1 ;\n i < k2 - 1 ;\n i ++ ) result += arr [ i ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumBetweenTwoKth ( arr , n , k1 , k2 ) :\n arr.sort ( )\n result = 0\n for i in range ( k1 , k2 - 1 ) :\n result += arr [ i ]\n return result\n\n"
},
{
"id": "python-java-FIND_NUMBER_PAIRS_ARRAY_XOR_0_1",
"pair": "python-java",
"Code1": "def calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n",
"Code2": "static int calculate ( int a [ ] , int n ) {\n int maximum = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int frequency [ ] = new int [ maximum + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n frequency [ a [ i ] ] += 1 ;\n }\n int answer = 0 ;\n for ( int i = 0 ;\n i < ( maximum ) + 1 ;\n i ++ ) {\n answer = answer + frequency [ i ] * ( frequency [ i ] - 1 ) ;\n }\n return answer / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calculate ( a ) :\n maximum = max ( a )\n frequency = [ 0 for x in range ( maximum + 1 ) ]\n for i in a :\n frequency [ i ] += 1\n answer = 0\n for i in frequency :\n answer = answer + i * ( i - 1 ) // 2\n return answer\n\n"
},
{
"id": "python-java-DOUBLE_FACTORIAL_1",
"pair": "python-java",
"Code1": "def doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n",
"Code2": "static int doublefactorial ( int n ) {\n int res = 1 ;\n for ( int i = n ;\n i >= 0 ;\n i = i - 2 ) {\n if ( i == 0 || i == 1 ) return res ;\n else res *= i ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef doublefactorial ( n ) :\n res = 1\n for i in range ( n , - 1 , - 2 ) :\n if ( i == 0 or i == 1 ) :\n return res\n else :\n res *= i\n\n"
},
{
"id": "python-java-LONGEST_COMMON_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n",
"Code2": "int lcs ( char [ ] X , char [ ] Y , int m , int n ) {\n if ( m == 0 || n == 0 ) return 0 ;\n if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lcs ( X , Y , m , n ) :\n if m == 0 or n == 0 :\n return 0 ;\n elif X [ m - 1 ] == Y [ n - 1 ] :\n return 1 + lcs ( X , Y , m - 1 , n - 1 ) ;\n else :\n return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ;\n\n"
},
{
"id": "python-java-MAXIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "python-java",
"Code1": "def maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n",
"Code2": "static int maxProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) {\n return a [ 0 ] ;\n }\n int max_neg = Integer . MIN_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int prod = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n max_neg = Math . max ( max_neg , a [ i ] ) ;\n }\n prod = prod * a [ i ] ;\n }\n if ( count_zero == n ) {\n return 0 ;\n }\n if ( count_neg % 2 == 1 ) {\n if ( count_neg == 1 && count_zero > 0 && count_zero + count_neg == n ) {\n return 0 ;\n }\n prod = prod / max_neg ;\n }\n return prod ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProductSubset ( a , n ) :\n if n == 1 :\n return a [ 0 ]\n max_neg = - 999999999999\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( n ) :\n if a [ i ] == 0 :\n count_zero += 1\n continue\n if a [ i ] < 0 :\n count_neg += 1\n max_neg = max ( max_neg , a [ i ] )\n prod = prod * a [ i ]\n if count_zero == n :\n return 0\n if count_neg & 1 :\n if ( count_neg == 1 and count_zero > 0 and count_zero + count_neg == n ) :\n return 0\n prod = int ( prod / max_neg )\n return prod\n\n"
},
{
"id": "python-java-TEMPLE_OFFERINGS",
"pair": "python-java",
"Code1": "def offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n",
"Code2": "static int offeringNumber ( int n , int templeHeight [ ] ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n int left = 0 , right = 0 ;\n for ( int j = i - 1 ;\n j >= 0 ;\n -- j ) {\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) ++ left ;\n else break ;\n }\n for ( int j = i + 1 ;\n j < n ;\n ++ j ) {\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) ++ right ;\n else break ;\n }\n sum += Math . max ( right , left ) + 1 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef offeringNumber ( n , templeHeight ) :\n sum = 0\n for i in range ( n ) :\n left = 0\n right = 0\n for j in range ( i - 1 , - 1 , - 1 ) :\n if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :\n left += 1\n else :\n break\n for j in range ( i + 1 , n ) :\n if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :\n right += 1\n else :\n break\n sum += max ( right , left ) + 1\n return sum\n\n"
},
{
"id": "python-java-FIND_SUM_NODES_GIVEN_PERFECT_BINARY_TREE",
"pair": "python-java",
"Code1": "def SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n",
"Code2": "static int sumNodes ( int l ) {\n int leafNodeCount = ( int ) Math . pow ( 2 , l - 1 ) ;\n Vector < Vector < Integer >> vec = new Vector < Vector < Integer >> ( ) ;\n for ( int i = 1 ;\n i <= l ;\n i ++ ) vec . add ( new Vector < Integer > ( ) ) ;\n for ( int i = 1 ;\n i <= leafNodeCount ;\n i ++ ) vec . get ( l - 1 ) . add ( i ) ;\n for ( int i = l - 2 ;\n i >= 0 ;\n i -- ) {\n int k = 0 ;\n while ( k < vec . get ( i + 1 ) . size ( ) - 1 ) {\n vec . get ( i ) . add ( vec . get ( i + 1 ) . get ( k ) + vec . get ( i + 1 ) . get ( k + 1 ) ) ;\n k += 2 ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n for ( int j = 0 ;\n j < vec . get ( i ) . size ( ) ;\n j ++ ) sum += vec . get ( i ) . get ( j ) ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef SumNodes ( l ) :\n leafNodeCount = pow ( 2 , l - 1 )\n vec = [ [ ] for i in range ( l ) ]\n for i in range ( 1 , leafNodeCount + 1 ) :\n vec [ l - 1 ].append ( i )\n for i in range ( l - 2 , - 1 , - 1 ) :\n k = 0\n while ( k < len ( vec [ i + 1 ] ) - 1 ) :\n vec [ i ].append ( vec [ i + 1 ] [ k ] + vec [ i + 1 ] [ k + 1 ] )\n k += 2\n Sum = 0\n for i in range ( l ) :\n for j in range ( len ( vec [ i ] ) ) :\n Sum += vec [ i ] [ j ]\n return Sum\n\n"
},
{
"id": "python-java-CONSTRUCT_LEXICOGRAPHICALLY_SMALLEST_PALINDROME",
"pair": "python-java",
"Code1": "def constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n",
"Code2": "static String constructPalin ( char [ ] str , int len ) {\n int i = 0 , j = len - 1 ;\n for ( ;\n i < j ;\n i ++ , j -- ) {\n if ( str [ i ] == str [ j ] && str [ i ] != ' * ' ) continue ;\n else if ( str [ i ] == str [ j ] && str [ i ] == ' * ' ) {\n str [ i ] = ' a ' ;\n str [ j ] = ' a ' ;\n continue ;\n }\n else if ( str [ i ] == ' * ' ) {\n str [ i ] = str [ j ] ;\n continue ;\n }\n else if ( str [ j ] == ' * ' ) {\n str [ j ] = str [ i ] ;\n continue ;\n }\n System . out . println ( \"Not Possible\" ) ;\n return \"\" ;\n }\n return String . valueOf ( str ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef constructPalin ( string , l ) :\n string = list ( string )\n i = - 1\n j = l\n while i < j :\n i += 1\n j -= 1\n if ( string [ i ] == string [ j ] and string [ i ] != '*' ) :\n continue\n elif ( string [ i ] == string [ j ] and string [ i ] == '*' ) :\n string [ i ] = 'a'\n string [ j ] = 'a'\n continue\n elif string [ i ] == '*' :\n string [ i ] = string [ j ]\n continue\n elif string [ j ] == '*' :\n string [ j ] = string [ i ]\n continue\n print ( \"Not Possible\" )\n return \"\"\n return ''.join ( string )\n\n"
},
{
"id": "python-java-COUNT_INDEX_PAIRS_EQUAL_ELEMENTS_ARRAY",
"pair": "python-java",
"Code1": "def countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n ans = 0\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n if ( arr [ i ] == arr [ j ] ) :\n ans += 1\n return ans\n\n"
},
{
"id": "python-java-FAST_MULTIPLICATION_METHOD_WITHOUT_USING_MULTIPLICATION_OPERATOR_RUSSIAN_PEASANTS_ALGORITHM",
"pair": "python-java",
"Code1": "def russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n",
"Code2": "static int russianPeasant ( int a , int b ) {\n int res = 0 ;\n while ( b > 0 ) {\n if ( ( b & 1 ) != 0 ) res = res + a ;\n a = a << 1 ;\n b = b >> 1 ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef russianPeasant ( a , b ) :\n res = 0\n while ( b > 0 ) :\n if ( b & 1 ) :\n res = res + a\n a = a << 1\n b = b >> 1\n return res\n\n"
},
{
"id": "python-java-CAESAR_CIPHER",
"pair": "python-java",
"Code1": "def encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n",
"Code2": "public static StringBuffer encrypt ( String text , int s ) {\n StringBuffer result = new StringBuffer ( ) ;\n for ( int i = 0 ;\n i < text . length ( ) ;\n i ++ ) {\n if ( Character . isUpperCase ( text . charAt ( i ) ) ) {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 65 ) % 26 + 65 ) ;\n result . append ( ch ) ;\n }\n else {\n char ch = ( char ) ( ( ( int ) text . charAt ( i ) + s - 97 ) % 26 + 97 ) ;\n result . append ( ch ) ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef encrypt ( text , s ) :\n result = \"\"\n for i in range ( len ( text ) ) :\n char = text [ i ]\n if ( char.isupper ( ) ) :\n result += chr ( ( ord ( char ) + s - 65 ) % 26 + 65 )\n else :\n result += chr ( ( ord ( char ) + s - 97 ) % 26 + 97 )\n return result\n\n"
},
{
"id": "python-java-PROGRAM_DISTANCE_TWO_POINTS_EARTH",
"pair": "python-java",
"Code1": "def distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n",
"Code2": "public static double distance ( double lat1 , double lat2 , double lon1 , double lon2 ) {\n lon1 = Math . toRadians ( lon1 ) ;\n lon2 = Math . toRadians ( lon2 ) ;\n lat1 = Math . toRadians ( lat1 ) ;\n lat2 = Math . toRadians ( lat2 ) ;\n double dlon = lon2 - lon1 ;\n double dlat = lat2 - lat1 ;\n double a = Math . pow ( Math . sin ( dlat / 2 ) , 2 ) + Math . cos ( lat1 ) * Math . cos ( lat2 ) * Math . pow ( Math . sin ( dlon / 2 ) , 2 ) ;\n double c = 2 * Math . asin ( Math . sqrt ( a ) ) ;\n double r = 6371 ;\n return ( c * r ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef distance ( lat1 , lat2 , lon1 , lon2 ) :\n lon1 = radians ( lon1 )\n lon2 = radians ( lon2 )\n lat1 = radians ( lat1 )\n lat2 = radians ( lat2 )\n dlon = lon2 - lon1\n dlat = lat2 - lat1\n a = sin ( dlat / 2 ) ** 2 + cos ( lat1 ) * cos ( lat2 ) * sin ( dlon / 2 ) ** 2\n c = 2 * asin ( sqrt ( a ) )\n r = 6371\n return ( c * r )\n\n"
},
{
"id": "python-java-NTH_EVEN_FIBONACCI_NUMBER",
"pair": "python-java",
"Code1": "def evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n",
"Code2": "static long evenFib ( int n ) {\n if ( n < 1 ) return n ;\n if ( n == 1 ) return 2 ;\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evenFib ( n ) :\n if ( n < 1 ) :\n return n\n if ( n == 1 ) :\n return 2\n return ( ( 4 * evenFib ( n - 1 ) ) + evenFib ( n - 2 ) )\n\n"
},
{
"id": "python-java-STEINS_ALGORITHM_FOR_FINDING_GCD",
"pair": "python-java",
"Code1": "def gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a",
"Code2": "static int gcd ( int a , int b ) {\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n int k ;\n for ( k = 0 ;\n ( ( a",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n k = 0\n while ( ( ( a\n"
},
{
"id": "python-java-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO",
"pair": "python-java",
"Code1": "def isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n",
"Code2": "static boolean isPowerOfTwo ( int n ) {\n if ( n == 0 ) return false ;\n while ( n != 1 ) {\n if ( n % 2 != 0 ) return false ;\n n = n / 2 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPowerOfTwo ( n ) :\n if ( n == 0 ) :\n return False\n while ( n != 1 ) :\n if ( n % 2 != 0 ) :\n return False\n n = n // 2\n return True\n\n"
},
{
"id": "python-java-SUM_PAIRWISE_PRODUCTS",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n",
"Code2": "static int findSum ( int n ) {\n int sum = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) for ( int j = i ;\n j <= n ;\n j ++ ) sum = sum + i * j ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n sm = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n sm = sm + i * j\n return sm\n\n"
},
{
"id": "python-java-SUM_BINOMIAL_COEFFICIENTS_1",
"pair": "python-java",
"Code1": "def binomialCoeffSum ( n ) :\n return ( 1 << n )\n",
"Code2": "static int binomialCoeffSum ( int n ) {\n return ( 1 << n ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binomialCoeffSum ( n ) :\n return ( 1 << n )\n\n"
},
{
"id": "python-java-EVALUATE_AN_ARRAY_EXPRESSION_WITH_NUMBERS_AND",
"pair": "python-java",
"Code1": "def calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n",
"Code2": "public static int calculateSum ( String arr [ ] , int n ) {\n if ( n == 0 ) return 0 ;\n String s = arr [ 0 ] ;\n int value = Integer . parseInt ( s ) ;\n int sum = value ;\n for ( int i = 2 ;\n i < n ;\n i = i + 2 ) {\n s = arr [ i ] ;\n value = Integer . parseInt ( s ) ;\n char operation = arr [ i - 1 ] . charAt ( 0 ) ;\n if ( operation == ' + ' ) sum += value ;\n else sum -= value ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calculateSum ( arr , n ) :\n if ( n == 0 ) :\n return 0\n s = arr [ 0 ]\n value = int ( s )\n sum = value\n for i in range ( 2 , n , 2 ) :\n s = arr [ i ]\n value = int ( s )\n operation = arr [ i - 1 ] [ 0 ]\n if ( operation == '+' ) :\n sum += value\n else :\n sum -= value\n return sum\n\n"
},
{
"id": "python-java-CHECK_WHETHER_POINT_EXISTS_CIRCLE_SECTOR_NOT",
"pair": "python-java",
"Code1": "def checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n",
"Code2": "static void checkPoint ( int radius , int x , int y , float percent , float startAngle ) {\n float endAngle = 360 / percent + startAngle ;\n double polarradius = Math . sqrt ( x * x + y * y ) ;\n double Angle = Math . atan ( y / x ) ;\n if ( Angle >= startAngle && Angle <= endAngle && polarradius < radius ) System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n else System . out . print ( \"Point\" + \"(\" + x + \",\" + y + \")\" + \" exist in the circle sector\\n\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkPoint ( radius , x , y , percent , startAngle ) :\n endAngle = 360 / percent + startAngle\n polarradius = math.sqrt ( x * x + y * y )\n Angle = math.atan ( y / x )\n if ( Angle >= startAngle and Angle <= endAngle and polarradius < radius ) :\n print ( \"Point (\" , x , \",\" , y , \") \" \"exist in the circle sector\" )\n else :\n print ( \"Point (\" , x , \",\" , y , \") \" \"does not exist in the circle sector\" )\n\n"
},
{
"id": "python-java-PRINTING_ITEMS_01_KNAPSACK",
"pair": "python-java",
"Code1": "def printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n",
"Code2": "static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n int res = K [ n ] [ W ] ;\n System . out . println ( res ) ;\n w = W ;\n for ( i = n ;\n i > 0 && res > 0 ;\n i -- ) {\n if ( res == K [ i - 1 ] [ w ] ) continue ;\n else {\n System . out . print ( wt [ i - 1 ] + \" \" ) ;\n res = res - val [ i - 1 ] ;\n w = w - wt [ i - 1 ] ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printknapSack ( W , wt , val , n ) :\n K = [ [ 0 for w in range ( W + 1 ) ] for i in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n res = K [ n ] [ W ]\n print ( res )\n w = W\n for i in range ( n , 0 , - 1 ) :\n if res <= 0 :\n break\n if res == K [ i - 1 ] [ w ] :\n continue\n else :\n print ( wt [ i - 1 ] )\n res = res - val [ i - 1 ]\n w = w - wt [ i - 1 ]\n\n"
},
{
"id": "python-java-SEQUENCES_GIVEN_LENGTH_EVERY_ELEMENT_EQUAL_TWICE_PREVIOUS_1",
"pair": "python-java",
"Code1": "def getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n",
"Code2": "static int getTotalNumberOfSequences ( int m , int n ) {\n int T [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) {\n for ( int j = 0 ;\n j < n + 1 ;\n j ++ ) {\n if ( i == 0 || j == 0 ) T [ i ] [ j ] = 0 ;\n else if ( i < j ) T [ i ] [ j ] = 0 ;\n else if ( j == 1 ) T [ i ] [ j ] = i ;\n else T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i / 2 ] [ j - 1 ] ;\n }\n }\n return T [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getTotalNumberOfSequences ( m , n ) :\n T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if i == 0 or j == 0 :\n T [ i ] [ j ] = 0\n elif i < j :\n T [ i ] [ j ] = 0\n elif j == 1 :\n T [ i ] [ j ] = i\n else :\n T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]\n return T [ m ] [ n ]\n\n"
},
{
"id": "python-java-SUM_MATRIX_ELEMENT_ABSOLUTE_DIFFERENCE_ROW_COLUMN_NUMBERS",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n",
"Code2": "static int findSum ( int n ) {\n int [ ] [ ] arr = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ i ] [ j ] = Math . abs ( i - j ) ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < n ;\n j ++ ) sum += arr [ i ] [ j ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ]\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = abs ( i - j )\n sum = 0\n for i in range ( n ) :\n for j in range ( n ) :\n sum += arr [ i ] [ j ]\n return sum\n\n"
},
{
"id": "python-java-REPLACE_CHARACTER_C1_C2_C2_C1_STRING_S",
"pair": "python-java",
"Code1": "def replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n",
"Code2": "static String replace ( String s , char c1 , char c2 ) {\n int l = s . length ( ) ;\n char [ ] arr = s . toCharArray ( ) ;\n for ( int i = 0 ;\n i < l ;\n i ++ ) {\n if ( arr [ i ] == c1 ) arr [ i ] = c2 ;\n else if ( arr [ i ] == c2 ) arr [ i ] = c1 ;\n }\n return String . valueOf ( arr ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef replace ( s , c1 , c2 ) :\n l = len ( s )\n for i in range ( l ) :\n if ( s [ i ] == c1 ) :\n s = s [ 0 : i ] + c2 + s [ i + 1 : ]\n elif ( s [ i ] == c2 ) :\n s = s [ 0 : i ] + c1 + s [ i + 1 : ]\n return s\n\n"
},
{
"id": "python-java-DISCRETE_LOGARITHM_FIND_INTEGER_K_AK_CONGRUENT_MODULO_B",
"pair": "python-java",
"Code1": "def discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n",
"Code2": "static int discreteLogarithm ( int a , int b , int m ) {\n int n = ( int ) ( Math . sqrt ( m ) + 1 ) ;\n int an = 1 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) an = ( an * a ) % m ;\n int [ ] value = new int [ m ] ;\n for ( int i = 1 , cur = an ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] == 0 ) value [ cur ] = i ;\n cur = ( cur * an ) % m ;\n }\n for ( int i = 0 , cur = b ;\n i <= n ;\n ++ i ) {\n if ( value [ cur ] > 0 ) {\n int ans = value [ cur ] * n - i ;\n if ( ans < m ) return ans ;\n }\n cur = ( cur * a ) % m ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef discreteLogarithm ( a , b , m ) :\n n = int ( math.sqrt ( m ) + 1 )\n an = 1\n for i in range ( n ) :\n an = ( an * a ) % m\n value = [ 0 ] * m\n cur = an\n for i in range ( 1 , n + 1 ) :\n if ( value [ cur ] == 0 ) :\n value [ cur ] = i\n cur = ( cur * an ) % m\n cur = b\n for i in range ( n + 1 ) :\n if ( value [ cur ] > 0 ) :\n ans = value [ cur ] * n - i\n if ( ans < m ) :\n return ans\n cur = ( cur * a ) % m\n return - 1\n\n"
},
{
"id": "python-java-FIND_LARGEST_PRIME_FACTOR_NUMBER",
"pair": "python-java",
"Code1": "def maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n",
"Code2": "static long maxPrimeFactors ( long n ) {\n long maxPrime = - 1 ;\n while ( n % 2 == 0 ) {\n maxPrime = 2 ;\n n >>= 1 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n while ( n % i == 0 ) {\n maxPrime = i ;\n n = n / i ;\n }\n }\n if ( n > 2 ) maxPrime = n ;\n return maxPrime ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxPrimeFactors ( n ) :\n maxPrime = - 1\n while n % 2 == 0 :\n maxPrime = 2\n n >>= 1\n for i in range ( 3 , int ( math.sqrt ( n ) ) + 1 , 2 ) :\n while n % i == 0 :\n maxPrime = i\n n = n / i\n if n > 2 :\n maxPrime = n\n return int ( maxPrime )\n\n"
},
{
"id": "python-java-POSSIBLE_FORM_TRIANGLE_ARRAY_VALUES",
"pair": "python-java",
"Code1": "def isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n",
"Code2": "static boolean isPossibleTriangle ( int [ ] arr , int N ) {\n if ( N < 3 ) return false ;\n Arrays . sort ( arr ) ;\n for ( int i = 0 ;\n i < N - 2 ;\n i ++ ) if ( arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPossibleTriangle ( arr , N ) :\n if N < 3 :\n return False\n arr.sort ( )\n for i in range ( N - 2 ) :\n if arr [ i ] + arr [ i + 1 ] > arr [ i + 2 ] :\n return True\n\n"
},
{
"id": "python-java-COUNT_NUMBER_INCREASING_SUBSEQUENCES_SIZE_K",
"pair": "python-java",
"Code1": "def numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n",
"Code2": "static int numOfIncSubseqOfSizeK ( int arr [ ] , int n , int k ) {\n int dp [ ] [ ] = new int [ k ] [ n ] , sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ 0 ] [ i ] = 1 ;\n }\n for ( int l = 1 ;\n l < k ;\n l ++ ) {\n for ( int i = l ;\n i < n ;\n i ++ ) {\n dp [ l ] [ i ] = 0 ;\n for ( int j = l - 1 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] < arr [ i ] ) {\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ] ;\n }\n }\n }\n }\n for ( int i = k - 1 ;\n i < n ;\n i ++ ) {\n sum += dp [ k - 1 ] [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numOfIncSubseqOfSizeK ( arr , n , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( k ) ]\n for i in range ( n ) :\n dp [ 0 ] [ i ] = 1\n for l in range ( 1 , k ) :\n for i in range ( l , n ) :\n dp [ l ] [ i ] = 0\n for j in range ( l - 1 , i ) :\n if ( arr [ j ] < arr [ i ] ) :\n dp [ l ] [ i ] += dp [ l - 1 ] [ j ]\n Sum = 0\n for i in range ( k - 1 , n ) :\n Sum += dp [ k - 1 ] [ i ]\n return Sum\n\n"
},
{
"id": "python-java-MINIMUM_COST_MAKE_LONGEST_COMMON_SUBSEQUENCE_LENGTH_K",
"pair": "python-java",
"Code1": "def solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n",
"Code2": "static int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) {\n if ( k == 0 ) {\n return 0 ;\n }\n if ( l < 0",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solve ( X , Y , l , r , k , dp ) :\n if k == 0 :\n return 0\n if l < 0 or r < 0 :\n return 1000000000\n if dp [ l ] [ r ] [ k ] != - 1 :\n return dp [ l ] [ r ] [ k ]\n cost = ( ( ord ( X [ l ] ) - ord ( 'a' ) ) ^ ( ord ( Y [ r ] ) - ord ( 'a' ) ) )\n dp [ l ] [ r ] [ k ] = min ( [ cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) , solve ( X , Y , l , r - 1 , k , dp ) ] )\n return dp [ l ] [ r ] [ k ]\n\n"
},
{
"id": "python-java-REMAINDER_7_LARGE_NUMBERS",
"pair": "python-java",
"Code1": "def remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n",
"Code2": "static int remainderWith7 ( String num ) {\n int series [ ] = {\n 1 , 3 , 2 , - 1 , - 3 , - 2 }\n ;\n int series_index = 0 ;\n int result = 0 ;\n for ( int i = num . length ( ) - 1 ;\n i >= 0 ;\n i -- ) {\n int digit = num . charAt ( i ) - ' 0 ' ;\n result += digit * series [ series_index ] ;\n series_index = ( series_index + 1 ) % 6 ;\n result %= 7 ;\n }\n if ( result < 0 ) result = ( result + 7 ) % 7 ;\n return result ;\n }\n ",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef remainderWith7 ( num ) :\n series = [ 1 , 3 , 2 , - 1 , - 3 , - 2 ]\n series_index = 0\n result = 0\n for i in range ( ( len ( num ) - 1 ) , - 1 , - 1 ) :\n digit = ord ( num [ i ] ) - 48\n result += digit * series [ series_index ]\n series_index = ( series_index + 1 ) % 6\n result %= 7\n if ( result < 0 ) :\n result = ( result + 7 ) % 7\n return result\n\n"
},
{
"id": "python-java-GIVEN_TWO_STRINGS_FIND_FIRST_STRING_SUBSEQUENCE_SECOND",
"pair": "python-java",
"Code1": "def isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n",
"Code2": "static boolean isSubSequence ( String str1 , String str2 , int m , int n ) {\n if ( m == 0 ) return true ;\n if ( n == 0 ) return false ;\n if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) return isSubSequence ( str1 , str2 , m - 1 , n - 1 ) ;\n return isSubSequence ( str1 , str2 , m , n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubSequence ( string1 , string2 , m , n ) :\n if m == 0 : return True\n if n == 0 : return False\n if string1 [ m - 1 ] == string2 [ n - 1 ] :\n return isSubSequence ( string1 , string2 , m - 1 , n - 1 )\n return isSubSequence ( string1 , string2 , m , n - 1 )\n\n"
},
{
"id": "python-java-PROGRAM_TO_FIND_REMAINDER_WITHOUT_USING_MODULO_OR_OPERATOR",
"pair": "python-java",
"Code1": "def getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n",
"Code2": "static int getRemainder ( int num , int divisor ) {\n return ( num - divisor * ( num / divisor ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getRemainder ( num , divisor ) :\n return ( num - divisor * ( num // divisor ) )\n\n"
},
{
"id": "python-java-MINIMUM_PRODUCT_SUBSET_ARRAY",
"pair": "python-java",
"Code1": "def minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n",
"Code2": "static int minProductSubset ( int a [ ] , int n ) {\n if ( n == 1 ) return a [ 0 ] ;\n int negmax = Integer . MIN_VALUE ;\n int posmin = Integer . MAX_VALUE ;\n int count_neg = 0 , count_zero = 0 ;\n int product = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] == 0 ) {\n count_zero ++ ;\n continue ;\n }\n if ( a [ i ] < 0 ) {\n count_neg ++ ;\n negmax = Math . max ( negmax , a [ i ] ) ;\n }\n if ( a [ i ] > 0 && a [ i ] < posmin ) posmin = a [ i ] ;\n product *= a [ i ] ;\n }\n if ( count_zero == n || ( count_neg == 0 && count_zero > 0 ) ) return 0 ;\n if ( count_neg == 0 ) return posmin ;\n if ( count_neg % 2 == 0 && count_neg != 0 ) {\n product = product / negmax ;\n }\n return product ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minProductSubset ( a , n ) :\n if ( n == 1 ) :\n return a [ 0 ]\n max_neg = float ( '-inf' )\n min_pos = float ( 'inf' )\n count_neg = 0\n count_zero = 0\n prod = 1\n for i in range ( 0 , n ) :\n if ( a [ i ] == 0 ) :\n count_zero = count_zero + 1\n continue\n if ( a [ i ] < 0 ) :\n count_neg = count_neg + 1\n max_neg = max ( max_neg , a [ i ] )\n if ( a [ i ] > 0 ) :\n min_pos = min ( min_pos , a [ i ] )\n prod = prod * a [ i ]\n if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :\n return 0\n if ( count_neg == 0 ) :\n return min_pos\n if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :\n prod = int ( prod / max_neg )\n return prod\n\n"
},
{
"id": "python-java-HOW_CAN_WE_SUM_THE_DIGITS_OF_A_GIVEN_NUMBER_IN_SINGLE_STATEMENT",
"pair": "python-java",
"Code1": "def getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n",
"Code2": "static int getSum ( int n ) {\n int sum = 0 ;\n while ( n != 0 ) {\n sum = sum + n % 10 ;\n n = n / 10 ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getSum ( n ) :\n sum = 0\n while ( n != 0 ) :\n sum = sum + int ( n % 10 )\n n = int ( n / 10 )\n return sum\n\n"
},
{
"id": "python-java-COUNT_DIGITS_FACTORIAL_SET_1",
"pair": "python-java",
"Code1": "def findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n",
"Code2": "static int findDigits ( int n ) {\n if ( n < 0 ) return 0 ;\n if ( n <= 1 ) return 1 ;\n double digits = 0 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) digits += Math . log10 ( i ) ;\n return ( int ) ( Math . floor ( digits ) ) + 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDigits ( n ) :\n if ( n < 0 ) :\n return 0\n if ( n <= 1 ) :\n return 1\n digits = 0\n for i in range ( 2 , n + 1 ) :\n digits += math.log10 ( i )\n return math.floor ( digits ) + 1\n\n"
},
{
"id": "python-java-SORT_ARRAY_TWO_HALVES_SORTED",
"pair": "python-java",
"Code1": "def mergeTwoHalf ( A , n ) :\n A.sort ( )\n",
"Code2": "static void mergeTwoHalf ( int [ ] A , int n ) {\n Arrays . sort ( A ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef mergeTwoHalf ( A , n ) :\n A.sort ( )\n\n"
},
{
"id": "python-java-CREATE_A_MATRIX_WITH_ALTERNATING_RECTANGLES_OF_0_AND_X",
"pair": "python-java",
"Code1": "def fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "static void fill0X ( int m , int n ) {\n int i , k = 0 , l = 0 ;\n int r = m , c = n ;\n char a [ ] [ ] = new char [ m ] [ n ] ;\n char x = ' X ' ;\n while ( k < m && l < n ) {\n for ( i = l ;\n i < n ;\n ++ i ) a [ k ] [ i ] = x ;\n k ++ ;\n for ( i = k ;\n i < m ;\n ++ i ) a [ i ] [ n - 1 ] = x ;\n n -- ;\n if ( k < m ) {\n for ( i = n - 1 ;\n i >= l ;\n -- i ) a [ m - 1 ] [ i ] = x ;\n m -- ;\n }\n if ( l < n ) {\n for ( i = m - 1 ;\n i >= k ;\n -- i ) a [ i ] [ l ] = x ;\n l ++ ;\n }\n x = ( x == ' 0 ' ) ? ' X ' : ' 0 ' ;\n }\n for ( i = 0 ;\n i < r ;\n i ++ ) {\n for ( int j = 0 ;\n j < c ;\n j ++ ) System . out . print ( a [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fill0X ( m , n ) :\n i , k , l = 0 , 0 , 0\n r = m\n c = n\n a = [ [ None ] * n for i in range ( m ) ]\n x = 'X'\n while k < m and l < n :\n for i in range ( l , n ) :\n a [ k ] [ i ] = x\n k += 1\n for i in range ( k , m ) :\n a [ i ] [ n - 1 ] = x\n n -= 1\n if k < m :\n for i in range ( n - 1 , l - 1 , - 1 ) :\n a [ m - 1 ] [ i ] = x\n m -= 1\n if l < n :\n for i in range ( m - 1 , k - 1 , - 1 ) :\n a [ i ] [ l ] = x\n l += 1\n x = 'X' if x == '0' else '0'\n for i in range ( r ) :\n for j in range ( c ) :\n print ( a [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-MINIMUM_PERIMETER_N_BLOCKS",
"pair": "python-java",
"Code1": "def minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n",
"Code2": "public static long minPerimeter ( int n ) {\n int l = ( int ) Math . sqrt ( n ) ;\n int sq = l * l ;\n if ( sq == n ) return l * 4 ;\n else {\n long row = n / l ;\n long perimeter = 2 * ( l + row ) ;\n if ( n % l != 0 ) perimeter += 2 ;\n return perimeter ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minPerimeter ( n ) :\n l = math.sqrt ( n )\n sq = l * l\n if ( sq == n ) :\n return l * 4\n else :\n row = n / l\n perimeter = 2 * ( l + row )\n if ( n % l != 0 ) :\n perimeter += 2\n return perimeter\n\n"
},
{
"id": "python-java-FIND_POSSIBLE_ROTATE_PAGE_ANGLE_NOT",
"pair": "python-java",
"Code1": "def possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n",
"Code2": "static void possibleOrNot ( long a1 , long a2 , long b1 , long b2 , long c1 , long c2 ) {\n long dis1 = ( long ) Math . pow ( b1 - a1 , 2 ) + ( long ) Math . pow ( b2 - a2 , 2 ) ;\n long dis2 = ( long ) Math . pow ( c1 - b1 , 2 ) + ( long ) Math . pow ( c2 - b2 , 2 ) ;\n if ( dis1 != dis2 ) System . out . print ( \"No\" ) ;\n else if ( b1 == ( ( a1 + c1 ) / 2.0 ) && b2 == ( ( a2 + c2 ) / 2.0 ) ) System . out . print ( \"No\" ) ;\n else System . out . print ( \"Yes\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef possibleOrNot ( a1 , a2 , b1 , b2 , c1 , c2 ) :\n dis1 = ( pow ( b1 - a1 , 2 ) + pow ( b2 - a2 , 2 ) )\n dis2 = ( pow ( c1 - b1 , 2 ) + pow ( c2 - b2 , 2 ) )\n if ( dis1 != dis2 ) :\n print ( \"No\" )\n elif ( b1 == ( ( a1 + c1 ) // 2.0 ) and b2 == ( ( a2 + c2 ) // 2.0 ) ) :\n print ( \"No\" )\n else :\n print ( \"Yes\" )\n\n"
},
{
"id": "python-java-PROGRAM_FIND_SLOPE_LINE",
"pair": "python-java",
"Code1": "def slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n",
"Code2": "static float slope ( float x1 , float y1 , float x2 , float y2 ) {\n return ( y2 - y1 ) / ( x2 - x1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef slope ( x1 , y1 , x2 , y2 ) :\n return ( float ) ( y2 - y1 ) / ( x2 - x1 )\n\n"
},
{
"id": "python-java-FIND_NUMBER_PERFECT_SQUARES_TWO_GIVEN_NUMBERS_1",
"pair": "python-java",
"Code1": "def CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n",
"Code2": "double countSquares ( int a , int b ) {\n return ( Math . floor ( Math . sqrt ( b ) ) - Math . ceil ( Math . sqrt ( a ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountSquares ( a , b ) :\n return ( math.floor ( math.sqrt ( b ) ) - math.ceil ( math.sqrt ( a ) ) + 1 )\n\n"
},
{
"id": "python-java-COUNT_BINARY_STRINGS_K_TIMES_APPEARING_ADJACENT_TWO_SET_BITS",
"pair": "python-java",
"Code1": "def countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n",
"Code2": "static int countStrings ( int n , int k ) {\n int dp [ ] [ ] [ ] = new int [ n + 1 ] [ k + 1 ] [ 2 ] ;\n dp [ 1 ] [ 0 ] [ 0 ] = 1 ;\n dp [ 1 ] [ 0 ] [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i && j < k + 1 ;\n j ++ ) {\n dp [ i ] [ j ] [ 0 ] = dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] ;\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ] ;\n if ( j - 1 >= 0 ) {\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ] ;\n }\n }\n }\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countStrings ( n , k ) :\n dp = [ [ [ 0 , 0 ] for __ in range ( k + 1 ) ] for _ in range ( n + 1 ) ]\n dp [ 1 ] [ 0 ] [ 0 ] = 1\n dp [ 1 ] [ 0 ] [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n for j in range ( k + 1 ) :\n dp [ i ] [ j ] [ 0 ] = ( dp [ i - 1 ] [ j ] [ 0 ] + dp [ i - 1 ] [ j ] [ 1 ] )\n dp [ i ] [ j ] [ 1 ] = dp [ i - 1 ] [ j ] [ 0 ]\n if j >= 1 :\n dp [ i ] [ j ] [ 1 ] += dp [ i - 1 ] [ j - 1 ] [ 1 ]\n return dp [ n ] [ k ] [ 0 ] + dp [ n ] [ k ] [ 1 ]\n\n"
},
{
"id": "python-java-FIND_SMALLEST_RANGE_CONTAINING_ELEMENTS_FROM_K_LISTS",
"pair": "python-java",
"Code1": "def findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n",
"Code2": "static void findSmallestRange ( int arr [ ] [ ] , int n , int k ) {\n int i , minval , maxval , minrange , minel = 0 , maxel = 0 , flag , minind ;\n for ( i = 0 ;\n i <= k ;\n i ++ ) {\n ptr [ i ] = 0 ;\n }\n minrange = Integer . MAX_VALUE ;\n while ( true ) {\n minind = - 1 ;\n minval = Integer . MAX_VALUE ;\n maxval = Integer . MIN_VALUE ;\n flag = 0 ;\n for ( i = 0 ;\n i < k ;\n i ++ ) {\n if ( ptr [ i ] == n ) {\n flag = 1 ;\n break ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] < minval ) {\n minind = i ;\n minval = arr [ i ] [ ptr [ i ] ] ;\n }\n if ( ptr [ i ] < n && arr [ i ] [ ptr [ i ] ] > maxval ) {\n maxval = arr [ i ] [ ptr [ i ] ] ;\n }\n }\n if ( flag == 1 ) {\n break ;\n }\n ptr [ minind ] ++ ;\n if ( ( maxval - minval ) < minrange ) {\n minel = minval ;\n maxel = maxval ;\n minrange = maxel - minel ;\n }\n }\n System . out . printf ( \"The smallest range is [%d , %d]\\n\" , minel , maxel ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSmallestRange ( arr , n , k ) :\n i , minval , maxval , minrange , minel , maxel , flag , minind = 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0\n for i in range ( k + 1 ) :\n ptr [ i ] = 0\n minrange = 10 ** 9\n while ( 1 ) :\n minind = - 1\n minval = 10 ** 9\n maxval = - 10 ** 9\n flag = 0\n for i in range ( k ) :\n if ( ptr [ i ] == n ) :\n flag = 1\n break\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] < minval ) :\n minind = i\n minval = arr [ i ] [ ptr [ i ] ]\n if ( ptr [ i ] < n and arr [ i ] [ ptr [ i ] ] > maxval ) :\n maxval = arr [ i ] [ ptr [ i ] ]\n if ( flag ) :\n break\n ptr [ minind ] += 1\n if ( ( maxval - minval ) < minrange ) :\n minel = minval\n maxel = maxval\n minrange = maxel - minel\n print ( \"The smallest range is [\" , minel , maxel , \"]\" )\n\n"
},
{
"id": "python-java-LEXICOGRAPHICAL_CONCATENATION_SUBSTRINGS_STRING",
"pair": "python-java",
"Code1": "def lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n",
"Code2": "static String lexicographicSubConcat ( String s ) {\n int n = s . length ( ) ;\n int sub_count = n * ( n + 1 ) / 2 ;\n String [ ] arr = new String [ sub_count ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int len = 1 ;\n len <= n - i ;\n len ++ ) {\n arr [ index ++ ] = s . substring ( i , i + len ) ;\n }\n Arrays . sort ( arr ) ;\n String res = \"\" ;\n for ( int i = 0 ;\n i < sub_count ;\n i ++ ) res += arr [ i ] ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lexicographicSubConcat ( s ) :\n n = len ( s )\n sub_count = ( n * ( n + 1 ) ) // 2\n arr = [ 0 ] * sub_count\n index = 0\n for i in range ( n ) :\n for j in range ( 1 , n - i + 1 ) :\n arr [ index ] = s [ i : i + j ]\n index += 1\n arr.sort ( )\n res = \"\"\n for i in range ( sub_count ) :\n res += arr [ i ]\n return res\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_ELEMENT_ROW_MATRIX",
"pair": "python-java",
"Code1": "def maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n",
"Code2": "public static void maxelement ( int no_of_rows , int [ ] [ ] arr ) {\n int i = 0 ;\n int max = 0 ;\n int [ ] result = new int [ no_of_rows ] ;\n while ( i < no_of_rows ) {\n for ( int j = 0 ;\n j < arr [ i ] . length ;\n j ++ ) {\n if ( arr [ i ] [ j ] > max ) {\n max = arr [ i ] [ j ] ;\n }\n }\n result [ i ] = max ;\n max = 0 ;\n i ++ ;\n }\n printArray ( result ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxelement ( arr ) :\n no_of_rows = len ( arr )\n no_of_column = len ( arr [ 0 ] )\n for i in range ( no_of_rows ) :\n max1 = 0\n for j in range ( no_of_column ) :\n if arr [ i ] [ j ] > max1 :\n max1 = arr [ i ] [ j ]\n print ( max1 )\n\n"
},
{
"id": "python-java-COUNT_NEGATIVE_NUMBERS_IN_A_COLUMN_WISE_ROW_WISE_SORTED_MATRIX_1",
"pair": "python-java",
"Code1": "def countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n",
"Code2": "static int countNegative ( int M [ ] [ ] , int n , int m ) {\n int count = 0 ;\n int i = 0 ;\n int j = m - 1 ;\n while ( j >= 0 && i < n ) {\n if ( M [ i ] [ j ] < 0 ) {\n count += j + 1 ;\n i += 1 ;\n }\n else j -= 1 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNegative ( M , n , m ) :\n count = 0\n i = 0\n j = m - 1\n while j >= 0 and i < n :\n if M [ i ] [ j ] < 0 :\n count += ( j + 1 )\n i += 1\n else :\n j -= 1\n return count\n\n"
},
{
"id": "python-java-FIND_POSITION_GIVEN_NUMBER_AMONG_NUMBERS_MADE_4_7",
"pair": "python-java",
"Code1": "def findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n",
"Code2": "static int findpos ( String n ) {\n int k = 0 , pos = 0 , i = 0 ;\n while ( k != n . length ( ) ) {\n switch ( n . charAt ( i ) ) {\n case ' 4 ' : pos = pos * 2 + 1 ;\n break ;\n case ' 7 ' : pos = pos * 2 + 2 ;\n break ;\n }\n i ++ ;\n k ++ ;\n }\n return pos ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findpos ( n ) :\n i = 0\n j = len ( n )\n pos = 0\n while ( i < j ) :\n if ( n [ i ] == '4' ) :\n pos = pos * 2 + 1\n if ( n [ i ] == '7' ) :\n pos = pos * 2 + 2\n i = i + 1\n return pos\n\n"
},
{
"id": "python-java-FIND_VALUE_OF_Y_MOD_2_RAISED_TO_POWER_X",
"pair": "python-java",
"Code1": "def yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n",
"Code2": "static long yMod ( long y , long x ) {\n if ( ( Math . log ( y ) / Math . log ( 2 ) ) < x ) return y ;\n if ( x > 63 ) return y ;\n return ( y % ( 1 << ( int ) x ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef yMod ( y , x ) :\n return ( y % pow ( 2 , x ) )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_14_MAXIMUM_SUM_INCREASING_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n",
"Code2": "static int maxSumIS ( int arr [ ] , int n ) {\n int i , j , max = 0 ;\n int msis [ ] = new int [ n ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) msis [ i ] = arr [ i ] ;\n for ( i = 1 ;\n i < n ;\n i ++ ) for ( j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ;\n for ( i = 0 ;\n i < n ;\n i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumIS ( arr , n ) :\n max = 0\n msis = [ 0 for x in range ( n ) ]\n for i in range ( n ) :\n msis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and msis [ i ] < msis [ j ] + arr [ i ] ) :\n msis [ i ] = msis [ j ] + arr [ i ]\n for i in range ( n ) :\n if max < msis [ i ] :\n max = msis [ i ]\n return max\n\n"
},
{
"id": "python-java-LENGTH_LONGEST_BALANCED_SUBSEQUENCE_1",
"pair": "python-java",
"Code1": "def maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n",
"Code2": "static int maxLength ( String s , int n ) {\n int invalidOpenBraces = 0 ;\n int invalidCloseBraces = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' ( ' ) {\n invalidOpenBraces ++ ;\n }\n else {\n if ( invalidOpenBraces == 0 ) {\n invalidCloseBraces ++ ;\n }\n else {\n invalidOpenBraces -- ;\n }\n }\n }\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxLength ( s , n ) :\n invalidOpenBraces = 0\n invalidCloseBraces = 0\n for i in range ( n ) :\n if ( s [ i ] == '(' ) :\n invalidOpenBraces += 1\n else :\n if ( invalidOpenBraces == 0 ) :\n invalidCloseBraces += 1\n else :\n invalidOpenBraces -= 1\n return ( n - ( invalidOpenBraces + invalidCloseBraces ) )\n\n"
},
{
"id": "python-java-MAXIMUM_PRODUCT_INCREASING_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n",
"Code2": "static int lis ( int [ ] arr , int n ) {\n int [ ] mpis = new int [ n ] ;\n int max = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) mpis [ i ] = arr [ i ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) mpis [ i ] = mpis [ j ] * arr [ i ] ;\n for ( int k = 0 ;\n k < mpis . length ;\n k ++ ) {\n if ( mpis [ k ] > max ) {\n max = mpis [ k ] ;\n }\n }\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lis ( arr , n ) :\n mpis = [ 0 ] * ( n )\n for i in range ( n ) :\n mpis [ i ] = arr [ i ]\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and mpis [ i ] < ( mpis [ j ] * arr [ i ] ) ) :\n mpis [ i ] = mpis [ j ] * arr [ i ]\n return max ( mpis )\n\n"
},
{
"id": "python-java-PETERSON_GRAPH",
"pair": "python-java",
"Code1": "def findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n",
"Code2": "static boolean findthepath ( char [ ] S , int v ) {\n result [ 0 ] = ( char ) ( v + ' 0 ' ) ;\n for ( int i = 1 ;\n i < ( int ) S . length ;\n i ++ ) {\n if ( adj [ v ] [ S [ i ] - ' A ' ] || adj [ S [ i ] - ' A ' ] [ v ] ) {\n v = S [ i ] - ' A ' ;\n }\n else if ( adj [ v ] [ S [ i ] - ' A ' + 5 ] || adj [ S [ i ] - ' A ' + 5 ] [ v ] ) {\n v = S [ i ] - ' A ' + 5 ;\n }\n else return false ;\n result [ i ] = ( char ) ( v + ' 0 ' ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findthepath ( S , v ) :\n result [ 0 ] = v\n for i in range ( 1 , len ( S ) ) :\n if ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' )\n elif ( adj [ v ] [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] or adj [ ord ( S [ i ] ) - ord ( 'A' ) + 5 ] [ v ] ) :\n v = ord ( S [ i ] ) - ord ( 'A' ) + 5\n else :\n return False\n result.append ( v )\n return True\n\n"
},
{
"id": "python-java-CHECK_QUEUE_CAN_SORTED_ANOTHER_QUEUE_USING_STACK",
"pair": "python-java",
"Code1": "def checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n",
"Code2": "static boolean checkSorted ( int n ) {\n Stack < Integer > st = new Stack < Integer > ( ) ;\n int expected = 1 ;\n int fnt ;\n while ( q . size ( ) != 0 ) {\n fnt = q . peek ( ) ;\n q . poll ( ) ;\n if ( fnt == expected ) expected ++ ;\n else {\n if ( st . size ( ) == 0 ) {\n st . push ( fnt ) ;\n }\n else if ( st . size ( ) != 0 && st . peek ( ) < fnt ) {\n return false ;\n }\n else st . push ( fnt ) ;\n }\n while ( st . size ( ) != 0 && st . peek ( ) == expected ) {\n st . pop ( ) ;\n expected ++ ;\n }\n }\n if ( expected - 1 == n && st . size ( ) == 0 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkSorted ( n , q ) :\n st = [ ]\n expected = 1\n fnt = None\n while ( not q.empty ( ) ) :\n fnt = q.queue [ 0 ]\n q.get ( )\n if ( fnt == expected ) :\n expected += 1\n else :\n if ( len ( st ) == 0 ) :\n st.append ( fnt )\n elif ( len ( st ) != 0 and st [ - 1 ] < fnt ) :\n return False\n else :\n st.append ( fnt )\n while ( len ( st ) != 0 and st [ - 1 ] == expected ) :\n st.pop ( )\n expected += 1\n if ( expected - 1 == n and len ( st ) == 0 ) :\n return True\n return False\n\n"
},
{
"id": "python-java-GENERATING_DISTINCT_SUBSEQUENCES_OF_A_GIVEN_STRING_IN_LEXICOGRAPHIC_ORDER",
"pair": "python-java",
"Code1": "def generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n",
"Code2": "static void generate ( Set < String > st , String s ) {\n if ( s . length ( ) == 0 ) {\n return ;\n }\n if ( ! st . contains ( s ) ) {\n st . add ( s ) ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) {\n String t = s ;\n t = t . substring ( 0 , i ) + t . substring ( i + 1 ) ;\n generate ( st , t ) ;\n }\n }\n return ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef generate ( st , s ) :\n if len ( s ) == 0 :\n return\n if s not in st :\n st.add ( s )\n for i in range ( len ( s ) ) :\n t = list ( s ).copy ( )\n t.remove ( s [ i ] )\n t = ''.join ( t )\n generate ( st , t )\n return\n\n"
},
{
"id": "python-java-RECURSIVE_FUNCTIONS",
"pair": "python-java",
"Code1": "def tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n",
"Code2": "static void tower ( int n , char sourcePole , char destinationPole , char auxiliaryPole ) {\n if ( 0 == n ) return ;\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole ) ;\n System . out . printf ( \"Move the disk %d from %c to %c\\n\" , n , sourcePole , destinationPole ) ;\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef tower ( n , sourcePole , destinationPole , auxiliaryPole ) :\n if ( 0 == n ) :\n return\n tower ( n - 1 , sourcePole , auxiliaryPole , destinationPole )\n print ( \"Move the disk\" , sourcePole , \"from\" , sourcePole , \"to\" , destinationPole )\n tower ( n - 1 , auxiliaryPole , destinationPole , sourcePole )\n\n"
},
{
"id": "python-java-PIZZA_CUT_PROBLEM_CIRCLE_DIVISION_LINES",
"pair": "python-java",
"Code1": "def findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n",
"Code2": "static int findMaximumPieces ( int n ) {\n return 1 + n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaximumPieces ( n ) :\n return int ( 1 + n * ( n + 1 ) / 2 )\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_MINIMUM_STRING_ROTATION",
"pair": "python-java",
"Code1": "def minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n",
"Code2": "static String minLexRotation ( String str ) {\n int n = str . length ( ) ;\n String arr [ ] = new String [ n ] ;\n String concat = str + str ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = concat . substring ( i , i + n ) ;\n }\n Arrays . sort ( arr ) ;\n return arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minLexRotation ( str_ ) :\n n = len ( str_ )\n arr = [ 0 ] * n\n concat = str_ + str_\n for i in range ( n ) :\n arr [ i ] = concat [ i : n + i ]\n arr.sort ( )\n return arr [ 0 ]\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_28_MINIMUM_INSERTIONS_TO_FORM_A_PALINDROME",
"pair": "python-java",
"Code1": "def findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n",
"Code2": "static int findMinInsertions ( char str [ ] , int l , int h ) {\n if ( l > h ) return Integer . MAX_VALUE ;\n if ( l == h ) return 0 ;\n if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ;\n return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinInsertions ( str , l , h ) :\n if ( l > h ) :\n return sys.maxsize\n if ( l == h ) :\n return 0\n if ( l == h - 1 ) :\n return 0 if ( str [ l ] == str [ h ] ) else 1\n if ( str [ l ] == str [ h ] ) :\n return findMinInsertions ( str , l + 1 , h - 1 )\n else :\n return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )\n\n"
},
{
"id": "python-java-PROGRAM_OCTAL_DECIMAL_CONVERSION",
"pair": "python-java",
"Code1": "def octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n",
"Code2": "static int octalToDecimal ( int n ) {\n int num = n ;\n int dec_value = 0 ;\n int base = 1 ;\n int temp = num ;\n while ( temp > 0 ) {\n int last_digit = temp % 10 ;\n temp = temp / 10 ;\n dec_value += last_digit * base ;\n base = base * 8 ;\n }\n return dec_value ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef octalToDecimal ( n ) :\n num = n\n dec_value = 0\n base = 1\n temp = num\n while ( temp ) :\n last_digit = temp % 10\n temp = int ( temp / 10 )\n dec_value += last_digit * base\n base = base * 8\n return dec_value\n\n"
},
{
"id": "python-java-FIND_THE_MISSING_NUMBER",
"pair": "python-java",
"Code1": "def getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n",
"Code2": "static int getMissingNo ( int a [ ] , int n ) {\n int i , total ;\n total = ( n + 1 ) * ( n + 2 ) / 2 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) total -= a [ i ] ;\n return total ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMissingNo ( A ) :\n n = len ( A )\n total = ( n + 1 ) * ( n + 2 ) / 2\n sum_of_A = sum ( A )\n return total - sum_of_A\n\n"
},
{
"id": "python-java-PRINT_SQUARES_FIRST_N_NATURAL_NUMBERS_WITHOUT_USING",
"pair": "python-java",
"Code1": "def printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n",
"Code2": "static void printSquares ( int n ) {\n int square = 0 , prev_x = 0 ;\n for ( int x = 0 ;\n x < n ;\n x ++ ) {\n square = ( square + x + prev_x ) ;\n System . out . print ( square + \" \" ) ;\n prev_x = x ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSquares ( n ) :\n square = 0 ; prev_x = 0 ;\n for x in range ( 0 , n ) :\n square = ( square + x + prev_x )\n print ( square , end = \" \" )\n prev_x = x\n\n"
},
{
"id": "python-java-PERMUTE_TWO_ARRAYS_SUM_EVERY_PAIR_GREATER_EQUAL_K",
"pair": "python-java",
"Code1": "def isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n",
"Code2": "static boolean isPossible ( Integer a [ ] , int b [ ] , int n , int k ) {\n Arrays . sort ( a , Collections . reverseOrder ( ) ) ;\n Arrays . sort ( b ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( a [ i ] + b [ i ] < k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPossible ( a , b , n , k ) :\n a.sort ( reverse = True )\n b.sort ( )\n for i in range ( n ) :\n if ( a [ i ] + b [ i ] < k ) :\n return False\n return True\n\n"
},
{
"id": "python-java-CHECK_WHETHER_GIVEN_CIRCLE_RESIDE_BOUNDARY_MAINTAINED_OUTER_CIRCLE_INNER_CIRCLE",
"pair": "python-java",
"Code1": "def fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n",
"Code2": "static void fitOrNotFit ( int R , int r , int x , int y , int rad ) {\n double val = Math . sqrt ( Math . pow ( x , 2 ) + Math . pow ( y , 2 ) ) ;\n if ( val + rad <= R && val - rad >= R - r ) System . out . println ( \"Fits\" ) ;\n else System . out . println ( \"Doesn't Fit\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef fitOrNotFit ( R , r , x , y , rad ) :\n val = math.sqrt ( math.pow ( x , 2 ) + math.pow ( y , 2 ) )\n if ( val + rad <= R and val - rad >= R - r ) :\n print ( \"Fits\\n\" )\n else :\n print ( \"Doesn't Fit\" )\n\n"
},
{
"id": "python-java-NTH_MULTIPLE_NUMBER_FIBONACCI_SERIES",
"pair": "python-java",
"Code1": "def findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n",
"Code2": "public static int findPosition ( int k , int n ) {\n long f1 = 0 , f2 = 1 , f3 ;\n int i = 2 ;\n while ( i != 0 ) {\n f3 = f1 + f2 ;\n f1 = f2 ;\n f2 = f3 ;\n if ( f2 % k == 0 ) {\n return n * i ;\n }\n i ++ ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findPosition ( k , n ) :\n f1 = 0\n f2 = 1\n i = 2\n while i != 0 :\n f3 = f1 + f2\n f1 = f2\n f2 = f3\n if f2 % k == 0 :\n return n * i\n i += 1\n return\n\n"
},
{
"id": "python-java-PRINT_N_TERMS_NEWMAN_CONWAY_SEQUENCE",
"pair": "python-java",
"Code1": "def sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n",
"Code2": "public static void sequence ( int n ) {\n int f [ ] = new int [ n + 1 ] ;\n f [ 0 ] = 0 ;\n f [ 1 ] = 1 ;\n f [ 2 ] = 1 ;\n System . out . print ( f [ 1 ] + \" \" + f [ 2 ] + \" \" ) ;\n for ( int i = 3 ;\n i <= n ;\n i ++ ) {\n f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ;\n System . out . print ( f [ i ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sequence ( n ) :\n f = [ 0 , 1 , 1 ]\n print ( f [ 1 ] , end = \" \" ) ,\n print ( f [ 2 ] , end = \" \" ) ,\n for i in range ( 3 , n + 1 ) :\n f.append ( f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] )\n print ( f [ i ] , end = \" \" ) ,\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_MANIPULATIONS_REQUIRED_TO_MAKE_TWO_STRINGS_ANAGRAM_WITHOUT_DELETION_OF_CHARACTER",
"pair": "python-java",
"Code1": "def countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n",
"Code2": "static int countManipulations ( String s1 , String s2 ) {\n int count = 0 ;\n int char_count [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < s1 . length ( ) ;\n i ++ ) char_count [ s1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < s2 . length ( ) ;\n i ++ ) if ( char_count [ s2 . charAt ( i ) - ' a ' ] -- <= 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countManipulations ( s1 , s2 ) :\n count = 0\n char_count = [ 0 ] * 26\n for i in range ( 26 ) :\n char_count [ i ] = 0\n for i in range ( len ( s1 ) ) :\n char_count [ ord ( s1 [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( len ( s2 ) ) :\n char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] -= 1\n if ( char_count [ ord ( s2 [ i ] ) - ord ( 'a' ) ] < 0 ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-COUNT_NUMBER_WAYS_REACH_GIVEN_SCORE_GAME",
"pair": "python-java",
"Code1": "def count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n",
"Code2": "static int count ( int n ) {\n int table [ ] = new int [ n + 1 ] , i ;\n Arrays . fill ( table , 0 ) ;\n table [ 0 ] = 1 ;\n for ( i = 3 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 3 ] ;\n for ( i = 5 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 5 ] ;\n for ( i = 10 ;\n i <= n ;\n i ++ ) table [ i ] += table [ i - 10 ] ;\n return table [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count ( n ) :\n table = [ 0 for i in range ( n + 1 ) ]\n table [ 0 ] = 1\n for i in range ( 3 , n + 1 ) :\n table [ i ] += table [ i - 3 ]\n for i in range ( 5 , n + 1 ) :\n table [ i ] += table [ i - 5 ]\n for i in range ( 10 , n + 1 ) :\n table [ i ] += table [ i - 10 ]\n return table [ n ]\n\n"
},
{
"id": "python-java-FIND_LENGTH_LONGEST_SUBSEQUENCE_ONE_STRING_SUBSTRING_ANOTHER_STRING",
"pair": "python-java",
"Code1": "def maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n",
"Code2": "static int maxSubsequenceSubstring ( char x [ ] , char y [ ] , int n , int m ) {\n int dp [ ] [ ] = new int [ MAX ] [ MAX ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) for ( int j = 0 ;\n j <= n ;\n j ++ ) dp [ i ] [ j ] = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( x [ j - 1 ] == y [ i - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n int ans = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) ans = Math . max ( ans , dp [ i ] [ n ] ) ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSubsequenceSubstring ( x , y , n , m ) :\n dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( x [ j - 1 ] == y [ i - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n ans = 0\n for i in range ( 1 , m + 1 ) :\n ans = max ( ans , dp [ i ] [ n ] )\n return ans\n\n"
},
{
"id": "python-java-LONGEST_REPEATING_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n",
"Code2": "static int findLongestRepeatingSubSeq ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n return dp [ n ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLongestRepeatingSubSeq ( str ) :\n n = len ( str )\n dp = [ [ 0 ] * ( n + 1 ) ] * ( n + 1 )\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n ] [ n ]\n\n"
},
{
"id": "python-java-PROGRAM_FIND_STRING_START_END_GEEKS",
"pair": "python-java",
"Code1": "def isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n",
"Code2": "static boolean isCornerPresent ( String str , String corner ) {\n int n = str . length ( ) ;\n int cl = corner . length ( ) ;\n if ( n < cl ) return false ;\n return ( str . substring ( 0 , cl ) . equals ( corner ) && str . substring ( n - cl , n ) . equals ( corner ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isCornerPresent ( str , corner ) :\n n = len ( str )\n cl = len ( corner )\n if ( n < cl ) :\n return False\n return ( ( str [ : cl ] == corner ) and ( str [ n - cl : ] == corner ) )\n\n"
},
{
"id": "python-java-MEDIAN_OF_TWO_SORTED_ARRAYS",
"pair": "python-java",
"Code1": "def getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n",
"Code2": "static int getMedian ( int ar1 [ ] , int ar2 [ ] , int n ) {\n int i = 0 ;\n int j = 0 ;\n int count ;\n int m1 = - 1 , m2 = - 1 ;\n for ( count = 0 ;\n count <= n ;\n count ++ ) {\n if ( i == n ) {\n m1 = m2 ;\n m2 = ar2 [ 0 ] ;\n break ;\n }\n else if ( j == n ) {\n m1 = m2 ;\n m2 = ar1 [ 0 ] ;\n break ;\n }\n if ( ar1 [ i ] < ar2 [ j ] ) {\n m1 = m2 ;\n m2 = ar1 [ i ] ;\n i ++ ;\n }\n else {\n m1 = m2 ;\n m2 = ar2 [ j ] ;\n j ++ ;\n }\n }\n return ( m1 + m2 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMedian ( ar1 , ar2 , n ) :\n i = 0\n j = 0\n m1 = - 1\n m2 = - 1\n count = 0\n while count < n + 1 :\n count += 1\n if i == n :\n m1 = m2\n m2 = ar2 [ 0 ]\n break\n elif j == n :\n m1 = m2\n m2 = ar1 [ 0 ]\n break\n if ar1 [ i ] < ar2 [ j ] :\n m1 = m2\n m2 = ar1 [ i ]\n i += 1\n else :\n m1 = m2\n m2 = ar2 [ j ]\n j += 1\n return ( m1 + m2 ) / 2\n\n"
},
{
"id": "python-java-COUNT_ZEROS_IN_A_ROW_WISE_AND_COLUMN_WISE_SORTED_MATRIX",
"pair": "python-java",
"Code1": "def countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n",
"Code2": "static int countZeroes ( int mat [ ] [ ] ) {\n int row = N - 1 , col = 0 ;\n int count = 0 ;\n while ( col < N ) {\n while ( mat [ row ] [ col ] > 0 ) if ( -- row < 0 ) return count ;\n count += ( row + 1 ) ;\n col ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countZeroes ( mat ) :\n N = 5 ;\n row = N - 1 ;\n col = 0 ;\n count = 0 ;\n while ( col < N ) :\n while ( mat [ row ] [ col ] ) :\n if ( row < 0 ) :\n return count ;\n row = row - 1 ;\n count = count + ( row + 1 ) ;\n col = col + 1 ;\n return count ;\n\n"
},
{
"id": "python-java-JUMP_SEARCH",
"pair": "python-java",
"Code1": "def jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n",
"Code2": "public static int jumpSearch ( int [ ] arr , int x ) {\n int n = arr . length ;\n int step = ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n int prev = 0 ;\n while ( arr [ Math . min ( step , n ) - 1 ] < x ) {\n prev = step ;\n step += ( int ) Math . floor ( Math . sqrt ( n ) ) ;\n if ( prev >= n ) return - 1 ;\n }\n while ( arr [ prev ] < x ) {\n prev ++ ;\n if ( prev == Math . min ( step , n ) ) return - 1 ;\n }\n if ( arr [ prev ] == x ) return prev ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef jumpSearch ( arr , x , n ) :\n step = math.sqrt ( n )\n prev = 0\n while arr [ int ( min ( step , n ) - 1 ) ] < x :\n prev = step\n step += math.sqrt ( n )\n if prev >= n :\n return - 1\n while arr [ int ( prev ) ] < x :\n prev += 1\n if prev == min ( step , n ) :\n return - 1\n if arr [ int ( prev ) ] == x :\n return prev\n return - 1\n\n"
},
{
"id": "python-java-FIND_X_Y_SATISFYING_AX_N",
"pair": "python-java",
"Code1": "def solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n",
"Code2": "static void solution ( int a , int b , int n ) {\n for ( int i = 0 ;\n i * a <= n ;\n i ++ ) {\n if ( ( n - ( i * a ) ) % b == 0 ) {\n System . out . println ( \"x = \" + i + \", y = \" + ( n - ( i * a ) ) / b ) ;\n return ;\n }\n }\n System . out . println ( \"No solution\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solution ( a , b , n ) :\n i = 0\n while i * a <= n :\n if ( n - ( i * a ) ) % b == 0 :\n print ( \"x = \" , i , \", y = \" , int ( ( n - ( i * a ) ) / b ) )\n return 0\n i = i + 1\n print ( \"No solution\" )\n\n"
},
{
"id": "python-java-DIVIDE_LARGE_NUMBER_REPRESENTED_STRING",
"pair": "python-java",
"Code1": "def longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n",
"Code2": "static String longDivision ( String number , int divisor ) {\n String ans = \"\" ;\n int idx = 0 ;\n char [ ] num = number . toCharArray ( ) ;\n int temp = num [ idx ] - ' 0 ' ;\n while ( temp < divisor ) temp = temp * 10 + ( num [ ++ idx ] - ' 0 ' ) ;\n idx += 1 ;\n while ( num . length > idx ) {\n ans += ( temp / divisor ) ;\n temp = ( temp % divisor ) * 10 + num [ idx ++ ] - ' 0 ' ;\n }\n if ( ans . length ( ) == 0 ) return \"0\" ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longDivision ( number , divisor ) :\n ans = \"\"\n idx = 0\n temp = ord ( number [ idx ] ) - ord ( '0' )\n while ( temp < divisor ) :\n temp = ( temp * 10 + ord ( number [ idx + 1 ] ) - ord ( '0' ) )\n idx += 1\n idx += 1\n while ( ( len ( number ) ) > idx ) :\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n temp = ( ( temp % divisor ) * 10 + ord ( number [ idx ] ) - ord ( '0' ) )\n idx += 1\n ans += chr ( math.floor ( temp // divisor ) + ord ( '0' ) )\n if ( len ( ans ) == 0 ) :\n return \"0\"\n return ans\n\n"
},
{
"id": "python-java-SORT_AN_ARRAY_OF_0S_1S_AND_2S",
"pair": "python-java",
"Code1": "def sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n",
"Code2": "static void sort012 ( int a [ ] , int arr_size ) {\n int lo = 0 ;\n int hi = arr_size - 1 ;\n int mid = 0 , temp = 0 ;\n while ( mid <= hi ) {\n switch ( a [ mid ] ) {\n case 0 : {\n temp = a [ lo ] ;\n a [ lo ] = a [ mid ] ;\n a [ mid ] = temp ;\n lo ++ ;\n mid ++ ;\n break ;\n }\n case 1 : mid ++ ;\n break ;\n case 2 : {\n temp = a [ mid ] ;\n a [ mid ] = a [ hi ] ;\n a [ hi ] = temp ;\n hi -- ;\n break ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sort012 ( a , arr_size ) :\n lo = 0\n hi = arr_size - 1\n mid = 0\n while mid <= hi :\n if a [ mid ] == 0 :\n a [ lo ] , a [ mid ] = a [ mid ] , a [ lo ]\n lo = lo + 1\n mid = mid + 1\n elif a [ mid ] == 1 :\n mid = mid + 1\n else :\n a [ mid ] , a [ hi ] = a [ hi ] , a [ mid ]\n hi = hi - 1\n\n"
},
{
"id": "python-java-CHECK_IF_A_GIVEN_ARRAY_CAN_REPRESENT_PREORDER_TRAVERSAL_OF_BINARY_SEARCH_TREE",
"pair": "python-java",
"Code1": "def canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n",
"Code2": "boolean canRepresentBST ( int pre [ ] , int n ) {\n Stack < Integer > s = new Stack < Integer > ( ) ;\n int root = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( pre [ i ] < root ) {\n return false ;\n }\n while ( ! s . empty ( ) && s . peek ( ) < pre [ i ] ) {\n root = s . peek ( ) ;\n s . pop ( ) ;\n }\n s . push ( pre [ i ] ) ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef canRepresentBST ( pre ) :\n s = [ ]\n root = INT_MIN\n for value in pre :\n if value < root :\n return False\n while ( len ( s ) > 0 and s [ - 1 ] < value ) :\n root = s.pop ( )\n s.append ( value )\n return True\n\n"
},
{
"id": "python-java-FIND_K_SUCH_THAT_ALL_ELEMENTS_IN_KTH_ROW_ARE_0_AND_KTH_COLUMN_ARE_1_IN_A_BOOLEAN_MATRIX",
"pair": "python-java",
"Code1": "def find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n",
"Code2": "static int find ( boolean arr [ ] [ ] ) {\n int i = 0 , j = n - 1 ;\n int res = - 1 ;\n while ( i < n && j >= 0 ) {\n if ( arr [ i ] [ j ] == false ) {\n while ( j >= 0 && ( arr [ i ] [ j ] == false || i == j ) ) {\n j -- ;\n }\n if ( j == - 1 ) {\n res = i ;\n break ;\n }\n else {\n i ++ ;\n }\n }\n else {\n while ( i < n && ( arr [ i ] [ j ] == true || i == j ) ) {\n i ++ ;\n }\n if ( i == n ) {\n res = j ;\n break ;\n }\n else {\n j -- ;\n }\n }\n }\n if ( res == - 1 ) {\n return res ;\n }\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( res != k && arr [ k ] [ res ] != true ) {\n return - 1 ;\n }\n }\n for ( int l = 0 ;\n l < n ;\n l ++ ) {\n if ( res != l && arr [ res ] [ l ] != false ) {\n return - 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find ( arr ) :\n n = len ( arr )\n i = 0\n j = n - 1\n res = - 1\n while i < n and j >= 0 :\n if arr [ i ] [ j ] == 0 :\n while j >= 0 and ( arr [ i ] [ j ] == 0 or i == j ) :\n j -= 1\n if j == - 1 :\n res = i\n break\n else : i += 1\n else :\n while i < n and ( arr [ i ] [ j ] == 1 or i == j ) :\n i += 1\n if i == n :\n res = j\n break\n else : j -= 1\n if res == - 1 :\n return res\n for i in range ( 0 , n ) :\n if res != i and arr [ i ] [ res ] != 1 :\n return - 1\n for j in range ( 0 , j ) :\n if res != j and arr [ res ] [ j ] != 0 :\n return - 1 ;\n return res ;\n\n"
},
{
"id": "python-java-POSITIVE_ELEMENTS_EVEN_NEGATIVE_ODD_POSITIONS_1",
"pair": "python-java",
"Code1": "def printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n",
"Code2": "static void printArray ( int [ ] a , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printArray ( a , n ) :\n for i in a :\n print ( i , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-SORT_ARRAY_CONVERTING_ELEMENTS_SQUARES_1",
"pair": "python-java",
"Code1": "def sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n",
"Code2": "public static void sortSquares ( int arr [ ] ) {\n int n = arr . length ;\n int k ;\n for ( k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ k ] >= 0 ) break ;\n }\n int i = k - 1 ;\n int j = k ;\n int ind = 0 ;\n int [ ] temp = new int [ n ] ;\n while ( i >= 0 && j < n ) {\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) {\n temp [ ind ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n else {\n temp [ ind ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n ind ++ ;\n }\n while ( i >= 0 ) {\n temp [ ind ++ ] = arr [ i ] * arr [ i ] ;\n i -- ;\n }\n while ( j < n ) {\n temp [ ind ++ ] = arr [ j ] * arr [ j ] ;\n j ++ ;\n }\n for ( int x = 0 ;\n x < n ;\n x ++ ) arr [ x ] = temp [ x ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortSquares ( arr , n ) :\n K = 0\n for K in range ( n ) :\n if ( arr [ K ] >= 0 ) :\n break\n i = K - 1\n j = K\n ind = 0\n temp = [ 0 ] * n\n while ( i >= 0 and j < n ) :\n if ( arr [ i ] * arr [ i ] < arr [ j ] * arr [ j ] ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n else :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n while ( i >= 0 ) :\n temp [ ind ] = arr [ i ] * arr [ i ]\n i -= 1\n ind += 1\n while ( j < n ) :\n temp [ ind ] = arr [ j ] * arr [ j ]\n j += 1\n ind += 1\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n\n"
},
{
"id": "python-java-PRINT_MAXIMUM_SHORTEST_DISTANCE",
"pair": "python-java",
"Code1": "def find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n",
"Code2": "static int find_maximum ( int a [ ] , int n , int k ) {\n HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n int d = Math . min ( 1 + i , n - i ) ;\n if ( ! b . containsKey ( x ) ) b . put ( x , d ) ;\n else {\n b . put ( x , Math . min ( d , b . get ( x ) ) ) ;\n }\n }\n int ans = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find_maximum ( a , n , k ) :\n b = dict ( )\n for i in range ( n ) :\n x = a [ i ]\n d = min ( 1 + i , n - i )\n if x not in b.keys ( ) :\n b [ x ] = d\n else :\n b [ x ] = min ( d , b [ x ] )\n ans = 10 ** 9\n for i in range ( n ) :\n x = a [ i ]\n if ( x != ( k - x ) and ( k - x ) in b.keys ( ) ) :\n ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )\n return ans\n\n"
},
{
"id": "python-java-MAXIMUM_CONSECUTIVE_REPEATING_CHARACTER_STRING_1",
"pair": "python-java",
"Code1": "def maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n",
"Code2": "static char maxRepeating ( String str ) {\n int n = str . length ( ) ;\n int count = 0 ;\n char res = str . charAt ( 0 ) ;\n int cur_count = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) cur_count ++ ;\n else {\n if ( cur_count > count ) {\n count = cur_count ;\n res = str . charAt ( i ) ;\n }\n cur_count = 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxRepeating ( str ) :\n n = len ( str )\n count = 0\n res = str [ 0 ]\n cur_count = 1\n for i in range ( n ) :\n if ( i < n - 1 and str [ i ] == str [ i + 1 ] ) :\n cur_count += 1\n else :\n if cur_count > count :\n count = cur_count\n res = str [ i ]\n cur_count = 1\n return res\n\n"
},
{
"id": "python-java-ARRAY_RANGE_QUERIES_ELEMENTS_FREQUENCY_VALUE",
"pair": "python-java",
"Code1": "def solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n",
"Code2": "static int solveQuery ( int start , int end , int arr [ ] ) {\n Map < Integer , Integer > mp = new HashMap < > ( ) ;\n for ( int i = start ;\n i <= end ;\n i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ;\n int count = 0 ;\n for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) if ( entry . getKey ( ) == entry . getValue ( ) ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solveQuery ( start , end , arr ) :\n frequency = dict ( )\n for i in range ( start , end + 1 ) :\n if arr [ i ] in frequency.keys ( ) :\n frequency [ arr [ i ] ] += 1\n else :\n frequency [ arr [ i ] ] = 1\n count = 0\n for x in frequency :\n if x == frequency [ x ] :\n count += 1\n return count\n\n"
},
{
"id": "python-java-PYTHON_PROGRAM_FIND_PERIMETER_CIRCUMFERENCE_SQUARE_RECTANGLE",
"pair": "python-java",
"Code1": "def Circumference ( a ) :\n return ( 4 * a )\n",
"Code2": "int Circumference ( int a ) {\n return 4 * a ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef Circumference ( a ) :\n return ( 4 * a )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_3",
"pair": "python-java",
"Code1": "def numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int path = 1 ;\n for ( int i = n ;\n i < ( m + n - 1 ) ;\n i ++ ) {\n path *= i ;\n path /= ( i - n + 1 ) ;\n }\n return path ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( m , n ) :\n for i in range ( n , ( m + n - 1 ) ) :\n path *= i\n path //= ( i - n + 1 )\n return path\n\n"
},
{
"id": "python-java-POINT_CLIPPING_ALGORITHM_COMPUTER_GRAPHICS",
"pair": "python-java",
"Code1": "def pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n",
"Code2": "static void pointClip ( int XY [ ] [ ] , int n , int Xmin , int Ymin , int Xmax , int Ymax ) {\n System . out . printf ( \"Point inside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] >= Xmin ) && ( XY [ i ] [ 0 ] <= Xmax ) ) {\n if ( ( XY [ i ] [ 1 ] >= Ymin ) && ( XY [ i ] [ 1 ] <= Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n }\n System . out . printf ( \"\\nPoint outside the viewing pane:\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( XY [ i ] [ 0 ] < Xmin ) || ( XY [ i ] [ 0 ] > Xmax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n if ( ( XY [ i ] [ 1 ] < Ymin ) || ( XY [ i ] [ 1 ] > Ymax ) ) System . out . printf ( \"[%d, %d] \" , XY [ i ] [ 0 ] , XY [ i ] [ 1 ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pointClip ( XY , n , Xmin , Ymin , Xmax , Ymax ) :\n print ( \"Point inside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] >= Xmin ) and ( XY [ i ] [ 0 ] <= Xmax ) ) :\n if ( ( XY [ i ] [ 1 ] >= Ymin ) and ( XY [ i ] [ 1 ] <= Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n print ( \"\\n\\nPoint outside the viewing pane:\" )\n for i in range ( n ) :\n if ( ( XY [ i ] [ 0 ] < Xmin ) or ( XY [ i ] [ 0 ] > Xmax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n if ( ( XY [ i ] [ 1 ] < Ymin ) or ( XY [ i ] [ 1 ] > Ymax ) ) :\n print ( \"[\" , XY [ i ] [ 0 ] , \", \" , XY [ i ] [ 1 ] , \"]\" , sep = \"\" , end = \"\" )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_INCREASING_SUBSEQUENCE_FROM_A_PREFIX_AND_A_GIVEN_ELEMENT_AFTER_PREFIX_IS_MUST",
"pair": "python-java",
"Code1": "def pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n",
"Code2": "static int pre_compute ( int a [ ] , int n , int index , int k ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > a [ 0 ] ) dp [ 0 ] [ i ] = a [ i ] + a [ 0 ] ;\n else dp [ 0 ] [ i ] = a [ i ] ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n if ( a [ j ] > a [ i ] && j > i ) {\n if ( dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] ) dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ] ;\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;\n }\n }\n return dp [ index ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pre_compute ( a , n , index , k ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n for i in range ( n ) :\n if a [ i ] > a [ 0 ] :\n dp [ 0 ] [ i ] = a [ i ] + a [ 0 ]\n else :\n dp [ 0 ] [ i ] = a [ i ]\n for i in range ( 1 , n ) :\n for j in range ( n ) :\n if a [ j ] > a [ i ] and j > i :\n if dp [ i - 1 ] [ i ] + a [ j ] > dp [ i - 1 ] [ j ] :\n dp [ i ] [ j ] = dp [ i - 1 ] [ i ] + a [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n else :\n dp [ i ] [ j ] = dp [ i - 1 ] [ j ]\n return dp [ index ] [ k ]\n\n"
},
{
"id": "python-java-SPLIT_ARRAY_ADD_FIRST_PART_END",
"pair": "python-java",
"Code1": "def splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n",
"Code2": "public static void splitArr ( int arr [ ] , int n , int k ) {\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int x = arr [ 0 ] ;\n for ( int j = 0 ;\n j < n - 1 ;\n ++ j ) arr [ j ] = arr [ j + 1 ] ;\n arr [ n - 1 ] = x ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef splitArr ( arr , n , k ) :\n for i in range ( 0 , k ) :\n x = arr [ 0 ]\n for j in range ( 0 , n - 1 ) :\n arr [ j ] = arr [ j + 1 ]\n arr [ n - 1 ] = x\n\n"
},
{
"id": "python-java-MINIMUM_LENGTH_SUBARRAY_SUM_GREATER_GIVEN_VALUE_1",
"pair": "python-java",
"Code1": "def smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n",
"Code2": "static int smallestSubWithSum ( int arr [ ] , int n , int x ) {\n int curr_sum = 0 , min_len = n + 1 ;\n int start = 0 , end = 0 ;\n while ( end < n ) {\n while ( curr_sum <= x && end < n ) {\n if ( curr_sum <= 0 && x > 0 ) {\n start = end ;\n curr_sum = 0 ;\n }\n curr_sum += arr [ end ++ ] ;\n }\n while ( curr_sum > x && start < n ) {\n if ( end - start < min_len ) min_len = end - start ;\n curr_sum -= arr [ start ++ ] ;\n }\n }\n return min_len ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef smallestSubWithSum ( arr , n , x ) :\n curr_sum = 0\n min_len = n + 1\n start = 0\n end = 0\n while ( end < n ) :\n while ( curr_sum <= x and end < n ) :\n if ( curr_sum <= 0 and x > 0 ) :\n start = end\n curr_sum = 0\n curr_sum += arr [ end ]\n end += 1\n while ( curr_sum > x and start < n ) :\n if ( end - start < min_len ) :\n min_len = end - start\n curr_sum -= arr [ start ]\n start += 1\n return min_len\n\n"
},
{
"id": "python-java-ARRAY_ELEMENT_MOVED_K_USING_SINGLE_MOVES",
"pair": "python-java",
"Code1": "def winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n",
"Code2": "static int winner ( int a [ ] , int n , int k ) {\n if ( k >= n - 1 ) return n ;\n int best = 0 , times = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] > best ) {\n best = a [ i ] ;\n if ( i == 1 ) times = 1 ;\n }\n else times += 1 ;\n if ( times >= k ) return best ;\n }\n return best ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef winner ( a , n , k ) :\n if k >= n - 1 :\n return n\n best = 0\n times = 0\n for i in range ( n ) :\n if a [ i ] > best :\n best = a [ i ]\n if i == True :\n times = 1\n else :\n times += 1\n if times >= k :\n return best\n return best\n\n"
},
{
"id": "python-java-CHECK_LARGE_NUMBER_DIVISIBLE_20",
"pair": "python-java",
"Code1": "def divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n",
"Code2": "static Boolean divisibleBy20 ( String num ) {\n int lastTwoDigits = Integer . parseInt ( num . substring ( num . length ( ) - 2 , num . length ( ) ) ) ;\n return ( ( lastTwoDigits % 5 == 0 ) && ( lastTwoDigits % 4 == 0 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef divisibleBy20 ( num ) :\n lastTwoDigits = int ( num [ - 2 : ] )\n return ( ( lastTwoDigits % 5 == 0 and lastTwoDigits % 4 == 0 ) )\n\n"
},
{
"id": "python-java-COUNT_DISTINCT_NON_NEGATIVE_PAIRS_X_Y_SATISFY_INEQUALITY_XX_YY_N_2_1",
"pair": "python-java",
"Code1": "def countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n",
"Code2": "static int countSolutions ( int n ) {\n int x = 0 , yCount , res = 0 ;\n for ( yCount = 0 ;\n yCount * yCount < n ;\n yCount ++ ) ;\n while ( yCount != 0 ) {\n res += yCount ;\n x ++ ;\n while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSolutions ( n ) :\n x = 0\n res = 0\n yCount = 0\n while ( yCount * yCount < n ) :\n yCount = yCount + 1\n while ( yCount != 0 ) :\n res = res + yCount\n x = x + 1\n while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) :\n yCount = yCount - 1\n return res\n\n"
},
{
"id": "python-java-FIND_NUMBER_OF_TRIANGLES_POSSIBLE_1",
"pair": "python-java",
"Code1": "def CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n",
"Code2": "static void CountTriangles ( int [ ] A ) {\n int n = A . length ;\n Arrays . sort ( A ) ;\n int count = 0 ;\n for ( int i = n - 1 ;\n i >= 1 ;\n i -- ) {\n int l = 0 , r = i - 1 ;\n while ( l < r ) {\n if ( A [ l ] + A [ r ] > A [ i ] ) {\n count += r - l ;\n r -- ;\n }\n else {\n l ++ ;\n }\n }\n }\n System . out . print ( \"No of possible solutions: \" + count ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef CountTriangles ( A ) :\n n = len ( A )\n A.sort ( )\n count = 0\n for i in range ( n - 1 , 0 , - 1 ) :\n l = 0\n r = i - 1\n while ( l < r ) :\n if ( A [ l ] + A [ r ] > A [ i ] ) :\n count += r - l\n r -= 1\n else :\n l += 1\n print ( \"No of possible solutions: \" , count )\n\n"
},
{
"id": "python-java-NEXT_HIGHER_NUMBER_WITH_SAME_NUMBER_OF_SET_BITS",
"pair": "python-java",
"Code1": "def snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit",
"Code2": "static int snoob ( int x ) {\n int rightOne , nextHigherOneBit , rightOnesPattern , next = 0 ;\n if ( x > 0 ) {\n rightOne = x & - x ;\n nextHigherOneBit = x + rightOne ;\n rightOnesPattern = x ^ nextHigherOneBit ;\n rightOnesPattern = ( rightOnesPattern ) / rightOne ;\n rightOnesPattern >>= 2 ;\n next = nextHigherOneBit",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef snoob ( x ) :\n next = 0\n if ( x ) :\n rightOne = x & - ( x )\n nextHigherOneBit = x + int ( rightOne )\n rightOnesPattern = x ^ int ( nextHigherOneBit )\n rightOnesPattern = ( int ( rightOnesPattern ) / int ( rightOne ) )\n rightOnesPattern = int ( rightOnesPattern ) >> 2\n next = nextHigherOneBit\n"
},
{
"id": "python-java-CHECK_ARRAY_REPRESENTS_INORDER_BINARY_SEARCH_TREE_NOT",
"pair": "python-java",
"Code1": "def isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "static boolean isInorder ( int [ ] arr , int n ) {\n if ( n == 0 || n == 1 ) {\n return true ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( arr [ i - 1 ] > arr [ i ] ) {\n return false ;\n }\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isInorder ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n , 1 ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-java-LONGEST_INCREASING_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n",
"Code2": "static int lis ( int arr [ ] , int n ) {\n max_ref = 1 ;\n _lis ( arr , n ) ;\n return max_ref ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lis ( arr ) :\n global maximum\n n = len ( arr )\n maximum = 1\n _lis ( arr , n )\n return maximum\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY",
"pair": "python-java",
"Code1": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n",
"Code2": "static int maxProduct ( int [ ] arr , int n ) {\n if ( n < 3 ) return - 1 ;\n int max_product = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n - 2 ;\n i ++ ) for ( int j = i + 1 ;\n j < n - 1 ;\n j ++ ) for ( int k = j + 1 ;\n k < n ;\n k ++ ) max_product = Math . max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] ) ;\n return max_product ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n max_product = - ( sys.maxsize - 1 )\n for i in range ( 0 , n - 2 ) :\n for j in range ( i + 1 , n - 1 ) :\n for k in range ( j + 1 , n ) :\n max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] )\n return max_product\n\n"
},
{
"id": "python-java-FREQUENCY_ELEMENT_UNSORTED_ARRAY",
"pair": "python-java",
"Code1": "def countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n",
"Code2": "static void countFreq ( int [ ] a , int n ) {\n HashMap < Integer , Integer > hm = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) hm . put ( a [ i ] , hm . get ( a [ i ] ) == null ? 1 : hm . get ( a [ i ] ) + 1 ) ;\n SortedMap < Integer , Integer > st = new TreeMap < > ( ) ;\n for ( HashMap . Entry < Integer , Integer > x : hm . entrySet ( ) ) {\n st . put ( x . getKey ( ) , x . getValue ( ) ) ;\n }\n int cumul = 0 ;\n for ( SortedMap . Entry < Integer , Integer > x : st . entrySet ( ) ) {\n cumul += x . getValue ( ) ;\n System . out . println ( x . getKey ( ) + \" \" + cumul ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countFreq ( a , n ) :\n hm = { }\n for i in range ( 0 , n ) :\n hm [ a [ i ] ] = hm.get ( a [ i ] , 0 ) + 1\n st = set ( )\n for x in hm :\n st.add ( ( x , hm [ x ] ) )\n cumul = 0\n for x in sorted ( st ) :\n cumul += x [ 1 ]\n print ( x [ 0 ] , cumul )\n\n"
},
{
"id": "python-java-COMPUTE_NCR_P_SET_1_INTRODUCTION_AND_DYNAMIC_PROGRAMMING_SOLUTION",
"pair": "python-java",
"Code1": "def nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n",
"Code2": "static int nCrModp ( int n , int r , int p ) {\n int C [ ] = new int [ r + 1 ] ;\n Arrays . fill ( C , 0 ) ;\n C [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = Math . min ( i , r ) ;\n j > 0 ;\n j -- ) C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p ;\n }\n return C [ r ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nCrModp ( n , r , p ) :\n C = [ 0 for i in range ( r + 1 ) ]\n C [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n for j in range ( min ( i , r ) , 0 , - 1 ) :\n C [ j ] = ( C [ j ] + C [ j - 1 ] ) % p\n return C [ r ]\n\n"
},
{
"id": "python-java-COCKTAIL_SORT",
"pair": "python-java",
"Code1": "def cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n",
"Code2": "void cocktailSort ( int a [ ] ) {\n boolean swapped = true ;\n int start = 0 ;\n int end = a . length ;\n while ( swapped == true ) {\n swapped = false ;\n for ( int i = start ;\n i < end - 1 ;\n ++ i ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n if ( swapped == false ) break ;\n swapped = false ;\n end = end - 1 ;\n for ( int i = end - 1 ;\n i >= start ;\n i -- ) {\n if ( a [ i ] > a [ i + 1 ] ) {\n int temp = a [ i ] ;\n a [ i ] = a [ i + 1 ] ;\n a [ i + 1 ] = temp ;\n swapped = true ;\n }\n }\n start = start + 1 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef cocktailSort ( a ) :\n n = len ( a )\n swapped = True\n start = 0\n end = n - 1\n while ( swapped == True ) :\n swapped = False\n for i in range ( start , end ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n if ( swapped == False ) :\n break\n swapped = False\n end = end - 1\n for i in range ( end - 1 , start - 1 , - 1 ) :\n if ( a [ i ] > a [ i + 1 ] ) :\n a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]\n swapped = True\n start = start + 1\n\n"
},
{
"id": "python-java-WORD_WRAP_PROBLEM_SPACE_OPTIMIZED_SOLUTION",
"pair": "python-java",
"Code1": "def solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n",
"Code2": "static void solveWordWrap ( int arr [ ] , int n , int k ) {\n int i , j ;\n int currlen ;\n int cost ;\n int dp [ ] = new int [ n ] ;\n int ans [ ] = new int [ n ] ;\n dp [ n - 1 ] = 0 ;\n ans [ n - 1 ] = n - 1 ;\n for ( i = n - 2 ;\n i >= 0 ;\n i -- ) {\n currlen = - 1 ;\n dp [ i ] = Integer . MAX_VALUE ;\n for ( j = i ;\n j < n ;\n j ++ ) {\n currlen += ( arr [ j ] + 1 ) ;\n if ( currlen > k ) break ;\n if ( j == n - 1 ) cost = 0 ;\n else cost = ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] ;\n if ( cost < dp [ i ] ) {\n dp [ i ] = cost ;\n ans [ i ] = j ;\n }\n }\n }\n i = 0 ;\n while ( i < n ) {\n System . out . print ( ( i + 1 ) + \" \" + ( ans [ i ] + 1 ) + \" \" ) ;\n i = ans [ i ] + 1 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solveWordWrap ( arr , n , k ) :\n dp = [ 0 ] * n\n ans = [ 0 ] * n\n dp [ n - 1 ] = 0\n ans [ n - 1 ] = n - 1\n for i in range ( n - 2 , - 1 , - 1 ) :\n currlen = - 1\n dp [ i ] = sys.maxsize\n for j in range ( i , n ) :\n currlen += ( arr [ j ] + 1 )\n if ( currlen > k ) :\n break\n if ( j == n - 1 ) :\n cost = 0\n else :\n cost = ( ( k - currlen ) * ( k - currlen ) + dp [ j + 1 ] )\n if ( cost < dp [ i ] ) :\n dp [ i ] = cost\n ans [ i ] = j\n i = 0\n while ( i < n ) :\n print ( i + 1 , ans [ i ] + 1 , end = \" \" )\n i = ans [ i ] + 1\n\n"
},
{
"id": "python-java-BINARY_SEARCH_1",
"pair": "python-java",
"Code1": "def binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int x ) {\n int l = 0 , r = arr . length - 1 ;\n while ( l <= r ) {\n int m = l + ( r - l ) / 2 ;\n if ( arr [ m ] == x ) return m ;\n if ( arr [ m ] < x ) l = m + 1 ;\n else r = m - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n while l <= r :\n mid = l + ( r - l ) // 2\n if arr [ mid ] == x :\n return mid\n elif arr [ mid ] < x :\n l = mid + 1\n else :\n r = mid - 1\n return - 1\n\n"
},
{
"id": "python-java-MINIMUM_XOR_VALUE_PAIR",
"pair": "python-java",
"Code1": "def minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n",
"Code2": "static int minXOR ( int arr [ ] , int n ) {\n int min_xor = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = i + 1 ;\n j < n ;\n j ++ ) min_xor = Math . min ( min_xor , arr [ i ] ^ arr [ j ] ) ;\n return min_xor ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minXOR ( arr , n ) :\n arr.sort ( )\n min_xor = 999999\n val = 0\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n - 1 ) :\n val = arr [ i ] ^ arr [ j ]\n min_xor = min ( min_xor , val )\n return min_xor\n\n"
},
{
"id": "python-java-FIND_SUM_EVEN_FACTORS_NUMBER",
"pair": "python-java",
"Code1": "def sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n",
"Code2": "public static int sumofFactors ( int n ) {\n if ( n % 2 != 0 ) return 0 ;\n int res = 1 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n if ( i == 2 && count == 1 ) curr_sum = 0 ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumofFactors ( n ) :\n if ( n % 2 != 0 ) :\n return 0\n res = 1\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while ( n % i == 0 ) :\n count = count + 1\n n = n // i\n if ( i == 2 and count == 1 ) :\n curr_sum = 0\n curr_term = curr_term * i\n curr_sum = curr_sum + curr_term\n res = res * curr_sum\n if ( n >= 2 ) :\n res = res * ( 1 + n )\n return res\n\n"
},
{
"id": "python-java-FIRST_UPPERCASE_LETTER_IN_A_STRING_ITERATIVE_AND_RECURSIVE_1",
"pair": "python-java",
"Code1": "def first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n",
"Code2": "static char first ( String str , int i ) {\n if ( str . charAt ( i ) == ' \\0 ' ) return 0 ;\n if ( Character . isUpperCase ( str . charAt ( i ) ) ) return str . charAt ( i ) ;\n return first ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef first ( str , i ) :\n if ( str [ i ] == '\\0' ) :\n return 0\n if ( str [ i ].isupper ( ) ) :\n return str [ i ]\n return first ( str , i + 1 )\n\n"
},
{
"id": "python-java-MAXIMUM_GAMES_PLAYED_WINNER",
"pair": "python-java",
"Code1": "def maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n",
"Code2": "static int maxGameByWinner ( int N ) {\n int [ ] dp = new int [ N ] ;\n dp [ 0 ] = 1 ;\n dp [ 1 ] = 2 ;\n int i = 2 ;\n do {\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ;\n }\n while ( dp [ i ++ ] <= N ) ;\n return ( i - 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxGameByWinner ( N ) :\n dp = [ 0 for i in range ( N ) ]\n dp [ 0 ] = 1\n dp [ 1 ] = 2\n i = 1\n while dp [ i ] <= N :\n i = i + 1\n dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]\n return ( i - 1 )\n\n"
},
{
"id": "python-java-EQUILIBRIUM_INDEX_OF_AN_ARRAY_1",
"pair": "python-java",
"Code1": "def equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n",
"Code2": "int equilibrium ( int arr [ ] , int n ) {\n int sum = 0 ;\n int leftsum = 0 ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) sum += arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n ++ i ) {\n sum -= arr [ i ] ;\n if ( leftsum == sum ) return i ;\n leftsum += arr [ i ] ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef equilibrium ( arr ) :\n total_sum = sum ( arr )\n leftsum = 0\n for i , num in enumerate ( arr ) :\n total_sum -= num\n if leftsum == total_sum :\n return i\n leftsum += num\n return - 1\n\n"
},
{
"id": "python-java-PROBABILITY_THREE_RANDOMLY_CHOSEN_NUMBERS_AP",
"pair": "python-java",
"Code1": "def procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n",
"Code2": "static double procal ( int n ) {\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef procal ( n ) :\n return ( 3.0 * n ) / ( 4.0 * ( n * n ) - 1 )\n\n"
},
{
"id": "python-java-REARRANGE_ARRAY_MAXIMUM_MINIMUM_FORM",
"pair": "python-java",
"Code1": "def rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n",
"Code2": "static void rearrange ( int [ ] arr , int n ) {\n int temp [ ] = new int [ n ] ;\n int small = 0 , large = n - 1 ;\n boolean flag = true ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( flag ) temp [ i ] = arr [ large -- ] ;\n else temp [ i ] = arr [ small ++ ] ;\n flag = ! flag ;\n }\n arr = temp . clone ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rearrange ( arr , n ) :\n temp = n * [ None ]\n small , large = 0 , n - 1\n flag = True\n for i in range ( n ) :\n if flag is True :\n temp [ i ] = arr [ large ]\n large -= 1\n else :\n temp [ i ] = arr [ small ]\n small += 1\n flag = bool ( 1 - flag )\n for i in range ( n ) :\n arr [ i ] = temp [ i ]\n return arr\n\n"
},
{
"id": "python-java-PRINT_DIGITS_POSITION_REMOVED_MAKE_NUMBER_DIVISIBLE_6",
"pair": "python-java",
"Code1": "def greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n",
"Code2": "static void greatest ( String s ) {\n int n = s . length ( ) ;\n int [ ] a = new int [ n ] ;\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n a [ i ] = s . charAt ( i ) - ' 0 ' ;\n sum += a [ i ] ;\n }\n if ( a [ n - 1 ] % 2 != 0 ) {\n if ( a [ n - 2 ] % 2 != 0 || ( sum - a [ n - 1 ] ) % 3 != 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n System . out . println ( n ) ;\n }\n }\n else {\n int re = sum % 3 ;\n int del = - 1 ;\n int flag = 0 ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n if ( ( a [ i ] ) % 3 == re ) {\n if ( a [ i + 1 ] > a [ i ] ) {\n del = i ;\n flag = 1 ;\n break ;\n }\n else {\n del = i ;\n }\n }\n }\n if ( flag == 0 ) {\n if ( a [ n - 2 ] % 2 == 0 && re == a [ n - 1 ] % 3 ) del = n - 1 ;\n }\n if ( del == - 1 ) System . out . println ( - 1 ) ;\n else {\n System . out . println ( del + 1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef greatest ( s ) :\n n = len ( s )\n a = [ 0 for i in range ( n ) ]\n Sum = 0\n for i in range ( n ) :\n a [ i ] = ord ( s [ i ] ) - ord ( '0' )\n Sum += a [ i ]\n if ( a [ n - 1 ] % 2 ) :\n if ( a [ n - 2 ] % 2 != 0 or ( Sum - a [ n - 1 ] ) % 3 != 0 ) :\n print ( \"-1\" )\n else :\n print ( n )\n else :\n re = Sum % 3\n dell = - 1\n flag = 0\n for i in range ( n - 1 ) :\n if ( ( a [ i ] ) % 3 == re ) :\n if ( a [ i + 1 ] > a [ i ] ) :\n dell = i\n flag = 1\n break\n else :\n dell = i\n if ( flag == 0 ) :\n if ( a [ n - 2 ] % 2 == 0 and re == a [ n - 1 ] % 3 ) :\n dell = n - 1\n if ( dell == - 1 ) :\n print ( \"-1\" )\n else :\n print ( dell + 1 )\n\n"
},
{
"id": "python-java-CHECK_IF_X_CAN_GIVE_CHANGE_TO_EVERY_PERSON_IN_THE_QUEUE",
"pair": "python-java",
"Code1": "def isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n",
"Code2": "static int isChangeable ( int notes [ ] , int n ) {\n int fiveCount = 0 ;\n int tenCount = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( notes [ i ] == 5 ) fiveCount ++ ;\n else if ( notes [ i ] == 10 ) {\n if ( fiveCount > 0 ) {\n fiveCount -- ;\n tenCount ++ ;\n }\n else return 0 ;\n }\n else {\n if ( fiveCount > 0 && tenCount > 0 ) {\n fiveCount -- ;\n tenCount -- ;\n }\n else if ( fiveCount >= 3 ) {\n fiveCount -= 3 ;\n }\n else return 0 ;\n }\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isChangeable ( notes , n ) :\n fiveCount = 0\n tenCount = 0\n for i in range ( n ) :\n if ( notes [ i ] == 5 ) :\n fiveCount += 1\n elif ( notes [ i ] == 10 ) :\n if ( fiveCount > 0 ) :\n fiveCount -= 1\n tenCount += 1\n else :\n return 0\n else :\n if ( fiveCount > 0 and tenCount > 0 ) :\n fiveCount -= 1\n tenCount -= 1\n elif ( fiveCount >= 3 ) :\n fiveCount -= 3\n else :\n return 0\n return 1\n\n"
},
{
"id": "python-java-LONGEST_COMMON_SUBSTRING",
"pair": "python-java",
"Code1": "def LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n",
"Code2": "static int LCSubStr ( char X [ ] , char Y [ ] , int m , int n ) {\n int LCStuff [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n int result = 0 ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 || j == 0 ) LCStuff [ i ] [ j ] = 0 ;\n else if ( X [ i - 1 ] == Y [ j - 1 ] ) {\n LCStuff [ i ] [ j ] = LCStuff [ i - 1 ] [ j - 1 ] + 1 ;\n result = Integer . max ( result , LCStuff [ i ] [ j ] ) ;\n }\n else LCStuff [ i ] [ j ] = 0 ;\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef LCSubStr ( X , Y , m , n ) :\n LCSuff = [ [ 0 for k in range ( n + 1 ) ] for l in range ( m + 1 ) ]\n result = 0\n for i in range ( m + 1 ) :\n for j in range ( n + 1 ) :\n if ( i == 0 or j == 0 ) :\n LCSuff [ i ] [ j ] = 0\n elif ( X [ i - 1 ] == Y [ j - 1 ] ) :\n LCSuff [ i ] [ j ] = LCSuff [ i - 1 ] [ j - 1 ] + 1\n result = max ( result , LCSuff [ i ] [ j ] )\n else :\n LCSuff [ i ] [ j ] = 0\n return result\n\n"
},
{
"id": "python-java-MAXIMUM_SUBSEQUENCE_SUM_SUCH_THAT_NO_THREE_ARE_CONSECUTIVE_1",
"pair": "python-java",
"Code1": "def maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n",
"Code2": "static int maxSumWO3Consec ( int n ) {\n if ( sum [ n ] != - 1 ) return sum [ n ] ;\n if ( n == 0 ) return sum [ n ] = 0 ;\n if ( n == 1 ) return sum [ n ] = arr [ 0 ] ;\n if ( n == 2 ) return sum [ n ] = arr [ 1 ] + arr [ 0 ] ;\n return sum [ n ] = Math . max ( Math . max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumWO3Consec ( n ) :\n if ( sum [ n ] != - 1 ) :\n return sum [ n ]\n if ( n == 0 ) :\n sum [ n ] = 0\n return sum [ n ]\n if ( n == 1 ) :\n sum [ n ] = arr [ 0 ]\n return sum [ n ]\n if ( n == 2 ) :\n sum [ n ] = arr [ 1 ] + arr [ 0 ]\n return sum [ n ]\n sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n - 1 ] ) , arr [ n - 2 ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )\n return sum [ n ]\n\n"
},
{
"id": "python-java-FIBONACCI_MODULO_P",
"pair": "python-java",
"Code1": "def findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n",
"Code2": "static int findMinZero ( int p ) {\n int first = 1 , second = 1 , number = 2 , next = 1 ;\n while ( next > 0 ) {\n next = ( first + second ) % p ;\n first = second ;\n second = next ;\n number ++ ;\n }\n return number ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinZero ( p ) :\n first = 1\n second = 1\n number = 2\n next = 1\n while ( next ) :\n next = ( first + second ) % p\n first = second\n second = next\n number = number + 1\n return number\n\n"
},
{
"id": "python-java-REORDER_A_ARRAY_ACCORDING_TO_GIVEN_INDEXES_1",
"pair": "python-java",
"Code1": "def reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n",
"Code2": "static void reorder ( ) {\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n while ( index [ i ] != i ) {\n int oldTargetI = index [ index [ i ] ] ;\n char oldTargetE = ( char ) arr [ index [ i ] ] ;\n arr [ index [ i ] ] = arr [ i ] ;\n index [ index [ i ] ] = index [ i ] ;\n index [ i ] = oldTargetI ;\n arr [ i ] = oldTargetE ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef reorder ( arr , index , n ) :\n for i in range ( 0 , n ) :\n while ( index [ i ] != i ) :\n oldTargetI = index [ index [ i ] ]\n oldTargetE = arr [ index [ i ] ]\n arr [ index [ i ] ] = arr [ i ]\n index [ index [ i ] ] = index [ i ]\n index [ i ] = oldTargetI\n arr [ i ] = oldTargetE\n\n"
},
{
"id": "python-java-LENGTH_LONGEST_SUB_STRING_CAN_MAKE_REMOVED",
"pair": "python-java",
"Code1": "def longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n",
"Code2": "static int longestNull ( String str ) {\n ArrayList < Pair > arr = new ArrayList < > ( ) ;\n arr . add ( new Pair ( ' @ ' , - 1 ) ) ;\n int maxlen = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n ++ i ) {\n arr . add ( new Pair ( str . charAt ( i ) , i ) ) ;\n while ( arr . size ( ) >= 3 && arr . get ( arr . size ( ) - 3 ) . first == ' 1 ' && arr . get ( arr . size ( ) - 2 ) . first == ' 0 ' && arr . get ( arr . size ( ) - 1 ) . first == ' 0 ' ) {\n arr . remove ( arr . size ( ) - 3 ) ;\n arr . remove ( arr . size ( ) - 2 ) ;\n arr . remove ( arr . size ( ) - 1 ) ;\n }\n int tmp = arr . get ( arr . size ( ) - 1 ) . second ;\n maxlen = Math . max ( maxlen , i - tmp ) ;\n }\n return maxlen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestNull ( S ) :\n arr = [ ]\n arr.append ( [ '@' , - 1 ] )\n maxlen = 0\n for i in range ( len ( S ) ) :\n arr.append ( [ S [ i ] , i ] )\n while ( len ( arr ) >= 3 and arr [ len ( arr ) - 3 ] [ 0 ] == '1' and arr [ len ( arr ) - 2 ] [ 0 ] == '0' and arr [ len ( arr ) - 1 ] [ 0 ] == '0' ) :\n arr.pop ( )\n arr.pop ( )\n arr.pop ( )\n tmp = arr [ - 1 ]\n maxlen = max ( maxlen , i - tmp [ 1 ] )\n return maxlen\n\n"
},
{
"id": "python-java-SUM_FIBONACCI_NUMBERS",
"pair": "python-java",
"Code1": "def calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n",
"Code2": "static int calculateSum ( int n ) {\n if ( n <= 0 ) return 0 ;\n int fibo [ ] = new int [ n + 1 ] ;\n fibo [ 0 ] = 0 ;\n fibo [ 1 ] = 1 ;\n int sum = fibo [ 0 ] + fibo [ 1 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ] ;\n sum += fibo [ i ] ;\n }\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef calculateSum ( n ) :\n if ( n <= 0 ) :\n return 0\n fibo = [ 0 ] * ( n + 1 )\n fibo [ 1 ] = 1\n sm = fibo [ 0 ] + fibo [ 1 ]\n for i in range ( 2 , n + 1 ) :\n fibo [ i ] = fibo [ i - 1 ] + fibo [ i - 2 ]\n sm = sm + fibo [ i ]\n return sm\n\n"
},
{
"id": "python-java-SHORTEST_PATH_EXACTLY_K_EDGES_DIRECTED_WEIGHTED_GRAPH",
"pair": "python-java",
"Code1": "def shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n",
"Code2": "int shortestPath ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 0 ;\n if ( k == 1 && graph [ u ] [ v ] != INF ) return graph [ u ] [ v ] ;\n if ( k <= 0 ) return INF ;\n int res = INF ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) {\n if ( graph [ u ] [ i ] != INF && u != i && v != i ) {\n int rec_res = shortestPath ( graph , i , v , k - 1 ) ;\n if ( rec_res != INF ) res = Math . min ( res , graph [ u ] [ i ] + rec_res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef shortestPath ( graph , u , v , k ) :\n V = 4\n INF = 999999999999\n if k == 0 and u == v :\n return 0\n if k == 1 and graph [ u ] [ v ] != INF :\n return graph [ u ] [ v ]\n if k <= 0 :\n return INF\n res = INF\n for i in range ( V ) :\n if graph [ u ] [ i ] != INF and u != i and v != i :\n rec_res = shortestPath ( graph , i , v , k - 1 )\n if rec_res != INF :\n res = min ( res , graph [ u ] [ i ] + rec_res )\n return res\n\n"
},
{
"id": "python-java-SUM_SQUARES_BINOMIAL_COEFFICIENTS",
"pair": "python-java",
"Code1": "def sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n",
"Code2": "static int sumofsquare ( int n ) {\n int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ;\n int i , j ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( j = 0 ;\n j <= min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumofsquare ( n ) :\n C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] )\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] )\n return sum\n\n"
},
{
"id": "python-java-CONSTRUCT_ARRAY_PAIR_SUM_ARRAY",
"pair": "python-java",
"Code1": "def constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n",
"Code2": "static void constructArr ( int arr [ ] , int pair [ ] , int n ) {\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) / 2 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) arr [ i ] = pair [ i - 1 ] - arr [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef constructArr ( arr , pair , n ) :\n arr [ 0 ] = ( pair [ 0 ] + pair [ 1 ] - pair [ n - 1 ] ) // 2\n for i in range ( 1 , n ) :\n arr [ i ] = pair [ i - 1 ] - arr [ 0 ]\n\n"
},
{
"id": "python-java-FIND_PATTERNS_101_GIVEN_STRING",
"pair": "python-java",
"Code1": "def patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n",
"Code2": "static int patternCount ( String str ) {\n char last = str . charAt ( 0 ) ;\n int i = 1 , counter = 0 ;\n while ( i < str . length ( ) ) {\n if ( str . charAt ( i ) == ' 0 ' && last == ' 1 ' ) {\n while ( str . charAt ( i ) == ' 0 ' ) i ++ ;\n if ( str . charAt ( i ) == ' 1 ' ) counter ++ ;\n }\n last = str . charAt ( i ) ;\n i ++ ;\n }\n return counter ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef patternCount ( str ) :\n last = str [ 0 ]\n i = 1 counter = 0\n while ( i < len ( str ) ) :\n if ( str [ i ] == '0' and last == '1' ) :\n while ( str [ i ] == '0' ) :\n i += 1\n if ( str [ i ] == '1' ) :\n counter += 1\n last = str [ i ]\n i += 1\n return counter\n\n"
},
{
"id": "python-java-RANGE_QUERIES_FOR_FREQUENCIES_OF_ARRAY_ELEMENTS",
"pair": "python-java",
"Code1": "def findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n",
"Code2": "public static int findFrequency ( int arr [ ] , int n , int left , int right , int element ) {\n int count = 0 ;\n for ( int i = left - 1 ;\n i < right ;\n ++ i ) if ( arr [ i ] == element ) ++ count ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findFrequency ( arr , n , left , right , element ) :\n count = 0\n for i in range ( left - 1 , right ) :\n if ( arr [ i ] == element ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-FINDING_VERTEX_FOCUS_DIRECTRIX_PARABOLA",
"pair": "python-java",
"Code1": "def parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n",
"Code2": "static void parabola ( float a , float b , float c ) {\n System . out . println ( \"Vertex: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Focus: (\" + ( - b / ( 2 * a ) ) + \", \" + ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) + \")\" ) ;\n System . out . println ( \"Directrix:\" + \" y=\" + ( int ) ( c - ( ( b * b ) + 1 ) * 4 * a ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef parabola ( a , b , c ) :\n print ( \"Vertex: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Focus: (\" , ( - b / ( 2 * a ) ) , \", \" , ( ( ( 4 * a * c ) - ( b * b ) + 1 ) / ( 4 * a ) ) , \")\" , sep = \"\" )\n print ( \"Directrix: y=\" , c - ( ( b * b ) + 1 ) * 4 * a , sep = \"\" )\n\n"
},
{
"id": "python-java-MINIMUM_SUM_PRODUCT_TWO_ARRAYS",
"pair": "python-java",
"Code1": "def minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n",
"Code2": "static int minproduct ( int a [ ] , int b [ ] , int n , int k ) {\n int diff = 0 , res = 0 ;\n int temp = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int pro = a [ i ] * b [ i ] ;\n res = res + pro ;\n if ( pro < 0 && b [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro < 0 && a [ i ] < 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] < 0 ) temp = ( a [ i ] + 2 * k ) * b [ i ] ;\n else if ( pro > 0 && a [ i ] > 0 ) temp = ( a [ i ] - 2 * k ) * b [ i ] ;\n int d = Math . abs ( pro - temp ) ;\n if ( d > diff ) diff = d ;\n }\n return res - diff ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minproduct ( a , b , n , k ) :\n diff = 0\n res = 0\n for i in range ( n ) :\n pro = a [ i ] * b [ i ]\n res = res + pro\n if ( pro < 0 and b [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro < 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] < 0 ) :\n temp = ( a [ i ] + 2 * k ) * b [ i ]\n elif ( pro > 0 and a [ i ] > 0 ) :\n temp = ( a [ i ] - 2 * k ) * b [ i ]\n d = abs ( pro - temp )\n if ( d > diff ) :\n diff = d\n return res - diff\n\n"
},
{
"id": "python-java-LONGEST_SUBSEQUENCE_WHERE_EVERY_CHARACTER_APPEARS_AT_LEAST_K_TIMES",
"pair": "python-java",
"Code1": "def longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n",
"Code2": "static void longestSubseqWithK ( String str , int k ) {\n int n = str . length ( ) ;\n int freq [ ] = new int [ MAX_CHARS ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n freq [ str . charAt ( i ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( freq [ str . charAt ( i ) - ' a ' ] >= k ) {\n System . out . print ( str . charAt ( i ) ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longestSubseqWithK ( str , k ) :\n n = len ( str )\n freq = [ 0 ] * MAX_CHARS\n for i in range ( n ) :\n freq [ ord ( str [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( n ) :\n if ( freq [ ord ( str [ i ] ) - ord ( 'a' ) ] >= k ) :\n print ( str [ i ] , end = \"\" )\n\n"
},
{
"id": "python-java-GIVEN_A_SORTED_AND_ROTATED_ARRAY_FIND_IF_THERE_IS_A_PAIR_WITH_A_GIVEN_SUM_1",
"pair": "python-java",
"Code1": "def pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n",
"Code2": "static int pairsInSortedRotated ( int arr [ ] , int n , int x ) {\n int i ;\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ;\n int l = ( i + 1 ) % n ;\n int r = i ;\n int cnt = 0 ;\n while ( l != r ) {\n if ( arr [ l ] + arr [ r ] == x ) {\n cnt ++ ;\n if ( l == ( r - 1 + n ) % n ) {\n return cnt ;\n }\n l = ( l + 1 ) % n ;\n r = ( r - 1 + n ) % n ;\n }\n else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ;\n else r = ( n + r - 1 ) % n ;\n }\n return cnt ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef pairsInSortedRotated ( arr , n , x ) :\n for i in range ( n ) :\n if arr [ i ] > arr [ i + 1 ] :\n break\n l = ( i + 1 ) % n\n r = i\n cnt = 0\n while ( l != r ) :\n if arr [ l ] + arr [ r ] == x :\n cnt += 1\n if l == ( r - 1 + n ) % n :\n return cnt\n l = ( l + 1 ) % n\n r = ( r - 1 + n ) % n\n elif arr [ l ] + arr [ r ] < x :\n l = ( l + 1 ) % n\n else :\n r = ( n + r - 1 ) % n\n return cnt\n\n"
},
{
"id": "python-java-MIDDLE_OF_THREE_USING_MINIMUM_COMPARISONS_2",
"pair": "python-java",
"Code1": "def middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n",
"Code2": "public static int middleOfThree ( int a , int b , int c ) {\n int x = a - b ;\n int y = b - c ;\n int z = a - c ;\n if ( x * y > 0 ) return b ;\n else if ( x * z > 0 ) return c ;\n else return a ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef middleOfThree ( a , b , c ) :\n x = a - b\n y = b - c\n z = a - c\n if x * y > 0 :\n return b\n elif ( x * z > 0 ) :\n return\n else :\n return a\n\n"
},
{
"id": "python-java-NEXT_POWER_OF_2",
"pair": "python-java",
"Code1": "def nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n int count = 0 ;\n if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ;\n while ( n != 0 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return 1 << count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n count = 0\n if ( n and not ( n & ( n - 1 ) ) ) :\n return n\n while ( n != 0 ) :\n n >>= 1\n count += 1\n return 1 << count\n\n"
},
{
"id": "python-java-MAXIMUM_SUBARRAY_SUM_ARRAY_CREATED_REPEATED_CONCATENATION",
"pair": "python-java",
"Code1": "def maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n",
"Code2": "static int maxSubArraySumRepeated ( int a [ ] , int n , int k ) {\n int max_so_far = 0 ;\n int INT_MIN , max_ending_here = 0 ;\n for ( int i = 0 ;\n i < n * k ;\n i ++ ) {\n max_ending_here = max_ending_here + a [ i % n ] ;\n if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ;\n if ( max_ending_here < 0 ) max_ending_here = 0 ;\n }\n return max_so_far ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSubArraySumRepeated ( a , n , k ) :\n max_so_far = - 2147483648\n max_ending_here = 0\n for i in range ( n * k ) :\n max_ending_here = max_ending_here + a [ i % n ]\n if ( max_so_far < max_ending_here ) :\n max_so_far = max_ending_here\n if ( max_ending_here < 0 ) :\n max_ending_here = 0\n return max_so_far\n\n"
},
{
"id": "python-java-STACK_SET_3_REVERSE_STRING_USING_STACK",
"pair": "python-java",
"Code1": "def reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n",
"Code2": "static void reverse ( char str [ ] ) {\n int n = str . length , i ;\n for ( i = 0 ;\n i < n / 2 ;\n i ++ ) {\n swap ( str , i , n - i - 1 ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef reverse ( string ) :\n string = string [ : : - 1 ]\n return string\n\n"
},
{
"id": "python-java-LEXICOGRAPHICALLY_NEXT_STRING",
"pair": "python-java",
"Code1": "def nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n",
"Code2": "public static String nextWord ( String str ) {\n if ( str == \"\" ) return \"a\" ;\n int i = str . length ( ) - 1 ;\n while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ;\n if ( i == - 1 ) str = str + ' a ' ;\n else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextWord ( s ) :\n if ( s == \" \" ) :\n return \"a\"\n i = len ( s ) - 1\n while ( s [ i ] == 'z' and i >= 0 ) :\n i -= 1\n if ( i == - 1 ) :\n s = s + 'a'\n else :\n s = s.replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 )\n return s\n\n"
},
{
"id": "python-java-SUM_BINOMIAL_COEFFICIENTS",
"pair": "python-java",
"Code1": "def binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n",
"Code2": "static int binomialCoeffSum ( int n ) {\n int C [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= Math . min ( i , n ) ;\n j ++ ) {\n if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ;\n else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ;\n }\n }\n int sum = 0 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) sum += C [ n ] [ i ] ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binomialCoeffSum ( n ) :\n C = [ [ 0 ] * ( n + 2 ) for i in range ( 0 , n + 2 ) ]\n for i in range ( 0 , n + 1 ) :\n for j in range ( 0 , min ( i , n ) + 1 ) :\n if ( j == 0 or j == i ) :\n C [ i ] [ j ] = 1\n else :\n C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]\n sum = 0\n for i in range ( 0 , n + 1 ) :\n sum += C [ n ] [ i ]\n return sum\n\n"
},
{
"id": "python-java-CHECK_WHETHER_GIVEN_NUMBER_EVEN_ODD",
"pair": "python-java",
"Code1": "def isEven ( n ) :\n return ( n % 2 == 0 )\n",
"Code2": "public static boolean isEven ( int n ) {\n return ( n % 2 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isEven ( n ) :\n return ( n % 2 == 0 )\n\n"
},
{
"id": "python-java-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n",
"Code2": "static int binarySearch ( int arr [ ] , int low , int high , int key ) {\n if ( high < low ) return - 1 ;\n int mid = ( low + high ) / 2 ;\n if ( key == arr [ mid ] ) return mid ;\n if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ;\n return binarySearch ( arr , low , ( mid - 1 ) , key ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , low , high , key ) :\n if ( high < low ) :\n return - 1\n mid = ( low + high ) / 2\n if ( key == arr [ int ( mid ) ] ) :\n return mid\n if ( key > arr [ int ( mid ) ] ) :\n return binarySearch ( arr , ( mid + 1 ) , high , key )\n return ( binarySearch ( arr , low , ( mid - 1 ) , key ) )\n\n"
},
{
"id": "python-java-MAXIMUM_AND_MINIMUM_IN_A_SQUARE_MATRIX",
"pair": "python-java",
"Code1": "def MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n",
"Code2": "static void maxMin ( int arr [ ] [ ] , int n ) {\n int min = + 2147483647 ;\n int max = - 2147483648 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n / 2 ;\n j ++ ) {\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) {\n if ( min > arr [ i ] [ n - j - 1 ] ) min = arr [ i ] [ n - j - 1 ] ;\n if ( max < arr [ i ] [ j ] ) max = arr [ i ] [ j ] ;\n }\n else {\n if ( min > arr [ i ] [ j ] ) min = arr [ i ] [ j ] ;\n if ( max < arr [ i ] [ n - j - 1 ] ) max = arr [ i ] [ n - j - 1 ] ;\n }\n }\n }\n System . out . print ( \"Maximum = \" + max + \", Minimum = \" + min ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MAXMIN ( arr , n ) :\n MIN = 10 ** 9\n MAX = - 10 ** 9\n for i in range ( n ) :\n for j in range ( n // 2 + 1 ) :\n if ( arr [ i ] [ j ] > arr [ i ] [ n - j - 1 ] ) :\n if ( MIN > arr [ i ] [ n - j - 1 ] ) :\n MIN = arr [ i ] [ n - j - 1 ]\n if ( MAX < arr [ i ] [ j ] ) :\n MAX = arr [ i ] [ j ]\n else :\n if ( MIN > arr [ i ] [ j ] ) :\n MIN = arr [ i ] [ j ]\n if ( MAX < arr [ i ] [ n - j - 1 ] ) :\n MAX = arr [ i ] [ n - j - 1 ]\n print ( \"MAXimum =\" , MAX , \", MINimum =\" , MIN )\n\n"
},
{
"id": "python-java-WRITE_ONE_LINE_C_FUNCTION_TO_FIND_WHETHER_A_NO_IS_POWER_OF_TWO_1",
"pair": "python-java",
"Code1": "def isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n",
"Code2": "static boolean isPowerOfTwo ( int x ) {\n return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPowerOfTwo ( x ) :\n return ( x and ( not ( x & ( x - 1 ) ) ) )\n\n"
},
{
"id": "python-java-COUNTS_PATHS_POINT_REACH_ORIGIN",
"pair": "python-java",
"Code1": "def countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n",
"Code2": "static int countPaths ( int n , int m ) {\n if ( n == 0 || m == 0 ) return 1 ;\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPaths ( n , m ) :\n if ( n == 0 or m == 0 ) :\n return 1\n return ( countPaths ( n - 1 , m ) + countPaths ( n , m - 1 ) )\n\n"
},
{
"id": "python-java-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1_1",
"pair": "python-java",
"Code1": "def isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n",
"Code2": "static boolean isRectangle ( int matrix [ ] [ ] ) {\n int rows = matrix . length ;\n if ( rows == 0 ) return false ;\n int columns = matrix [ 0 ] . length ;\n HashMap < Integer , HashSet < Integer >> table = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < rows ;\n i ++ ) {\n for ( int j = 0 ;\n j < columns - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < columns ;\n k ++ ) {\n if ( matrix [ i ] [ j ] == 1 && matrix [ i ] [ k ] == 1 ) {\n if ( table . containsKey ( j ) && table . get ( j ) . contains ( k ) ) {\n return true ;\n }\n if ( table . containsKey ( k ) && table . get ( k ) . contains ( j ) ) {\n return true ;\n }\n if ( ! table . containsKey ( j ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( k ) ;\n table . put ( j , x ) ;\n }\n else {\n table . get ( j ) . add ( k ) ;\n }\n if ( ! table . containsKey ( k ) ) {\n HashSet < Integer > x = new HashSet < > ( ) ;\n x . add ( j ) ;\n table . put ( k , x ) ;\n }\n else {\n table . get ( k ) . add ( j ) ;\n }\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isRectangle ( matrix ) :\n rows = len ( matrix )\n if ( rows == 0 ) :\n return False\n columns = len ( matrix [ 0 ] )\n table = { }\n for i in range ( rows ) :\n for j in range ( columns - 1 ) :\n for k in range ( j + 1 , columns ) :\n if ( matrix [ i ] [ j ] == 1 and matrix [ i ] [ k ] == 1 ) :\n if ( j in table and k in table [ j ] ) :\n return True\n if ( k in table and j in table [ k ] ) :\n return True\n if j not in table :\n table [ j ] = set ( )\n if k not in table :\n table [ k ] = set ( )\n table [ j ].add ( k )\n table [ k ].add ( j )\n return False\n\n"
},
{
"id": "python-java-PROGRAM_DECIMAL_BINARY_CONVERSION",
"pair": "python-java",
"Code1": "def decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n",
"Code2": "static void decToBinary ( int n ) {\n int [ ] binaryNum = new int [ 32 ] ;\n int i = 0 ;\n while ( n > 0 ) {\n binaryNum [ i ] = n % 2 ;\n n = n / 2 ;\n i ++ ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( binaryNum [ j ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decToBinary ( n ) :\n binaryNum = [ 0 ] * n\n i = 0\n while ( n > 0 ) :\n binaryNum [ i ] = n % 2\n n = int ( n / 2 )\n i += 1\n for j in range ( i - 1 , - 1 , - 1 ) :\n print ( binaryNum [ j ] , end = \"\" )\n\n"
},
{
"id": "python-java-FRIENDS_PAIRING_PROBLEM_1",
"pair": "python-java",
"Code1": "def countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n",
"Code2": "static int countFriendsPairings ( int n ) {\n if ( dp [ n ] != - 1 ) return dp [ n ] ;\n if ( n > 2 ) return dp [ n ] = countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) ;\n else return dp [ n ] = n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countFriendsPairings ( n ) :\n dp = [ - 1 ] * 100\n if ( dp [ n ] != - 1 ) :\n return dp [ n ]\n if ( n > 2 ) :\n dp [ n ] = ( countFriendsPairings ( n - 1 ) + ( n - 1 ) * countFriendsPairings ( n - 2 ) )\n return dp [ n ]\n else :\n dp [ n ] = n\n return dp [ n ]\n\n"
},
{
"id": "python-java-MAXIMUM_SUBARRAY_SUM_USING_PREFIX_SUM",
"pair": "python-java",
"Code1": "def maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n",
"Code2": "static int maximumSumSubarray ( int arr [ ] , int n ) {\n int min_prefix_sum = 0 ;\n int res = Integer . MIN_VALUE ;\n int prefix_sum [ ] = new int [ n ] ;\n prefix_sum [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n res = Math . max ( res , prefix_sum [ i ] - min_prefix_sum ) ;\n min_prefix_sum = Math . min ( min_prefix_sum , prefix_sum [ i ] ) ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumSumSubarray ( arr , n ) :\n min_prefix_sum = 0\n res = - math.inf\n prefix_sum = [ ]\n prefix_sum.append ( arr [ 0 ] )\n for i in range ( 1 , n ) :\n prefix_sum.append ( prefix_sum [ i - 1 ] + arr [ i ] )\n for i in range ( n ) :\n res = max ( res , prefix_sum [ i ] - min_prefix_sum )\n min_prefix_sum = min ( min_prefix_sum , prefix_sum [ i ] )\n return res\n\n"
},
{
"id": "python-java-NUMBER_SUBSEQUENCES_AB_STRING_REPEATED_K_TIMES",
"pair": "python-java",
"Code1": "def countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n",
"Code2": "static int countOccurrences ( String s , int K ) {\n int n = s . length ( ) ;\n int C = 0 , c1 = 0 , c2 = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( s . charAt ( i ) == ' a ' ) c1 ++ ;\n if ( s . charAt ( i ) == ' b ' ) {\n c2 ++ ;\n C += c1 ;\n }\n }\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countOccurrences ( s , K ) :\n n = len ( s )\n c1 = 0\n c2 = 0\n C = 0\n for i in range ( n ) :\n if s [ i ] == 'a' :\n c1 += 1\n if s [ i ] == 'b' :\n c2 += 1\n C += c1\n return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2\n\n"
},
{
"id": "python-java-CHECK_LARGE_NUMBER_DIVISIBLE_13_NOT",
"pair": "python-java",
"Code1": "def checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n",
"Code2": "static boolean checkDivisibility ( String num ) {\n int length = num . length ( ) ;\n if ( length == 1 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( length % 3 == 1 ) {\n num += \"00\" ;\n length += 2 ;\n }\n else if ( length % 3 == 2 ) {\n num += \"0\" ;\n length += 1 ;\n }\n int sum = 0 , p = 1 ;\n for ( int i = length - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n sum = sum + group * p ;\n p *= ( - 1 ) ;\n }\n sum = Math . abs ( sum ) ;\n return ( sum % 13 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkDivisibility ( num ) :\n length = len ( num )\n if ( length == 1 and num [ 0 ] == '0' ) :\n return True\n if ( length % 3 == 1 ) :\n num = str ( num ) + \"00\"\n length += 2\n elif ( length % 3 == 2 ) :\n num = str ( num ) + \"0\"\n length += 1\n sum = 0\n p = 1\n for i in range ( length - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n sum = sum + group * p\n p *= ( - 1 )\n sum = abs ( sum )\n return ( sum % 13 == 0 )\n\n"
},
{
"id": "python-java-NUMBER_UNIQUE_RECTANGLES_FORMED_USING_N_UNIT_SQUARES",
"pair": "python-java",
"Code1": "def countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n",
"Code2": "static int countRect ( int n ) {\n int ans = 0 ;\n for ( int length = 1 ;\n length <= Math . sqrt ( n ) ;\n ++ length ) for ( int height = length ;\n height * length <= n ;\n ++ height ) ans ++ ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countRect ( n ) :\n ans = 0\n for length in range ( 1 , int ( math.sqrt ( n ) ) + 1 ) :\n height = length\n while ( height * length <= n ) :\n ans += 1\n height += 1\n return ans\n\n"
},
{
"id": "python-java-COUNT_SET_BITS_IN_AN_INTEGER_2",
"pair": "python-java",
"Code1": "def countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n",
"Code2": "static int countSetBits ( int n ) {\n int count = 0 ;\n while ( n > 0 ) {\n n &= ( n - 1 ) ;\n count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSetBits ( n ) :\n count = 0\n while ( n ) :\n n &= ( n - 1 )\n count += 1\n return count\n\n"
},
{
"id": "python-java-LONGEST_SUBARRAY_COUNT_1S_ONE_COUNT_0S",
"pair": "python-java",
"Code1": "def lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n",
"Code2": "static int lenOfLongSubarr ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ;\n int sum = 0 , maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum += arr [ i ] == 0 ? - 1 : 1 ;\n if ( sum == 1 ) maxLen = i + 1 ;\n else if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ;\n if ( um . containsKey ( sum - 1 ) ) {\n if ( maxLen < ( i - um . get ( sum - 1 ) ) ) maxLen = i - um . get ( sum - 1 ) ;\n }\n }\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lenOfLongSubarr ( arr , n ) :\n um = { i : 0 for i in range ( 10 ) }\n sum = 0\n maxLen = 0\n for i in range ( n ) :\n if arr [ i ] == 0 :\n sum += - 1\n else :\n sum += 1\n if ( sum == 1 ) :\n maxLen = i + 1\n elif ( sum not in um ) :\n um [ sum ] = i\n if ( ( sum - 1 ) in um ) :\n if ( maxLen < ( i - um [ sum - 1 ] ) ) :\n maxLen = i - um [ sum - 1 ]\n return maxLen\n\n"
},
{
"id": "python-java-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER_1",
"pair": "python-java",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "static int factorial ( int n ) {\n int res = 1 , i ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) res *= i ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_OF_JUMPS_TO_REACH_END_OF_A_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n",
"Code2": "static int minJumps ( int arr [ ] , int l , int h ) {\n if ( h == l ) return 0 ;\n if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ;\n int min = Integer . MAX_VALUE ;\n for ( int i = l + 1 ;\n i <= h && i <= l + arr [ l ] ;\n i ++ ) {\n int jumps = minJumps ( arr , i , h ) ;\n if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ;\n }\n return min ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minJumps ( arr , l , h ) :\n if ( h == l ) :\n return 0\n if ( arr [ l ] == 0 ) :\n return float ( 'inf' )\n min = float ( 'inf' )\n for i in range ( l + 1 , h + 1 ) :\n if ( i < l + arr [ l ] + 1 ) :\n jumps = minJumps ( arr , i , h )\n if ( jumps != float ( 'inf' ) and jumps + 1 < min ) :\n min = jumps + 1\n return min\n\n"
},
{
"id": "python-java-MINIMUM_TIME_WRITE_CHARACTERS_USING_INSERT_DELETE_COPY_OPERATION",
"pair": "python-java",
"Code1": "def minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n",
"Code2": "static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) {\n if ( N == 0 ) return 0 ;\n if ( N == 1 ) return insert ;\n int dp [ ] = new int [ N + 1 ] ;\n for ( int i = 1 ;\n i <= N ;\n i ++ ) {\n if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ;\n else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ;\n }\n return dp [ N ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minTimeForWritingChars ( N , insrt , remov , cpy ) :\n if N == 0 :\n return 0\n if N == 1 :\n return insrt\n dp = [ 0 ] * ( N + 1 )\n for i in range ( 1 , N + 1 ) :\n if i % 2 == 0 :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ i // 2 ] + cpy )\n else :\n dp [ i ] = min ( dp [ i - 1 ] + insrt , dp [ ( i + 1 ) // 2 ] + cpy + remov )\n return dp [ N ]\n\n"
},
{
"id": "python-java-PRINTING_STRING_PLUS_PATTERN_MATRIX",
"pair": "python-java",
"Code1": "def carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "static void carveCross ( String str ) {\n int n = str . length ( ) ;\n if ( n % 2 == 0 ) {\n System . out . print ( \"Not possible. Please enter \" + \"odd length string.\\n\" ) ;\n }\n else {\n char arr [ ] [ ] = new char [ max ] [ max ] ;\n int m = n / 2 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n arr [ i ] [ j ] = ' X ' ;\n }\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] [ m ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ m ] [ i ] = str . charAt ( i ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) {\n System . out . print ( arr [ i ] [ j ] + \" \" ) ;\n }\n System . out . print ( \"\\n\" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef carveCross ( str ) :\n n = len ( str )\n if ( n % 2 == 0 ) :\n print ( \"Not possible.Please enter \" , \"odd length string.\\n\" )\n else :\n arr = [ [ False for x in range ( max ) ] for y in range ( max ) ]\n m = n // 2\n for i in range ( n ) :\n for j in range ( n ) :\n arr [ i ] [ j ] = 'X'\n for i in range ( n ) :\n arr [ i ] [ m ] = str [ i ]\n for i in range ( n ) :\n arr [ m ] [ i ] = str [ i ]\n for i in range ( n ) :\n for j in range ( n ) :\n print ( arr [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-SUBARRAYS_DISTINCT_ELEMENTS",
"pair": "python-java",
"Code1": "def sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n",
"Code2": "public static int sumoflength ( int [ ] arr , int n ) {\n Set < Integer > s = new HashSet < > ( ) ;\n int j = 0 , ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n while ( j < n && ! s . contains ( arr [ j ] ) ) {\n s . add ( arr [ i ] ) ;\n j ++ ;\n }\n ans += ( ( j - i ) * ( j - i + 1 ) ) / 2 ;\n s . remove ( arr [ i ] ) ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumoflength ( arr , n ) :\n s = [ ]\n j = 0\n ans = 0\n for i in range ( n ) :\n while ( j < n and ( arr [ j ] not in s ) ) :\n s.append ( arr [ j ] )\n j += 1\n ans += ( ( j - i ) * ( j - i + 1 ) ) // 2\n s.remove ( arr [ i ] )\n return ans\n\n"
},
{
"id": "python-java-FIND_TRIPLETS_ARRAY_WHOSE_SUM_EQUAL_ZERO_1",
"pair": "python-java",
"Code1": "def findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n",
"Code2": "static void findTriplets ( int arr [ ] , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int x = - ( arr [ i ] + arr [ j ] ) ;\n if ( s . contains ( x ) ) {\n System . out . printf ( \"%d %d %d\\n\" , x , arr [ i ] , arr [ j ] ) ;\n found = true ;\n }\n else {\n s . add ( arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) {\n System . out . printf ( \" No Triplet Found\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findTriplets ( arr , n ) :\n found = False\n for i in range ( n - 1 ) :\n s = set ( )\n for j in range ( i + 1 , n ) :\n x = - ( arr [ i ] + arr [ j ] )\n if x in s :\n print ( x , arr [ i ] , arr [ j ] )\n found = True\n else :\n s.add ( arr [ j ] )\n if found == False :\n print ( \"No Triplet Found\" )\n\n"
},
{
"id": "python-java-MAXIMUM_LENGTH_PREFIX_ONE_STRING_OCCURS_SUBSEQUENCE_ANOTHER",
"pair": "python-java",
"Code1": "def maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n",
"Code2": "static int maxPrefix ( String s , String t ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < t . length ( ) ;\n i ++ ) {\n if ( count == t . length ( ) ) break ;\n if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxPrefix ( s , t ) :\n count = 0\n for i in range ( 0 , len ( t ) ) :\n if ( count == len ( s ) ) :\n break\n if ( t [ i ] == s [ count ] ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-MOVE_VE_ELEMENTS_END_ORDER_EXTRA_SPACE_ALLOWED",
"pair": "python-java",
"Code1": "def segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n",
"Code2": "static void segregateElements ( int arr [ ] , int n ) {\n int temp [ ] = new int [ n ] ;\n int j = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] >= 0 ) temp [ j ++ ] = arr [ i ] ;\n if ( j == n || j == 0 ) return ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( arr [ i ] < 0 ) temp [ j ++ ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = temp [ i ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef segregateElements ( arr , n ) :\n temp = [ 0 for k in range ( n ) ]\n j = 0\n for i in range ( n ) :\n if ( arr [ i ] >= 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n if ( j == n or j == 0 ) :\n return\n for i in range ( n ) :\n if ( arr [ i ] < 0 ) :\n temp [ j ] = arr [ i ]\n j += 1\n for k in range ( n ) :\n arr [ k ] = temp [ k ]\n\n"
},
{
"id": "python-java-MERGING_INTERVALS",
"pair": "python-java",
"Code1": "def mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n",
"Code2": "public static void mergeIntervals ( Interval arr [ ] ) {\n Arrays . sort ( arr , new Comparator < Interval > ( ) {\n public int compare ( Interval i1 , Interval i2 ) {\n return i2 . start - i1 . start ;\n }\n }\n ) ;\n int index = 0 ;\n for ( int i = 1 ;\n i < arr . length ;\n i ++ ) {\n if ( arr [ index ] . end >= arr [ i ] . start ) {\n arr [ index ] . end = Math . max ( arr [ index ] . end , arr [ i ] . end ) ;\n arr [ index ] . start = Math . min ( arr [ index ] . start , arr [ i ] . start ) ;\n }\n else {\n arr [ index ] = arr [ i ] ;\n index ++ ;\n }\n }\n System . out . print ( \"The Merged Intervals are: \" ) ;\n for ( int i = 0 ;\n i <= index ;\n i ++ ) {\n System . out . print ( \"[\" + arr [ i ] . start + \",\" + arr [ i ] . end + \"]\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef mergeIntervals ( arr ) :\n arr.sort ( key = lambda x : x [ 0 ] )\n m = [ ]\n s = - 10000\n max = - 100000\n for i in range ( len ( arr ) ) :\n a = arr [ i ]\n if a [ 0 ] > max :\n if i != 0 :\n m.append ( [ s , max ] )\n max = a [ 1 ]\n s = a [ 0 ]\n else :\n if a [ 1 ] >= max :\n max = a [ 1 ]\n if max != - 100000 and [ s , max ] not in m :\n m.append ( [ s , max ] )\n print ( \"The Merged Intervals are :\" , end = \" \" )\n for i in range ( len ( m ) ) :\n print ( m [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-PROGRAM_FIND_CORRELATION_COEFFICIENT",
"pair": "python-java",
"Code1": "def correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n",
"Code2": "static float correlationCoefficient ( int X [ ] , int Y [ ] , int n ) {\n int sum_X = 0 , sum_Y = 0 , sum_XY = 0 ;\n int squareSum_X = 0 , squareSum_Y = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n sum_X = sum_X + X [ i ] ;\n sum_Y = sum_Y + Y [ i ] ;\n sum_XY = sum_XY + X [ i ] * Y [ i ] ;\n squareSum_X = squareSum_X + X [ i ] * X [ i ] ;\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ] ;\n }\n float corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) / ( float ) ( Math . sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) ) ;\n return corr ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef correlationCoefficient ( X , Y , n ) :\n sum_X = 0\n sum_Y = 0\n sum_XY = 0\n squareSum_X = 0\n squareSum_Y = 0\n i = 0\n while i < n :\n sum_X = sum_X + X [ i ]\n sum_Y = sum_Y + Y [ i ]\n sum_XY = sum_XY + X [ i ] * Y [ i ]\n squareSum_X = squareSum_X + X [ i ] * X [ i ]\n squareSum_Y = squareSum_Y + Y [ i ] * Y [ i ]\n i = i + 1\n corr = ( float ) ( n * sum_XY - sum_X * sum_Y ) /\n ( float ) ( math.sqrt ( ( n * squareSum_X - sum_X * sum_X ) * ( n * squareSum_Y - sum_Y * sum_Y ) ) )\n return corr\n\n"
},
{
"id": "python-java-MAXIMUM_AREA_RECTANGLE_PICKING_FOUR_SIDES_ARRAY",
"pair": "python-java",
"Code1": "def findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n",
"Code2": "static int findArea ( Integer arr [ ] , int n ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n int [ ] dimension = {\n 0 , 0 }\n ;\n for ( int i = 0 , j = 0 ;\n i < n - 1 && j < 2 ;\n i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ;\n return ( dimension [ 0 ] * dimension [ 1 ] ) ;\n }\n ",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findArea ( arr , n ) :\n arr.sort ( reverse = True )\n dimension = [ 0 , 0 ]\n i = 0\n j = 0\n while ( i < n - 1 and j < 2 ) :\n if ( arr [ i ] == arr [ i + 1 ] ) :\n dimension [ j ] = arr [ i ]\n j += 1\n i += 1\n i += 1\n return ( dimension [ 0 ] * dimension [ 1 ] )\n\n"
},
{
"id": "python-java-MINIMUM_INCREMENT_K_OPERATIONS_MAKE_ELEMENTS_EQUAL",
"pair": "python-java",
"Code1": "def minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n",
"Code2": "static int minOps ( int arr [ ] , int n , int k ) {\n Arrays . sort ( arr ) ;\n int max = arr [ arr . length - 1 ] ;\n int res = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ( max - arr [ i ] ) % k != 0 ) return - 1 ;\n else res += ( max - arr [ i ] ) / k ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minOps ( arr , n , k ) :\n max1 = max ( arr )\n res = 0\n for i in range ( 0 , n ) :\n if ( ( max1 - arr [ i ] ) % k != 0 ) :\n return - 1\n else :\n res += ( max1 - arr [ i ] ) / k\n return int ( res )\n\n"
},
{
"id": "python-java-SQUARE_ROOT_OF_AN_INTEGER",
"pair": "python-java",
"Code1": "def floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n",
"Code2": "static int floorSqrt ( int x ) {\n if ( x == 0 || x == 1 ) return x ;\n int i = 1 , result = 1 ;\n while ( result <= x ) {\n i ++ ;\n result = i * i ;\n }\n return i - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef floorSqrt ( x ) :\n if ( x == 0 or x == 1 ) :\n return x\n i = 1 result = 1\n while ( result <= x ) :\n i += 1\n result = i * i\n return i - 1\n\n"
},
{
"id": "python-java-CHECK_WHETHER_LARGE_NUMBER_DIVISIBLE_7",
"pair": "python-java",
"Code1": "def isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n",
"Code2": "static boolean isDivisible7 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n n = num . length ( ) ;\n int gSum = 0 , p = 1 ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n int group = 0 ;\n group += num . charAt ( i -- ) - ' 0 ' ;\n group += ( num . charAt ( i -- ) - ' 0 ' ) * 10 ;\n group += ( num . charAt ( i ) - ' 0 ' ) * 100 ;\n gSum = gSum + group * p ;\n p = p * - 1 ;\n }\n return ( gSum % 7 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isdivisible7 ( num ) :\n n = len ( num )\n if ( n == 0 and num [ 0 ] == '\\n' ) :\n return 1\n if ( n % 3 == 1 ) :\n num = str ( num ) + \"00\"\n n += 2\n elif ( n % 3 == 2 ) :\n num = str ( num ) + \"0\"\n n += 1\n GSum = 0\n p = 1\n for i in range ( n - 1 , - 1 , - 1 ) :\n group = 0\n group += ord ( num [ i ] ) - ord ( '0' )\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 10\n i -= 1\n group += ( ord ( num [ i ] ) - ord ( '0' ) ) * 100\n GSum = GSum + group * p\n p *= ( - 1 )\n return ( GSum % 7 == 0 )\n\n"
},
{
"id": "python-java-CONSTRUCT_GRAPH_GIVEN_DEGREES_VERTICES",
"pair": "python-java",
"Code1": "def printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n",
"Code2": "static void printMat ( int degseq [ ] , int n ) {\n int [ ] [ ] mat = new int [ n ] [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( degseq [ i ] > 0 && degseq [ j ] > 0 ) {\n degseq [ i ] -- ;\n degseq [ j ] -- ;\n mat [ i ] [ j ] = 1 ;\n mat [ j ] [ i ] = 1 ;\n }\n }\n }\n System . out . print ( \"\\n\" + setw ( 3 ) + \" \" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( setw ( 3 ) + \"(\" + i + \")\" ) ;\n System . out . print ( \"\\n\\n\" ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( setw ( 4 ) + \"(\" + i + \")\" ) ;\n for ( int j = 0 ;\n j < n ;\n j ++ ) System . out . print ( setw ( 5 ) + mat [ i ] [ j ] ) ;\n System . out . print ( \"\\n\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printMat ( degseq , n ) :\n mat = [ [ 0 ] * n for i in range ( n ) ]\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) :\n degseq [ i ] -= 1\n degseq [ j ] -= 1\n mat [ i ] [ j ] = 1\n mat [ j ] [ i ] = 1\n print ( \" \" , end = \"\" )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n print ( )\n print ( )\n for i in range ( n ) :\n print ( \"\" , \"(\" , i , \")\" , end = \"\" )\n for j in range ( n ) :\n print ( \" \" , mat [ i ] [ j ] , end = \"\" )\n print ( )\n\n"
},
{
"id": "python-java-MINIMUM_TIME_REQUIRED_PRODUCE_M_ITEMS",
"pair": "python-java",
"Code1": "def minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n",
"Code2": "static int minTime ( int [ ] arr , int n , int m ) {\n int t = 0 ;\n while ( true ) {\n int items = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) items += ( t / arr [ i ] ) ;\n if ( items >= m ) return t ;\n t ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minTime ( arr , n , m ) :\n t = 0\n while ( 1 ) :\n items = 0\n for i in range ( n ) :\n items += ( t // arr [ i ] )\n if ( items >= m ) :\n return t\n t += 1\n\n"
},
{
"id": "python-java-MAXIMUM_DECIMAL_VALUE_PATH_IN_A_BINARY_MATRIX_1",
"pair": "python-java",
"Code1": "def MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n",
"Code2": "static int MaximumDecimalValue ( int mat [ ] [ ] , int n ) {\n int dp [ ] [ ] = new int [ n ] [ n ] ;\n if ( mat [ 0 ] [ 0 ] == 1 ) {\n dp [ 0 ] [ 0 ] = 1 ;\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ 0 ] [ i ] == 1 ) {\n dp [ 0 ] [ i ] = ( int ) ( dp [ 0 ] [ i - 1 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( mat [ i ] [ 0 ] == 1 ) {\n dp [ i ] [ 0 ] = ( int ) ( dp [ i - 1 ] [ 0 ] + Math . pow ( 2 , i ) ) ;\n }\n else {\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] ;\n }\n }\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n if ( mat [ i ] [ j ] == 1 ) {\n dp [ i ] [ j ] = ( int ) ( Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + Math . pow ( 2 , i + j ) ) ;\n }\n else {\n dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ;\n }\n }\n }\n return dp [ n - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef MaximumDecimalValue ( mat , n ) :\n dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n if ( mat [ 0 ] [ 0 ] == 1 ) :\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n ) :\n if ( mat [ 0 ] [ i ] == 1 ) :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + 2 ** i\n else :\n dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ]\n for i in range ( 1 , n ) :\n if ( mat [ i ] [ 0 ] == 1 ) :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ] + 2 ** i\n else :\n dp [ i ] [ 0 ] = dp [ i - 1 ] [ 0 ]\n for i in range ( 1 , n ) :\n for j in range ( 1 , n ) :\n if ( mat [ i ] [ j ] == 1 ) :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) + ( 2 ** ( i + j ) )\n else :\n dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] )\n return dp [ n - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-CHECK_DIVISIBILITY_LARGE_NUMBER_999",
"pair": "python-java",
"Code1": "def isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n",
"Code2": "static boolean isDivisible999 ( String num ) {\n int n = num . length ( ) ;\n if ( n == 0 && num . charAt ( 0 ) == ' 0 ' ) return true ;\n if ( n % 3 == 1 ) num = \"00\" + num ;\n if ( n % 3 == 2 ) num = \"0\" + num ;\n int gSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int group = 0 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 100 ;\n group += ( num . charAt ( i ++ ) - ' 0 ' ) * 10 ;\n group += num . charAt ( i ) - ' 0 ' ;\n gSum += group ;\n }\n if ( gSum > 1000 ) {\n num = Integer . toString ( gSum ) ;\n n = num . length ( ) ;\n gSum = isDivisible999 ( num ) ? 1 : 0 ;\n }\n return ( gSum == 999 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDivisible999 ( num ) :\n n = len ( num ) ;\n if ( n == 0 or num [ 0 ] == '0' ) :\n return true\n if ( ( n % 3 ) == 1 ) :\n num = \"00\" + num\n if ( ( n % 3 ) == 2 ) :\n num = \"0\" + num\n gSum = 0\n for i in range ( 0 , n , 3 ) :\n group = 0\n group += ( ord ( num [ i ] ) - 48 ) * 100\n group += ( ord ( num [ i + 1 ] ) - 48 ) * 10\n group += ( ord ( num [ i + 2 ] ) - 48 )\n gSum += group\n if ( gSum > 1000 ) :\n num = str ( gSum )\n n = len ( num )\n gSum = isDivisible999 ( num )\n return ( gSum == 999 )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_BITONIC_SUBARRAY",
"pair": "python-java",
"Code1": "def maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n",
"Code2": "static int maxSumBitonicSubArr ( int arr [ ] , int n ) {\n int [ ] msis = new int [ n ] ;\n int [ ] msds = new int [ n ] ;\n int max_sum = Integer . MIN_VALUE ;\n msis [ 0 ] = arr [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ;\n else msis [ i ] = arr [ i ] ;\n msds [ n - 1 ] = arr [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ;\n else msds [ i ] = arr [ i ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ;\n return max_sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSumBitonicSubArr ( arr , n ) :\n msis = [ None ] * n\n msds = [ None ] * n\n max_sum = 0\n msis [ 0 ] = arr [ 0 ]\n for i in range ( 1 , n ) :\n if ( arr [ i ] > arr [ i - 1 ] ) :\n msis [ i ] = msis [ i - 1 ] + arr [ i ]\n else :\n msis [ i ] = arr [ i ]\n msds [ n - 1 ] = arr [ n - 1 ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] > arr [ i + 1 ] ) :\n msds [ i ] = msds [ i + 1 ] + arr [ i ]\n else :\n msds [ i ] = arr [ i ]\n for i in range ( n ) :\n if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) :\n max_sum = ( msis [ i ] + msds [ i ] - arr [ i ] )\n return max_sum\n\n"
},
{
"id": "python-java-FIND_MINIMUM_NUMBER_DIVIDED_MAKE_NUMBER_PERFECT_SQUARE",
"pair": "python-java",
"Code1": "def findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n",
"Code2": "static int findMinNumber ( int n ) {\n int count = 0 , ans = 1 ;\n while ( n % 2 == 0 ) {\n count ++ ;\n n /= 2 ;\n }\n if ( count % 2 == 1 ) ans *= 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i += 2 ) {\n count = 0 ;\n while ( n % i == 0 ) {\n count ++ ;\n n /= i ;\n }\n if ( count % 2 == 1 ) ans *= i ;\n }\n if ( n > 2 ) ans *= n ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinNumber ( n ) :\n count = 0\n ans = 1\n while n % 2 == 0 :\n count += 1\n n //= 2\n if count % 2 is not 0 :\n ans *= 2\n for i in range ( 3 , ( int ) ( math.sqrt ( n ) ) + 1 , 2 ) :\n count = 0\n while n % i == 0 :\n count += 1\n n //= i\n if count % 2 is not 0 :\n ans *= i\n if n > 2 :\n ans *= n\n return ans\n\n"
},
{
"id": "python-java-GCD_ELEMENTS_GIVEN_RANGE",
"pair": "python-java",
"Code1": "def rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n",
"Code2": "static int rangeGCD ( int n , int m ) {\n return ( n == m ) ? n : 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rangeGCD ( n , m ) :\n return n if ( n == m ) else 1\n\n"
},
{
"id": "python-java-PROGRAMMING_PUZZLE_ASSIGN_VALUE_WITHOUT_CONTROL_STATEMENT",
"pair": "python-java",
"Code1": "def assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n",
"Code2": "static int assignValue ( int a , int b , int x ) {\n int arr [ ] = {\n a , b }\n ;\n return ( arr [ x ] ) ;\n }\n ",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef assignValue ( a , b , x ) :\n arr = [ a , b ]\n return ( arr [ x ] )\n\n"
},
{
"id": "python-java-TRIANGULAR_NUMBERS",
"pair": "python-java",
"Code1": "def isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n",
"Code2": "static boolean isTriangular ( int num ) {\n if ( num < 0 ) return false ;\n int sum = 0 ;\n for ( int n = 1 ;\n sum <= num ;\n n ++ ) {\n sum = sum + n ;\n if ( sum == num ) return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isTriangular ( num ) :\n if ( num < 0 ) :\n return False\n sum , n = 0 , 1\n while ( sum <= num ) :\n sum = sum + n\n if ( sum == num ) :\n return True\n n += 1\n return False\n\n"
},
{
"id": "python-java-PANGRAM_CHECKING",
"pair": "python-java",
"Code1": "def checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n",
"Code2": "public static boolean checkPangram ( String str ) {\n boolean [ ] mark = new boolean [ 26 ] ;\n int index = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n if ( ' A ' <= str . charAt ( i ) && str . charAt ( i ) <= ' Z ' ) index = str . charAt ( i ) - ' A ' ;\n else if ( ' a ' <= str . charAt ( i ) && str . charAt ( i ) <= ' z ' ) index = str . charAt ( i ) - ' a ' ;\n mark [ index ] = true ;\n }\n for ( int i = 0 ;\n i <= 25 ;\n i ++ ) if ( mark [ i ] == false ) return ( false ) ;\n return ( true ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkPangram ( s ) :\n List = [ ]\n for i in range ( 26 ) :\n List.append ( False )\n for c in s.lower ( ) :\n if not c == \" \" :\n List [ ord ( c ) - ord ( 'a' ) ] = True\n for ch in List :\n if ch == False :\n return False\n return True\n\n"
},
{
"id": "python-java-INTERPOLATION_SEARCH",
"pair": "python-java",
"Code1": "def interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n",
"Code2": "static int interpolationSearch ( int x ) {\n int lo = 0 , hi = ( arr . length - 1 ) ;\n while ( lo <= hi && x >= arr [ lo ] && x <= arr [ hi ] ) {\n if ( lo == hi ) {\n if ( arr [ lo ] == x ) return lo ;\n return - 1 ;\n }\n int pos = lo + ( ( ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) ;\n if ( arr [ pos ] == x ) return pos ;\n if ( arr [ pos ] < x ) lo = pos + 1 ;\n else hi = pos - 1 ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef interpolationSearch ( arr , n , x ) :\n lo = 0\n hi = ( n - 1 )\n while lo <= hi and x >= arr [ lo ] and x <= arr [ hi ] :\n if lo == hi :\n if arr [ lo ] == x :\n return lo ;\n return - 1 ;\n pos = lo + int ( ( ( float ( hi - lo ) / ( arr [ hi ] - arr [ lo ] ) ) * ( x - arr [ lo ] ) ) )\n if arr [ pos ] == x :\n return pos\n if arr [ pos ] < x :\n lo = pos + 1 ;\n else :\n hi = pos - 1 ;\n return - 1\n\n"
},
{
"id": "python-java-FITTING_SHELVES_PROBLEM",
"pair": "python-java",
"Code1": "def minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n",
"Code2": "static void minSpacePreferLarge ( int wall , int m , int n ) {\n int num_m = 0 , num_n = 0 , min_empty = wall ;\n int p = 0 , q = 0 , rem ;\n while ( wall >= n ) {\n p = wall / m ;\n rem = wall % m ;\n if ( rem <= min_empty ) {\n num_m = p ;\n num_n = q ;\n min_empty = rem ;\n }\n q += 1 ;\n wall = wall - n ;\n }\n System . out . println ( num_m + \" \" + num_n + \" \" + min_empty ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minSpacePreferLarge ( w , m , n ) :\n num_m = 0\n num_n = 0\n rem = w\n p = 0\n q = 0\n r = 0\n while ( w >= n ) :\n p = w / m\n r = w % m\n if ( r <= rem ) :\n num_m = p\n num_n = q\n rem = r\n q += 1\n w -= n\n print ( str ( int ( num_m ) ) + \" \" + str ( num_n ) + \" \" + str ( rem ) )\n\n"
},
{
"id": "python-java-FIND_REPETITIVE_ELEMENT_1_N_1_3",
"pair": "python-java",
"Code1": "def findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n",
"Code2": "static int findRepeating ( int arr [ ] , int n ) {\n int missingElement = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int element = arr [ Math . abs ( arr [ i ] ) ] ;\n if ( element < 0 ) {\n missingElement = arr [ i ] ;\n break ;\n }\n arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n }\n return Math . abs ( missingElement ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n missingElement = 0\n for i in range ( 0 , n ) :\n element = arr [ abs ( arr [ i ] ) ]\n if ( element < 0 ) :\n missingElement = arr [ i ]\n break\n arr [ abs ( arr [ i ] ) ] = - arr [ abs ( arr [ i ] ) ]\n return abs ( missingElement )\n\n"
},
{
"id": "python-java-K_LARGESTOR_SMALLEST_ELEMENTS_IN_AN_ARRAY",
"pair": "python-java",
"Code1": "def kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "public static void kLargest ( Integer [ ] arr , int k ) {\n Arrays . sort ( arr , Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( arr [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kLargest ( arr , k ) :\n arr.sort ( reverse = True )\n for i in range ( k ) :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM_1",
"pair": "python-java",
"Code1": "def knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n int i , w ;\n int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ;\n for ( i = 0 ;\n i <= n ;\n i ++ ) {\n for ( w = 0 ;\n w <= W ;\n w ++ ) {\n if ( i == 0 || w == 0 ) K [ i ] [ w ] = 0 ;\n else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ;\n else K [ i ] [ w ] = K [ i - 1 ] [ w ] ;\n }\n }\n return K [ n ] [ W ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n K = [ [ 0 for x in range ( W + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( n + 1 ) :\n for w in range ( W + 1 ) :\n if i == 0 or w == 0 :\n K [ i ] [ w ] = 0\n elif wt [ i - 1 ] <= w :\n K [ i ] [ w ] = max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] )\n else :\n K [ i ] [ w ] = K [ i - 1 ] [ w ]\n return K [ n ] [ W ]\n\n"
},
{
"id": "python-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_2",
"pair": "python-java",
"Code1": "def isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n",
"Code2": "static boolean isPowerOfFour ( int n ) {\n return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) )\n\n"
},
{
"id": "python-java-C_PROGRAM_FACTORIAL_NUMBER",
"pair": "python-java",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_GROUPS_SIZE_2_3_SUM_MULTIPLE_3",
"pair": "python-java",
"Code1": "def findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n",
"Code2": "int findgroups ( int arr [ ] , int n ) {\n int c [ ] = new int [ ] {\n 0 , 0 , 0 }\n ;\n int i ;\n int res = 0 ;\n for ( i = 0 ;\n i < n ;\n i ++ ) c [ arr [ i ] % 3 ] ++ ;\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ;\n res += c [ 1 ] * c [ 2 ] ;\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ;\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ;\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ;\n res += c [ 0 ] * c [ 1 ] * c [ 2 ] ;\n return res ;\n }\n ",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findgroups ( arr , n ) :\n c = [ 0 , 0 , 0 ]\n res = 0\n for i in range ( 0 , n ) :\n c [ arr [ i ] % 3 ] += 1\n res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )\n res += c [ 1 ] * c [ 2 ]\n res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6\n res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6\n res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )\n res += c [ 0 ] * c [ 1 ] * c [ 2 ]\n return res\n\n"
},
{
"id": "python-java-K_TH_LARGEST_SUM_CONTIGUOUS_SUBARRAY",
"pair": "python-java",
"Code1": "def kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n",
"Code2": "static int kthLargestSum ( int arr [ ] , int n , int k ) {\n int sum [ ] = new int [ n + 1 ] ;\n sum [ 0 ] = 0 ;\n sum [ 1 ] = arr [ 0 ] ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ;\n PriorityQueue < Integer > Q = new PriorityQueue < Integer > ( ) ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = i ;\n j <= n ;\n j ++ ) {\n int x = sum [ j ] - sum [ i - 1 ] ;\n if ( Q . size ( ) < k ) Q . add ( x ) ;\n else {\n if ( Q . peek ( ) < x ) {\n Q . poll ( ) ;\n Q . add ( x ) ;\n }\n }\n }\n }\n return Q . poll ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kthLargestSum ( arr , n , k ) :\n sum = [ ]\n sum.append ( 0 )\n sum.append ( arr [ 0 ] )\n for i in range ( 2 , n + 1 ) :\n sum.append ( sum [ i - 1 ] + arr [ i - 1 ] )\n Q = [ ]\n heapq.heapify ( Q )\n for i in range ( 1 , n + 1 ) :\n for j in range ( i , n + 1 ) :\n x = sum [ j ] - sum [ i - 1 ]\n if len ( Q ) < k :\n heapq.heappush ( Q , x )\n else :\n if Q [ 0 ] < x :\n heapq.heappop ( Q )\n heapq.heappush ( Q , x )\n return Q [ 0 ]\n\n"
},
{
"id": "python-java-FIND_A_SPECIFIC_PAIR_IN_MATRIX_1",
"pair": "python-java",
"Code1": "def findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n",
"Code2": "static int findMaxValue ( int N , int mat [ ] [ ] ) {\n int maxValue = Integer . MIN_VALUE ;\n int maxArr [ ] [ ] = new int [ N ] [ N ] ;\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ] ;\n int maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( mat [ N - 1 ] [ j ] > maxv ) maxv = mat [ N - 1 ] [ j ] ;\n maxArr [ N - 1 ] [ j ] = maxv ;\n }\n maxv = mat [ N - 1 ] [ N - 1 ] ;\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n if ( mat [ i ] [ N - 1 ] > maxv ) maxv = mat [ i ] [ N - 1 ] ;\n maxArr [ i ] [ N - 1 ] = maxv ;\n }\n for ( int i = N - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 2 ;\n j >= 0 ;\n j -- ) {\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) maxValue = maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] ;\n maxArr [ i ] [ j ] = Math . max ( mat [ i ] [ j ] , Math . max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) ) ;\n }\n }\n return maxValue ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxValue ( mat ) :\n maxValue = - sys.maxsize - 1\n maxArr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ]\n maxArr [ N - 1 ] [ N - 1 ] = mat [ N - 1 ] [ N - 1 ]\n maxv = mat [ N - 1 ] [ N - 1 ]\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ N - 1 ] [ j ] > maxv ) :\n maxv = mat [ N - 1 ] [ j ]\n maxArr [ N - 1 ] [ j ] = maxv\n maxv = mat [ N - 1 ] [ N - 1 ]\n for i in range ( N - 2 , - 1 , - 1 ) :\n if ( mat [ i ] [ N - 1 ] > maxv ) :\n maxv = mat [ i ] [ N - 1 ]\n maxArr [ i ] [ N - 1 ] = maxv\n for i in range ( N - 2 , - 1 , - 1 ) :\n for j in range ( N - 2 , - 1 , - 1 ) :\n if ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] > maxValue ) :\n maxValue = ( maxArr [ i + 1 ] [ j + 1 ] - mat [ i ] [ j ] )\n maxArr [ i ] [ j ] = max ( mat [ i ] [ j ] , max ( maxArr [ i ] [ j + 1 ] , maxArr [ i + 1 ] [ j ] ) )\n return maxValue\n\n"
},
{
"id": "python-java-K_TH_PRIME_FACTOR_GIVEN_NUMBER",
"pair": "python-java",
"Code1": "def kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n",
"Code2": "static int kPrimeFactor ( int n , int k ) {\n while ( n % 2 == 0 ) {\n k -- ;\n n = n / 2 ;\n if ( k == 0 ) return 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n while ( n % i == 0 ) {\n if ( k == 1 ) return i ;\n k -- ;\n n = n / i ;\n }\n }\n if ( n > 2 && k == 1 ) return n ;\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef kPrimeFactor ( n , k ) :\n while ( n % 2 == 0 ) :\n k = k - 1\n n = n / 2\n if ( k == 0 ) :\n return 2\n i = 3\n while i <= math.sqrt ( n ) :\n while ( n % i == 0 ) :\n if ( k == 1 ) :\n return i\n k = k - 1\n n = n / i\n i = i + 2\n if ( n > 2 and k == 1 ) :\n return n\n return - 1\n\n"
},
{
"id": "python-java-PRINT_DISTINCT_ELEMENTS_GIVEN_INTEGER_ARRAY_2",
"pair": "python-java",
"Code1": "def printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "static void printDistinct ( int arr [ ] ) {\n HashSet < Integer > set = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( ! set . contains ( arr [ i ] ) ) {\n set . add ( arr [ i ] ) ;\n System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDistinct ( arr , n ) :\n s = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] not in s.keys ( ) ) :\n s [ arr [ i ] ] = arr [ i ]\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-PROGRAM_DECIMAL_BINARY_CONVERSION_1",
"pair": "python-java",
"Code1": "def decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n",
"Code2": "public void decToBinary ( int n ) {\n for ( int i = 31 ;\n i >= 0 ;\n i -- ) {\n int k = n >> i ;\n if ( ( k & 1 ) > 0 ) System . out . print ( \"1\" ) ;\n else System . out . print ( \"0\" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decToBinary ( n ) :\n for i in range ( 31 , - 1 , - 1 ) :\n k = n >> i\n if ( k & 1 ) :\n print ( \"1\" , end = \"\" )\n else :\n print ( \"0\" , end = \"\" )\n\n"
},
{
"id": "python-java-SUPER_PRIME",
"pair": "python-java",
"Code1": "def SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n",
"Code2": "static void SieveOfEratosthenes ( int n , boolean isPrime [ ] ) {\n isPrime [ 0 ] = isPrime [ 1 ] = false ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) isPrime [ i ] = true ;\n for ( int p = 2 ;\n p * p <= n ;\n p ++ ) {\n if ( isPrime [ p ] == true ) {\n for ( int i = p * 2 ;\n i <= n ;\n i += p ) isPrime [ i ] = false ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef SieveOfEratosthenes ( n , isPrime ) :\n isPrime [ 0 ] = isPrime [ 1 ] = False\n for i in range ( 2 , n + 1 ) :\n isPrime [ i ] = True\n for p in range ( 2 , n + 1 ) :\n if ( p * p <= n and isPrime [ p ] == True ) :\n for i in range ( p * 2 , n + 1 , p ) :\n isPrime [ i ] = False\n p += 1\n\n"
},
{
"id": "python-java-COUNT_OPERATIONS_MAKE_STRINGAB_FREE",
"pair": "python-java",
"Code1": "def abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n",
"Code2": "static int abFree ( char [ ] s ) {\n int b_count = 0 ;\n int res = 0 ;\n for ( int i = 0 ;\n i < s . length ;\n i ++ ) {\n if ( s [ s . length - i - 1 ] == ' a ' ) {\n res = ( res + b_count ) ;\n b_count = ( b_count * 2 ) ;\n }\n else {\n b_count += 1 ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef abFree ( s ) :\n b_count = 0\n res = 0\n for i in range ( len ( s ) ) :\n if s [ ~ i ] == 'a' :\n res = ( res + b_count )\n b_count = ( b_count * 2 )\n else :\n b_count += 1\n return res\n\n"
},
{
"id": "python-java-RECURSIVE_SOLUTION_COUNT_SUBSTRINGS_FIRST_LAST_CHARACTERS",
"pair": "python-java",
"Code1": "def countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n",
"Code2": "static int countSubstrs ( String str , int i , int j , int n ) {\n if ( n == 1 ) return 1 ;\n if ( n <= 0 ) return 0 ;\n int res = countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) ;\n if ( str . charAt ( i ) == str . charAt ( j ) ) res ++ ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubstrs ( str , i , j , n ) :\n if ( n == 1 ) :\n return 1\n if ( n <= 0 ) :\n return 0\n res = ( countSubstrs ( str , i + 1 , j , n - 1 ) + countSubstrs ( str , i , j - 1 , n - 1 ) - countSubstrs ( str , i + 1 , j - 1 , n - 2 ) )\n if ( str [ i ] == str [ j ] ) :\n res += 1\n return res\n\n"
},
{
"id": "python-java-FIND_THE_FIRST_MISSING_NUMBER",
"pair": "python-java",
"Code1": "def findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n",
"Code2": "int findFirstMissing ( int array [ ] , int start , int end ) {\n if ( start > end ) return end + 1 ;\n if ( start != array [ start ] ) return start ;\n int mid = ( start + end ) / 2 ;\n if ( array [ mid ] == mid ) return findFirstMissing ( array , mid + 1 , end ) ;\n return findFirstMissing ( array , start , mid ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findFirstMissing ( array , start , end ) :\n if ( start > end ) :\n return end + 1\n if ( start != array [ start ] ) :\n return start\n mid = int ( ( start + end ) / 2 )\n if ( array [ mid ] == mid ) :\n return findFirstMissing ( array , mid + 1 , end )\n return findFirstMissing ( array , start , mid )\n\n"
},
{
"id": "python-java-PROGRAM_FOR_FACTORIAL_OF_A_NUMBER",
"pair": "python-java",
"Code1": "def factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n",
"Code2": "static int factorial ( int n ) {\n if ( n == 0 ) return 1 ;\n return n * factorial ( n - 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef factorial ( n ) :\n return 1 if ( n == 1 or n == 0 ) else n * factorial ( n - 1 )\n\n"
},
{
"id": "python-java-MINIMUM_ROTATIONS_UNLOCK_CIRCULAR_LOCK",
"pair": "python-java",
"Code1": "def minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n",
"Code2": "static int minRotation ( int input , int unlock_code ) {\n int rotation = 0 ;\n int input_digit , code_digit ;\n while ( input > 0 || unlock_code > 0 ) {\n input_digit = input % 10 ;\n code_digit = unlock_code % 10 ;\n rotation += Math . min ( Math . abs ( input_digit - code_digit ) , 10 - Math . abs ( input_digit - code_digit ) ) ;\n input /= 10 ;\n unlock_code /= 10 ;\n }\n return rotation ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRotation ( input , unlock_code ) :\n rotation = 0\n while ( input > 0 or unlock_code > 0 ) :\n input_digit = input % 10\n code_digit = unlock_code % 10\n rotation += min ( abs ( input_digit - code_digit ) , 10 - abs ( input_digit - code_digit ) )\n input = int ( input / 10 )\n unlock_code = int ( unlock_code / 10 )\n return rotation\n\n"
},
{
"id": "python-java-LARGEST_SUBSET_WHOSE_ALL_ELEMENTS_ARE_FIBONACCI_NUMBERS",
"pair": "python-java",
"Code1": "def findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n",
"Code2": "public static void findFibSubset ( Integer [ ] x ) {\n Integer max = Collections . max ( Arrays . asList ( x ) ) ;\n List < Integer > fib = new ArrayList < Integer > ( ) ;\n List < Integer > result = new ArrayList < Integer > ( ) ;\n Integer a = 0 ;\n Integer b = 1 ;\n while ( b < max ) {\n Integer c = a + b ;\n a = b ;\n b = c ;\n fib . add ( c ) ;\n }\n for ( Integer i = 0 ;\n i < x . length ;\n i ++ ) {\n if ( fib . contains ( x [ i ] ) ) {\n result . add ( x [ i ] ) ;\n }\n }\n System . out . println ( result ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findFibSubset ( arr , n ) :\n m = max ( arr )\n a = 0\n b = 1\n hash = [ ]\n hash.append ( a )\n hash.append ( b )\n while ( b < m ) :\n c = a + b\n a = b\n b = c\n hash.append ( b )\n for i in range ( n ) :\n if arr [ i ] in hash :\n print ( arr [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-MARKOV_MATRIX",
"pair": "python-java",
"Code1": "def checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n",
"Code2": "static boolean checkMarkov ( double m [ ] [ ] ) {\n for ( int i = 0 ;\n i < m . length ;\n i ++ ) {\n double sum = 0 ;\n for ( int j = 0 ;\n j < m [ i ] . length ;\n j ++ ) sum = sum + m [ i ] [ j ] ;\n if ( sum != 1 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkMarkov ( m ) :\n for i in range ( 0 , len ( m ) ) :\n sm = 0\n for j in range ( 0 , len ( m [ i ] ) ) :\n sm = sm + m [ i ] [ j ]\n if ( sm != 1 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-SEARCH_INSERT_AND_DELETE_IN_A_SORTED_ARRAY_1",
"pair": "python-java",
"Code1": "def insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n",
"Code2": "static int insertSorted ( int arr [ ] , int n , int key , int capacity ) {\n if ( n >= capacity ) return n ;\n int i ;\n for ( i = n - 1 ;\n ( i >= 0 && arr [ i ] > key ) ;\n i -- ) arr [ i + 1 ] = arr [ i ] ;\n arr [ i + 1 ] = key ;\n return ( n + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef insertSorted ( arr , n , key , capacity ) :\n if ( n >= capacity ) :\n return n\n i = n - 1\n while i >= 0 and arr [ i ] > key :\n arr [ i + 1 ] = arr [ i ]\n i -= 1\n arr [ i + 1 ] = key\n return ( n + 1 )\n\n"
},
{
"id": "python-java-PROGRAM_REVERSE_STRING_ITERATIVE_RECURSIVE_2",
"pair": "python-java",
"Code1": "def recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n",
"Code2": "static void recursiveReverse ( char [ ] str , int i ) {\n int n = str . length ;\n if ( i == n / 2 ) return ;\n swap ( str , i , n - i - 1 ) ;\n recursiveReverse ( str , i + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef recursiveReverse ( str , i = 0 ) :\n n = len ( str )\n if i == n // 2 :\n return\n str [ i ] , str [ n - i - 1 ] = str [ n - i - 1 ] , str [ i ]\n recursiveReverse ( str , i + 1 )\n\n"
},
{
"id": "python-java-CHECK_IF_ARRAY_ELEMENTS_ARE_CONSECUTIVE",
"pair": "python-java",
"Code1": "def areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n",
"Code2": "boolean areConsecutive ( int arr [ ] , int n ) {\n if ( n < 1 ) return false ;\n int min = getMin ( arr , n ) ;\n int max = getMax ( arr , n ) ;\n if ( max - min + 1 == n ) {\n boolean visited [ ] = new boolean [ n ] ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( visited [ arr [ i ] - min ] != false ) return false ;\n visited [ arr [ i ] - min ] = true ;\n }\n return true ;\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef areConsecutive ( arr , n ) :\n if ( n < 1 ) :\n return False\n Min = min ( arr )\n Max = max ( arr )\n if ( Max - Min + 1 == n ) :\n visited = [ False for i in range ( n ) ]\n for i in range ( n ) :\n if ( visited [ arr [ i ] - Min ] != False ) :\n return False\n visited [ arr [ i ] - Min ] = True\n return True\n return False\n\n"
},
{
"id": "python-java-MODULUS_TWO_FLOAT_DOUBLE_NUMBERS",
"pair": "python-java",
"Code1": "def findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n",
"Code2": "static double findMod ( double a , double b ) {\n if ( a < 0 ) a = - a ;\n if ( b < 0 ) b = - b ;\n double mod = a ;\n while ( mod >= b ) mod = mod - b ;\n if ( a < 0 ) return - mod ;\n return mod ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMod ( a , b ) :\n if ( a < 0 ) :\n a = - a\n if ( b < 0 ) :\n b = - b\n mod = a\n while ( mod >= b ) :\n mod = mod - b\n if ( a < 0 ) :\n return - mod\n return mod\n\n"
},
{
"id": "python-java-SUM_OF_ALL_SUBSTRINGS_OF_A_STRING_REPRESENTING_A_NUMBER",
"pair": "python-java",
"Code1": "def sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n",
"Code2": "public static int sumOfSubstrings ( String num ) {\n int n = num . length ( ) ;\n int sumofdigit [ ] = new int [ n ] ;\n sumofdigit [ 0 ] = num . charAt ( 0 ) - ' 0 ' ;\n int res = sumofdigit [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n int numi = num . charAt ( i ) - ' 0 ' ;\n sumofdigit [ i ] = ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] ;\n res += sumofdigit [ i ] ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumOfSubstrings ( num ) :\n n = len ( num )\n sumofdigit = [ ]\n sumofdigit.append ( int ( num [ 0 ] ) )\n res = sumofdigit [ 0 ]\n for i in range ( 1 , n ) :\n numi = int ( num [ i ] )\n sumofdigit.append ( ( i + 1 ) * numi + 10 * sumofdigit [ i - 1 ] )\n res += sumofdigit [ i ]\n return res\n\n"
},
{
"id": "python-java-FIND_PAIR_WITH_GREATEST_PRODUCT_IN_ARRAY_1",
"pair": "python-java",
"Code1": "def findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n",
"Code2": "static int findGreatest ( int arr [ ] , int n ) {\n Map < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( m . containsKey ( arr [ i ] ) ) {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ;\n }\n }\n Arrays . sort ( arr ) ;\n for ( int i = n - 1 ;\n i > 1 ;\n i -- ) {\n for ( int j = 0 ;\n j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ;\n j ++ ) {\n if ( arr [ i ] % arr [ j ] == 0 ) {\n int result = arr [ i ] / arr [ j ] ;\n if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) {\n return arr [ i ] ;\n }\n else if ( result == arr [ j ] && m . get ( result ) > 1 ) {\n return arr [ i ] ;\n }\n }\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findGreatest ( arr , n ) :\n m = dict ( )\n for i in arr :\n m [ i ] = m.get ( i , 0 ) + 1\n arr = sorted ( arr )\n for i in range ( n - 1 , 0 , - 1 ) :\n j = 0\n while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :\n if ( arr [ i ] % arr [ j ] == 0 ) :\n result = arr [ i ] // arr [ j ]\n if ( result != arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 0 ) :\n return arr [ i ]\n elif ( result == arr [ j ] and ( result in m.keys ( ) ) and m [ result ] > 1 ) :\n return arr [ i ]\n j += 1\n return - 1\n\n"
},
{
"id": "python-java-FIND_THE_MISSING_NUMBER_1",
"pair": "python-java",
"Code1": "def getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n",
"Code2": "static int getMissingNo ( int a [ ] , int n ) {\n int total = 1 ;\n for ( int i = 2 ;\n i <= ( n + 1 ) ;\n i ++ ) {\n total += i ;\n total -= a [ i - 2 ] ;\n }\n return total ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMissingNo ( a , n ) :\n i , total = 0 , 1\n for i in range ( 2 , n + 2 ) :\n total += i\n total -= a [ i - 2 ]\n return total\n\n"
},
{
"id": "python-java-NEXT_POWER_OF_2_2",
"pair": "python-java",
"Code1": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n\n"
},
{
"id": "python-java-C_PROGRAM_ADDITION_TWO_MATRICES",
"pair": "python-java",
"Code1": "def add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n",
"Code2": "static void add ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) {\n int i , j ;\n for ( i = 0 ;\n i < N ;\n i ++ ) for ( j = 0 ;\n j < N ;\n j ++ ) C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef add ( A , B , C ) :\n for i in range ( N ) :\n for j in range ( N ) :\n C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]\n\n"
},
{
"id": "python-java-ENTRINGER_NUMBER_1",
"pair": "python-java",
"Code1": "def zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n",
"Code2": "static int zigzag ( int n , int k ) {\n int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n dp [ 0 ] [ 0 ] = 1 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) dp [ i ] [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= n ;\n i ++ ) {\n for ( int j = 1 ;\n j <= Math . min ( i , k ) ;\n j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ;\n }\n return dp [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef zigzag ( n , k ) :\n dp = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ]\n dp [ 0 ] [ 0 ] = 1\n for i in range ( 1 , n + 1 ) :\n dp [ i ] [ 0 ] = 0\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , k + 1 ) :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] )\n return dp [ n ] [ k ]\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_11_EGG_DROPPING_PUZZLE_1",
"pair": "python-java",
"Code1": "def eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n",
"Code2": "static int eggDrop ( int n , int k ) {\n int eggFloor [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ;\n int res ;\n int i , j , x ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n eggFloor [ i ] [ 1 ] = 1 ;\n eggFloor [ i ] [ 0 ] = 0 ;\n }\n for ( j = 1 ;\n j <= k ;\n j ++ ) eggFloor [ 1 ] [ j ] = j ;\n for ( i = 2 ;\n i <= n ;\n i ++ ) {\n for ( j = 2 ;\n j <= k ;\n j ++ ) {\n eggFloor [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( x = 1 ;\n x <= j ;\n x ++ ) {\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] ) ;\n if ( res < eggFloor [ i ] [ j ] ) eggFloor [ i ] [ j ] = res ;\n }\n }\n }\n return eggFloor [ n ] [ k ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef eggDrop ( n , k ) :\n eggFloor = [ [ 0 for x in range ( k + 1 ) ] for x in range ( n + 1 ) ]\n for i in range ( 1 , n + 1 ) :\n eggFloor [ i ] [ 1 ] = 1\n eggFloor [ i ] [ 0 ] = 0\n for j in range ( 1 , k + 1 ) :\n eggFloor [ 1 ] [ j ] = j\n for i in range ( 2 , n + 1 ) :\n for j in range ( 2 , k + 1 ) :\n eggFloor [ i ] [ j ] = INT_MAX\n for x in range ( 1 , j + 1 ) :\n res = 1 + max ( eggFloor [ i - 1 ] [ x - 1 ] , eggFloor [ i ] [ j - x ] )\n if res < eggFloor [ i ] [ j ] :\n eggFloor [ i ] [ j ] = res\n return eggFloor [ n ] [ k ]\n\n"
},
{
"id": "python-java-PRINT_A_CLOSEST_STRING_THAT_DOES_NOT_CONTAIN_ADJACENT_DUPLICATES",
"pair": "python-java",
"Code1": "def noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n",
"Code2": "public static String noAdjacentDup ( String s1 ) {\n int n = s1 . length ( ) ;\n char [ ] s = s1 . toCharArray ( ) ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( s [ i ] == s [ i - 1 ] ) {\n s [ i ] = ' a ' ;\n while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ;\n i ++ ;\n }\n }\n return ( new String ( s ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef noAdjacentDup ( s ) :\n n = len ( s )\n for i in range ( 1 , n ) :\n if ( s [ i ] == s [ i - 1 ] ) :\n s [ i ] = \"a\"\n while ( s [ i ] == s [ i - 1 ] or ( i + 1 < n and s [ i ] == s [ i + 1 ] ) ) :\n s [ i ] += 1\n i += 1\n return s\n\n"
},
{
"id": "python-java-MODIFY_ARRAY_TO_MAXIMIZE_SUM_OF_ADJACENT_DIFFERENCES",
"pair": "python-java",
"Code1": "def maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n",
"Code2": "static int maximumDifferenceSum ( int arr [ ] , int N ) {\n int dp [ ] [ ] = new int [ N ] [ 2 ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0 ;\n for ( int i = 0 ;\n i < ( N - 1 ) ;\n i ++ ) {\n dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + Math . abs ( 1 - arr [ i ] ) ) ;\n dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] + Math . abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + Math . abs ( arr [ i + 1 ] - arr [ i ] ) ) ;\n }\n return Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumDifferenceSum ( arr , N ) :\n dp = [ [ 0 , 0 ] for i in range ( N ) ]\n for i in range ( N ) :\n dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0\n for i in range ( N - 1 ) :\n dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )\n dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )\n return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )\n\n"
},
{
"id": "python-java-MINIMUM_INSERTIONS_SORT_ARRAY",
"pair": "python-java",
"Code1": "def minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n",
"Code2": "static int minInsertionStepToSortArray ( int arr [ ] , int N ) {\n int [ ] lis = new int [ N ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) lis [ i ] = 1 ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] >= arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ;\n int max = 0 ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) if ( max < lis [ i ] ) max = lis [ i ] ;\n return ( N - max ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minInsertionStepToSortArray ( arr , N ) :\n lis = [ 0 ] * N\n for i in range ( N ) :\n lis [ i ] = 1\n for i in range ( 1 , N ) :\n for j in range ( i ) :\n if ( arr [ i ] >= arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :\n lis [ i ] = lis [ j ] + 1\n max = 0\n for i in range ( N ) :\n if ( max < lis [ i ] ) :\n max = lis [ i ]\n return ( N - max )\n\n"
},
{
"id": "python-java-EFFICIENT_WAY_CHECK_WHETHER_N_TH_FIBONACCI_NUMBER_MULTIPLE_10",
"pair": "python-java",
"Code1": "def isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n",
"Code2": "static boolean isMultipleOf10 ( int n ) {\n if ( n % 15 == 0 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isMultipleOf10 ( n ) :\n return ( n % 15 == 0 )\n\n"
},
{
"id": "python-java-HARDY_RAMANUJAN_THEOREM",
"pair": "python-java",
"Code1": "def exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n",
"Code2": "static int exactPrimeFactorCount ( int n ) {\n int count = 0 ;\n if ( n % 2 == 0 ) {\n count ++ ;\n while ( n % 2 == 0 ) n = n / 2 ;\n }\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i = i + 2 ) {\n if ( n % i == 0 ) {\n count ++ ;\n while ( n % i == 0 ) n = n / i ;\n }\n }\n if ( n > 2 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef exactPrimeFactorCount ( n ) :\n count = 0\n if ( n % 2 == 0 ) :\n count = count + 1\n while ( n % 2 == 0 ) :\n n = int ( n / 2 )\n i = 3\n while ( i <= int ( math.sqrt ( n ) ) ) :\n if ( n % i == 0 ) :\n count = count + 1\n while ( n % i == 0 ) :\n n = int ( n / i )\n i = i + 2\n if ( n > 2 ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-QUERIES_FOR_CHARACTERS_IN_A_REPEATED_STRING",
"pair": "python-java",
"Code1": "def query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n",
"Code2": "static void query ( String s , int i , int j ) {\n int n = s . length ( ) ;\n i %= n ;\n j %= n ;\n if ( s . charAt ( i ) == s . charAt ( j ) ) System . out . println ( \"Yes\" ) ;\n else System . out . println ( \"No\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef query ( s , i , j ) :\n n = len ( s )\n i %= n\n j %= n\n print ( \"Yes\" ) if s [ i ] == s [ j ] else print ( \"No\" )\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_PRODUCT_OF_A_TRIPLET_IN_ARRAY_1",
"pair": "python-java",
"Code1": "def maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n",
"Code2": "static int maxProduct ( int arr [ ] , int n ) {\n if ( n < 3 ) {\n return - 1 ;\n }\n Arrays . sort ( arr ) ;\n return Math . max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProduct ( arr , n ) :\n if n < 3 :\n return - 1\n arr.sort ( )\n return max ( arr [ 0 ] * arr [ 1 ] * arr [ n - 1 ] , arr [ n - 1 ] * arr [ n - 2 ] * arr [ n - 3 ] )\n\n"
},
{
"id": "python-java-FIND_SUBARRAY_LEAST_AVERAGE",
"pair": "python-java",
"Code1": "def findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n",
"Code2": "static void findMinAvgSubarray ( int n , int k ) {\n if ( n < k ) return ;\n int res_index = 0 ;\n int curr_sum = 0 ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) curr_sum += arr [ i ] ;\n int min_sum = curr_sum ;\n for ( int i = k ;\n i < n ;\n i ++ ) {\n curr_sum += arr [ i ] - arr [ i - k ] ;\n if ( curr_sum < min_sum ) {\n min_sum = curr_sum ;\n res_index = ( i - k + 1 ) ;\n }\n }\n System . out . println ( \"Subarray between [\" + res_index + \", \" + ( res_index + k - 1 ) + \"] has minimum average\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinAvgSubarray ( arr , n , k ) :\n if ( n < k ) : return 0\n res_index = 0\n curr_sum = 0\n for i in range ( k ) :\n curr_sum += arr [ i ]\n min_sum = curr_sum\n for i in range ( k , n ) :\n curr_sum += arr [ i ] - arr [ i - k ]\n if ( curr_sum < min_sum ) :\n min_sum = curr_sum\n res_index = ( i - k + 1 )\n print ( \"Subarray between [\" , res_index , \", \" , ( res_index + k - 1 ) , \"] has minimum average\" )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_PATHS_SOURCE_DESTINATION_EXACTLY_K_EDGES",
"pair": "python-java",
"Code1": "def countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n",
"Code2": "int countwalks ( int graph [ ] [ ] , int u , int v , int k ) {\n if ( k == 0 && u == v ) return 1 ;\n if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ;\n if ( k <= 0 ) return 0 ;\n int count = 0 ;\n for ( int i = 0 ;\n i < V ;\n i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countwalks ( graph , u , v , k ) :\n if ( k == 0 and u == v ) :\n return 1\n if ( k == 1 and graph [ u ] [ v ] ) :\n return 1\n if ( k <= 0 ) :\n return 0\n count = 0\n for i in range ( 0 , V ) :\n if ( graph [ u ] [ i ] == 1 ) :\n count += countwalks ( graph , i , v , k - 1 )\n return count\n\n"
},
{
"id": "python-java-COUNT_PAIRS_WHOSE_PRODUCTS_EXIST_IN_ARRAY_1",
"pair": "python-java",
"Code1": "def countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n",
"Code2": "static int countPairs ( int arr [ ] , int n ) {\n int result = 0 ;\n HashSet < Integer > Hash = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n Hash . add ( arr [ i ] ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int product = arr [ i ] * arr [ j ] ;\n if ( Hash . contains ( product ) ) {\n result ++ ;\n }\n }\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( arr , n ) :\n result = 0\n Hash = set ( )\n for i in range ( n ) :\n Hash.add ( arr [ i ] )\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n product = arr [ i ] * arr [ j ]\n if product in ( Hash ) :\n result += 1\n return result\n\n"
},
{
"id": "python-java-SERIES_LARGEST_GCD_SUM_EQUALS_N",
"pair": "python-java",
"Code1": "def print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n",
"Code2": "static void print_sequence ( int n , int k ) {\n int b = n / ( k * ( k + 1 ) / 2 ) ;\n if ( b == 0 ) {\n System . out . println ( \"-1\" ) ;\n }\n else {\n int r = 1 ;\n for ( int x = 1 ;\n x * x <= n ;\n x ++ ) {\n if ( n % x != 0 ) continue ;\n if ( x <= b && x > r ) r = x ;\n if ( n / x <= b && n / x > r ) r = n / x ;\n }\n for ( int i = 1 ;\n i < k ;\n i ++ ) System . out . print ( r * i + \" \" ) ;\n int res = n - ( r * ( k * ( k - 1 ) / 2 ) ) ;\n System . out . println ( res ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef print_sequence ( n , k ) :\n b = int ( n / ( k * ( k + 1 ) / 2 ) )\n if b == 0 :\n print ( \"-1\" )\n else :\n r = 1\n x = 1\n while x ** 2 <= n :\n if n % x != 0 :\n continue\n elif x <= b and x > r :\n r = x\n elif n / x <= b and n / x > r :\n r = n / x\n x = x + 1\n i = 1\n while i < k :\n print ( r * i , end = \" \" )\n i = i + 1\n last_term = n - ( r * ( k * ( k - 1 ) / 2 ) )\n print ( last_term )\n\n"
},
{
"id": "python-java-SMALLEST_POWER_OF_2_GREATER_THAN_OR_EQUAL_TO_N_2",
"pair": "python-java",
"Code1": "def nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n",
"Code2": "static int nextPowerOf2 ( int n ) {\n n -- ;\n n |= n >> 1 ;\n n |= n >> 2 ;\n n |= n >> 4 ;\n n |= n >> 8 ;\n n |= n >> 16 ;\n n ++ ;\n return n ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef nextPowerOf2 ( n ) :\n n -= 1\n n |= n >> 1\n n |= n >> 2\n n |= n >> 4\n n |= n >> 8\n n |= n >> 16\n n += 1\n return n\n\n"
},
{
"id": "python-java-MAXIMIZE_ARRJ_ARRI_ARRL_ARRK_SUCH_THAT_I_J_K_L",
"pair": "python-java",
"Code1": "def findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n",
"Code2": "static int findMaxValue ( int [ ] arr , int n ) {\n if ( n < 4 ) {\n System . out . println ( \"The array should have\" + \" atleast 4 elements\" ) ;\n }\n int table1 [ ] = new int [ n + 1 ] ;\n int table2 [ ] = new int [ n ] ;\n int table3 [ ] = new int [ n - 1 ] ;\n int table4 [ ] = new int [ n - 2 ] ;\n Arrays . fill ( table1 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table2 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table3 , Integer . MIN_VALUE ) ;\n Arrays . fill ( table4 , Integer . MIN_VALUE ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n table1 [ i ] = Math . max ( table1 [ i + 1 ] , arr [ i ] ) ;\n }\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n table2 [ i ] = Math . max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] ) ;\n }\n for ( int i = n - 3 ;\n i >= 0 ;\n i -- ) table3 [ i ] = Math . max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] ) ;\n for ( int i = n - 4 ;\n i >= 0 ;\n i -- ) table4 [ i ] = Math . max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] ) ;\n return table4 [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxValue ( arr , n ) :\n if n < 4 :\n print ( \"The array should have atlest 4 elements\" )\n return MIN\n table1 , table2 = [ MIN ] * ( n + 1 ) , [ MIN ] * n\n table3 , table4 = [ MIN ] * ( n - 1 ) , [ MIN ] * ( n - 2 )\n for i in range ( n - 1 , - 1 , - 1 ) :\n table1 [ i ] = max ( table1 [ i + 1 ] , arr [ i ] )\n for i in range ( n - 2 , - 1 , - 1 ) :\n table2 [ i ] = max ( table2 [ i + 1 ] , table1 [ i + 1 ] - arr [ i ] )\n for i in range ( n - 3 , - 1 , - 1 ) :\n table3 [ i ] = max ( table3 [ i + 1 ] , table2 [ i + 1 ] + arr [ i ] )\n for i in range ( n - 4 , - 1 , - 1 ) :\n table4 [ i ] = max ( table4 [ i + 1 ] , table3 [ i + 1 ] - arr [ i ] )\n return table4 [ 0 ]\n\n"
},
{
"id": "python-java-PRINT_ARRAY_STRINGS_SORTED_ORDER_WITHOUT_COPYING_ONE_STRING_ANOTHER",
"pair": "python-java",
"Code1": "def printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n",
"Code2": "static void printInSortedOrder ( String arr [ ] , int n ) {\n int index [ ] = new int [ n ] ;\n int i , j , min ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n index [ i ] = i ;\n }\n for ( i = 0 ;\n i < n - 1 ;\n i ++ ) {\n min = i ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) {\n min = j ;\n }\n }\n if ( min != i ) {\n int temp = index [ min ] ;\n index [ min ] = index [ i ] ;\n index [ i ] = temp ;\n }\n }\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n System . out . print ( arr [ index [ i ] ] + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printInSortedOrder ( arr , n ) :\n index = [ 0 ] * n\n for i in range ( n ) :\n index [ i ] = i\n for i in range ( n - 1 ) :\n min = i\n for j in range ( i + 1 , n ) :\n if ( arr [ index [ min ] ] > arr [ index [ j ] ] ) :\n min = j\n if ( min != i ) :\n index [ min ] , index [ i ] = index [ i ] , index [ min ]\n for i in range ( n ) :\n print ( arr [ index [ i ] ] , end = \" \" )\n\n"
},
{
"id": "python-java-SQUARED_TRIANGULAR_NUMBER_SUM_CUBES",
"pair": "python-java",
"Code1": "def findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n",
"Code2": "static int findS ( int s ) {\n int sum = 0 ;\n for ( int n = 1 ;\n sum < s ;\n n ++ ) {\n sum += n * n * n ;\n if ( sum == s ) return n ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findS ( s ) :\n _sum = 0\n n = 1\n while ( _sum < s ) :\n _sum += n * n * n\n n += 1\n n -= 1\n if _sum == s :\n return n\n return - 1\n\n"
},
{
"id": "python-java-RECURSION",
"pair": "python-java",
"Code1": "def printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n",
"Code2": "static void printFun ( int test ) {\n if ( test < 1 ) return ;\n else {\n System . out . printf ( \"%d \" , test ) ;\n printFun ( test - 1 ) ;\n System . out . printf ( \"%d \" , test ) ;\n return ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printFun ( test ) :\n if ( test < 1 ) :\n return\n else :\n print ( test , end = \" \" )\n printFun ( test - 1 )\n print ( test , end = \" \" )\n return\n\n"
},
{
"id": "python-java-SHIFT_MATRIX_ELEMENTS_K",
"pair": "python-java",
"Code1": "def shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n",
"Code2": "static void shiftMatrixByK ( int [ ] [ ] mat , int k ) {\n if ( k > N ) {\n System . out . print ( \"Shifting is\" + \" not possible\" ) ;\n return ;\n }\n int j = 0 ;\n while ( j < N ) {\n for ( int i = k ;\n i < N ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) System . out . print ( mat [ j ] [ i ] + \" \" ) ;\n System . out . println ( ) ;\n j ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef shiftMatrixByK ( mat , k ) :\n if ( k > N ) :\n print ( \"shifting is\"\" not possible\" )\n return\n j = 0\n while ( j < N ) :\n for i in range ( k , N ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n for i in range ( 0 , k ) :\n print ( \"{} \".format ( mat [ j ] [ i ] ) , end = \"\" )\n print ( \"\" )\n j = j + 1\n\n"
},
{
"id": "python-java-SORTING_USING_TRIVIAL_HASH_FUNCTION_1",
"pair": "python-java",
"Code1": "def sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n",
"Code2": "static void sortUsingHash ( int a [ ] , int n ) {\n int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ;\n int min = Math . abs ( Arrays . stream ( a ) . min ( ) . getAsInt ( ) ) ;\n int hashpos [ ] = new int [ max + 1 ] ;\n int hashneg [ ] = new int [ min + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( a [ i ] >= 0 ) hashpos [ a [ i ] ] += 1 ;\n else hashneg [ Math . abs ( a [ i ] ) ] += 1 ;\n }\n for ( int i = min ;\n i > 0 ;\n i -- ) {\n if ( hashneg [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashneg [ i ] ;\n j ++ ) {\n System . out . print ( ( - 1 ) * i + \" \" ) ;\n }\n }\n }\n for ( int i = 0 ;\n i <= max ;\n i ++ ) {\n if ( hashpos [ i ] > 0 ) {\n for ( int j = 0 ;\n j < hashpos [ i ] ;\n j ++ ) {\n System . out . print ( i + \" \" ) ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortUsingHash ( a , n ) :\n Max = max ( a )\n Min = abs ( min ( a ) )\n hashpos = [ 0 ] * ( Max + 1 )\n hashneg = [ 0 ] * ( Min + 1 )\n for i in range ( 0 , n ) :\n if a [ i ] >= 0 :\n hashpos [ a [ i ] ] += 1\n else :\n hashneg [ abs ( a [ i ] ) ] += 1\n for i in range ( Min , 0 , - 1 ) :\n if hashneg [ i ] != 0 :\n for j in range ( 0 , hashneg [ i ] ) :\n print ( ( - 1 ) * i , end = \" \" )\n for i in range ( 0 , Max + 1 ) :\n if hashpos [ i ] != 0 :\n for j in range ( 0 , hashpos [ i ] ) :\n print ( i , end = \" \" )\n\n"
},
{
"id": "python-java-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY",
"pair": "python-java",
"Code1": "def findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n",
"Code2": "static void findPair ( int [ ] arr , int n ) {\n boolean found = false ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n for ( int k = 0 ;\n k < n ;\n k ++ ) {\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) {\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n found = true ;\n }\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not exist\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findPair ( arr , n ) :\n found = False\n for i in range ( 0 , n ) :\n for j in range ( i + 1 , n ) :\n for k in range ( 0 , n ) :\n if ( arr [ i ] + arr [ j ] == arr [ k ] ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if ( found == False ) :\n print ( \"Not exist\" )\n\n"
},
{
"id": "python-java-FIND_PAIR_MAXIMUM_GCD_ARRAY_1",
"pair": "python-java",
"Code1": "def findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n",
"Code2": "public static int findMaxGCD ( int arr [ ] , int n ) {\n int high = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) high = Math . max ( high , arr [ i ] ) ;\n int count [ ] = new int [ high + 1 ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ arr [ i ] ] ++ ;\n int counter = 0 ;\n for ( int i = high ;\n i >= 1 ;\n i -- ) {\n int j = i ;\n while ( j <= high ) {\n if ( count [ j ] > 0 ) counter += count [ j ] ;\n j += i ;\n if ( counter == 2 ) return i ;\n }\n counter = 0 ;\n }\n return 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxGCD ( arr , n ) :\n high = 0\n for i in range ( 0 , n ) :\n high = max ( high , arr [ i ] )\n count = [ 0 ] * ( high + 1 )\n for i in range ( 0 , n ) :\n count [ arr [ i ] ] += 1\n counter = 0\n for i in range ( high , 0 , - 1 ) :\n j = i\n while ( j <= high ) :\n if ( count [ j ] > 0 ) :\n counter += count [ j ]\n j += i\n if ( counter == 2 ) :\n return i\n counter = 0\n\n"
},
{
"id": "python-java-EULERS_CRITERION_CHECK_IF_SQUARE_ROOT_UNDER_MODULO_P_EXISTS",
"pair": "python-java",
"Code1": "def squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n",
"Code2": "static boolean squareRootExists ( int n , int p ) {\n n = n % p ;\n for ( int x = 2 ;\n x < p ;\n x ++ ) if ( ( x * x ) % p == n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef squareRootExists ( n , p ) :\n n = n % p\n for x in range ( 2 , p , 1 ) :\n if ( ( x * x ) % p == n ) :\n return True\n return False\n\n"
},
{
"id": "python-java-COUNT_ENTRIES_EQUAL_TO_X_IN_A_SPECIAL_MATRIX",
"pair": "python-java",
"Code1": "def count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n",
"Code2": "static int count ( int n , int x ) {\n int count = 0 ;\n for ( int i = 1 ;\n i <= n && i <= x ;\n i ++ ) {\n if ( x / i <= n && x % i == 0 ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef count ( n , x ) :\n cnt = 0\n for i in range ( 1 , n + 1 ) :\n if i <= x :\n if x // i <= n and x % i == 0 :\n cnt += 1\n return cnt\n\n"
},
{
"id": "python-java-SIZE_SUBARRAY_MAXIMUM_SUM",
"pair": "python-java",
"Code1": "def maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n",
"Code2": "static int maxSubArraySum ( int a [ ] , int size ) {\n int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ;\n for ( int i = 0 ;\n i < size ;\n i ++ ) {\n max_ending_here += a [ i ] ;\n if ( max_so_far < max_ending_here ) {\n max_so_far = max_ending_here ;\n start = s ;\n end = i ;\n }\n if ( max_ending_here < 0 ) {\n max_ending_here = 0 ;\n s = i + 1 ;\n }\n }\n return ( end - start + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSubArraySum ( a , size ) :\n max_so_far = - maxsize - 1\n max_ending_here = 0\n start = 0\n end = 0\n s = 0\n for i in range ( 0 , size ) :\n max_ending_here += a [ i ]\n if max_so_far < max_ending_here :\n max_so_far = max_ending_here\n start = s\n end = i\n if max_ending_here < 0 :\n max_ending_here = 0\n s = i + 1\n return ( end - start + 1 )\n\n"
},
{
"id": "python-java-SMALLEST_SUBARRAY_WITH_ALL_OCCURRENCES_OF_A_MOST_FREQUENT_ELEMENT",
"pair": "python-java",
"Code1": "def smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "static void smallestSubsegment ( int a [ ] , int n ) {\n HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ;\n HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ;\n int mx = 0 ;\n int mn = - 1 , strindex = - 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int x = a [ i ] ;\n if ( count . get ( x ) == null ) {\n left . put ( x , i ) ;\n count . put ( x , 1 ) ;\n }\n else count . put ( x , count . get ( x ) + 1 ) ;\n if ( count . get ( x ) > mx ) {\n mx = count . get ( x ) ;\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) {\n mn = i - left . get ( x ) + 1 ;\n strindex = left . get ( x ) ;\n }\n }\n for ( int i = strindex ;\n i < strindex + mn ;\n i ++ ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef smallestSubsegment ( a , n ) :\n left = dict ( )\n count = dict ( )\n mx = 0\n mn , strindex = 0 , 0\n for i in range ( n ) :\n x = a [ i ]\n if ( x not in count.keys ( ) ) :\n left [ x ] = i\n count [ x ] = 1\n else :\n count [ x ] += 1\n if ( count [ x ] > mx ) :\n mx = count [ x ]\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :\n mn = i - left [ x ] + 1\n strindex = left [ x ]\n for i in range ( strindex , strindex + mn ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-FIND_INDEX_MAXIMUM_OCCURRING_ELEMENT_EQUAL_PROBABILITY",
"pair": "python-java",
"Code1": "def findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n",
"Code2": "static void findRandomIndexOfMax ( int arr [ ] , int n ) {\n HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( mp . containsKey ( arr [ i ] ) ) {\n mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ;\n }\n else {\n mp . put ( arr [ i ] , 1 ) ;\n }\n int max_element = Integer . MIN_VALUE ;\n int max_so_far = Integer . MIN_VALUE ;\n for ( Map . Entry < Integer , Integer > p : mp . entrySet ( ) ) {\n if ( p . getValue ( ) > max_so_far ) {\n max_so_far = p . getValue ( ) ;\n max_element = p . getKey ( ) ;\n }\n }\n int r = ( int ) ( ( new Random ( ) . nextInt ( max_so_far ) % max_so_far ) + 1 ) ;\n for ( int i = 0 , count = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] == max_element ) count ++ ;\n if ( count == r ) {\n System . out . print ( \"Element with maximum frequency present \" + \"at index \" + i + \"\\n\" ) ;\n break ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRandomIndexOfMax ( arr , n ) :\n mp = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] in mp ) :\n mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1\n else :\n mp [ arr [ i ] ] = 1\n max_element = - 323567\n max_so_far = - 323567\n for p in mp :\n if ( mp [ p ] > max_so_far ) :\n max_so_far = mp [ p ]\n max_element = p\n r = int ( ( ( random.randrange ( 1 , max_so_far , 2 ) % max_so_far ) + 1 ) )\n i = 0\n count = 0\n while ( i < n ) :\n if ( arr [ i ] == max_element ) :\n count = count + 1\n if ( count == r ) :\n print ( \"Element with maximum frequency present at index \" , i )\n break\n i = i + 1\n\n"
},
{
"id": "python-java-FIND_MINIMUM_RADIUS_ATLEAST_K_POINT_LIE_INSIDE_CIRCLE",
"pair": "python-java",
"Code1": "def minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n",
"Code2": "static int minRadius ( int k , int [ ] x , int [ ] y , int n ) {\n int [ ] dis = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ] ;\n Arrays . sort ( dis ) ;\n return dis [ k - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minRadius ( k , x , y , n ) :\n dis = [ 0 ] * n\n for i in range ( 0 , n ) :\n dis [ i ] = x [ i ] * x [ i ] + y [ i ] * y [ i ]\n dis.sort ( )\n return dis [ k - 1 ]\n\n"
},
{
"id": "python-java-FIND_THE_ELEMENT_THAT_APPEARS_ONCE_2",
"pair": "python-java",
"Code1": "def singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n",
"Code2": "static int singleNumber ( int a [ ] , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( int i : a ) {\n s . add ( i ) ;\n }\n int arr_sum = 0 ;\n for ( int i : a ) {\n arr_sum += i ;\n }\n int set_sum = 0 ;\n for ( int i : s ) {\n set_sum += i ;\n }\n return ( 3 * set_sum - arr_sum ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef singleNumber ( nums ) :\n return ( 3 * sum ( set ( nums ) ) - sum ( nums ) ) / 2\n\n"
},
{
"id": "python-java-QUERIES_COUNTS_ARRAY_ELEMENTS_VALUES_GIVEN_RANGE",
"pair": "python-java",
"Code1": "def countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n",
"Code2": "static int countInRange ( int arr [ ] , int n , int x , int y ) {\n int count = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] >= x && arr [ i ] <= y ) count ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countInRange ( arr , n , x , y ) :\n count = 0 ;\n for i in range ( n ) :\n if ( arr [ i ] >= x and arr [ i ] <= y ) :\n count += 1\n return count\n\n"
},
{
"id": "python-java-FIND_SMALLEST_NUMBER_WITH_GIVEN_NUMBER_OF_DIGITS_AND_DIGIT_SUM",
"pair": "python-java",
"Code1": "def findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n",
"Code2": "static void findSmallest ( int m , int s ) {\n if ( s == 0 ) {\n System . out . print ( m == 1 ? \"Smallest number is 0\" : \"Not possible\" ) ;\n return ;\n }\n if ( s > 9 * m ) {\n System . out . println ( \"Not possible\" ) ;\n return ;\n }\n int [ ] res = new int [ m ] ;\n s -= 1 ;\n for ( int i = m - 1 ;\n i > 0 ;\n i -- ) {\n if ( s > 9 ) {\n res [ i ] = 9 ;\n s -= 9 ;\n }\n else {\n res [ i ] = s ;\n s = 0 ;\n }\n }\n res [ 0 ] = s + 1 ;\n System . out . print ( \"Smallest number is \" ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) System . out . print ( res [ i ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSmallest ( m , s ) :\n if ( s == 0 ) :\n if ( m == 1 ) :\n print ( \"Smallest number is 0\" )\n else :\n print ( \"Not possible\" )\n return\n if ( s > 9 * m ) :\n print ( \"Not possible\" )\n return\n res = [ 0 for i in range ( m + 1 ) ]\n s -= 1\n for i in range ( m - 1 , 0 , - 1 ) :\n if ( s > 9 ) :\n res [ i ] = 9\n s -= 9\n else :\n res [ i ] = s\n s = 0\n res [ 0 ] = s + 1\n print ( \"Smallest number is \" , end = \"\" )\n for i in range ( m ) :\n print ( res [ i ] , end = \"\" )\n\n"
},
{
"id": "python-java-POSSIBILITY_OF_A_WORD_FROM_A_GIVEN_SET_OF_CHARACTERS",
"pair": "python-java",
"Code1": "def isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n",
"Code2": "static boolean isPresent ( String s , String q ) {\n int [ ] freq = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < s . length ( ) ;\n i ++ ) freq [ s . charAt ( i ) ] ++ ;\n for ( int i = 0 ;\n i < q . length ( ) ;\n i ++ ) {\n freq [ q . charAt ( i ) ] -- ;\n if ( freq [ q . charAt ( i ) ] < 0 ) return false ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPresent ( s , q ) :\n freq = [ 0 ] * MAX_CHAR\n for i in range ( 0 , len ( s ) ) :\n freq [ ord ( s [ i ] ) ] += 1\n for i in range ( 0 , len ( q ) ) :\n freq [ ord ( q [ i ] ) ] -= 1\n if ( freq [ ord ( q [ i ] ) ] < 0 ) :\n return False\n return True\n\n"
},
{
"id": "python-java-SORT_ARRAY_APPLYING_GIVEN_EQUATION",
"pair": "python-java",
"Code1": "def sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n",
"Code2": "static void sortArray ( int arr [ ] , int n , int A , int B , int C ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ;\n int index = - 1 ;\n int maximum = - 999999 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( maximum < arr [ i ] ) {\n index = i ;\n maximum = arr [ i ] ;\n }\n }\n int i = 0 , j = n - 1 ;\n int [ ] new_arr = new int [ n ] ;\n int k = 0 ;\n while ( i < index && j > index ) {\n if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ;\n else new_arr [ k ++ ] = arr [ j -- ] ;\n }\n while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ;\n while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ;\n new_arr [ n - 1 ] = maximum ;\n for ( int p = 0 ;\n p < n ;\n p ++ ) arr [ p ] = new_arr [ p ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortArray ( arr , n , A , B , C ) :\n for i in range ( n ) :\n arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C )\n index = - ( sys.maxsize - 1 )\n maximum = - ( sys.maxsize - 1 )\n for i in range ( n ) :\n if maximum < arr [ i ] :\n index = i\n maximum = arr [ i ]\n i = 0 j = n - 1\n new_arr = [ 0 ] * n\n k = 0\n while i < index and j > index :\n if arr [ i ] < arr [ j ] :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n else :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n while i < index :\n new_arr [ k ] = arr [ i ]\n k += 1\n i += 1\n while j > index :\n new_arr [ k ] = arr [ j ]\n k += 1\n j -= 1\n new_arr [ n - 1 ] = maximum\n for i in range ( n ) :\n arr [ i ] = new_arr [ i ]\n\n"
},
{
"id": "python-java-DISTANCE_NEAREST_CELL_1_BINARY_MATRIX",
"pair": "python-java",
"Code1": "def printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n",
"Code2": "static void printDistance ( int mat [ ] [ ] ) {\n int ans [ ] [ ] = new int [ N ] [ M ] ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) ans [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < M ;\n j ++ ) {\n for ( int k = 0 ;\n k < N ;\n k ++ ) for ( int l = 0 ;\n l < M ;\n l ++ ) {\n if ( mat [ k ] [ l ] == 1 ) ans [ i ] [ j ] = Math . min ( ans [ i ] [ j ] , Math . abs ( i - k ) + Math . abs ( j - l ) ) ;\n }\n }\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n for ( int j = 0 ;\n j < M ;\n j ++ ) System . out . print ( ans [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printDistance ( mat ) :\n global N , M\n ans = [ [ None ] * M for i in range ( N ) ]\n for i in range ( N ) :\n for j in range ( M ) :\n ans [ i ] [ j ] = 999999999999\n for i in range ( N ) :\n for j in range ( M ) :\n for k in range ( N ) :\n for l in range ( M ) :\n if ( mat [ k ] [ l ] == 1 ) :\n ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )\n for i in range ( N ) :\n for j in range ( M ) :\n print ( ans [ i ] [ j ] , end = \" \" )\n print ( )\n\n"
},
{
"id": "python-java-FIND_LAST_INDEX_CHARACTER_STRING",
"pair": "python-java",
"Code1": "def findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n",
"Code2": "static int findLastIndex ( String str , Character x ) {\n int index = - 1 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) if ( str . charAt ( i ) == x ) index = i ;\n return index ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLastIndex ( str , x ) :\n index = - 1\n for i in range ( 0 , len ( str ) ) :\n if str [ i ] == x :\n index = i\n return index\n\n"
},
{
"id": "python-java-PRINT_TRIPLETS_SORTED_ARRAY_FORM_AP",
"pair": "python-java",
"Code1": "def printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n",
"Code2": "static void printAllAPTriplets ( int [ ] arr , int n ) {\n ArrayList < Integer > s = new ArrayList < Integer > ( ) ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int diff = arr [ j ] - arr [ i ] ;\n boolean exists = s . contains ( arr [ i ] - diff ) ;\n if ( exists ) System . out . println ( arr [ i ] - diff + \" \" + arr [ i ] + \" \" + arr [ j ] ) ;\n }\n s . add ( arr [ i ] ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printAllAPTriplets ( arr , n ) :\n s = [ ]\n for i in range ( 0 , n - 1 ) :\n for j in range ( i + 1 , n ) :\n diff = arr [ j ] - arr [ i ]\n if ( ( arr [ i ] - diff ) in arr ) :\n print ( \"{} {} {}\".format ( ( arr [ i ] - diff ) , arr [ i ] , arr [ j ] ) , end = \"\\n\" )\n s.append ( arr [ i ] )\n\n"
},
{
"id": "python-java-REMOVE_BRACKETS_ALGEBRAIC_STRING_CONTAINING_OPERATORS",
"pair": "python-java",
"Code1": "def simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n",
"Code2": "static String simplify ( String str ) {\n int len = str . length ( ) ;\n char res [ ] = new char [ len ] ;\n int index = 0 , i = 0 ;\n Stack < Integer > s = new Stack < Integer > ( ) ;\n s . push ( 0 ) ;\n while ( i < len ) {\n if ( str . charAt ( i ) == ' + ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' - ' ;\n if ( s . peek ( ) == 0 ) res [ index ++ ] = ' + ' ;\n }\n else if ( str . charAt ( i ) == ' - ' ) {\n if ( s . peek ( ) == 1 ) res [ index ++ ] = ' + ' ;\n else if ( s . peek ( ) == 0 ) res [ index ++ ] = ' - ' ;\n }\n else if ( str . charAt ( i ) == ' ( ' && i > 0 ) {\n if ( str . charAt ( i - 1 ) == ' - ' ) {\n int x = ( s . peek ( ) == 1 ) ? 0 : 1 ;\n s . push ( x ) ;\n }\n else if ( str . charAt ( i - 1 ) == ' + ' ) s . push ( s . peek ( ) ) ;\n }\n else if ( str . charAt ( i ) == ' ) ' ) s . pop ( ) ;\n else res [ index ++ ] = str . charAt ( i ) ;\n i ++ ;\n }\n return new String ( res ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef simplify ( Str ) :\n Len = len ( Str )\n res = [ None ] * Len\n index = 0\n i = 0\n s = [ ]\n s.append ( 0 )\n while ( i < Len ) :\n if ( Str [ i ] == '+' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '-'\n index += 1\n if ( s [ - 1 ] == 0 ) :\n res [ index ] = '+'\n index += 1\n elif ( Str [ i ] == '-' ) :\n if ( s [ - 1 ] == 1 ) :\n res [ index ] = '+'\n index += 1\n elif ( s [ - 1 ] == 0 ) :\n res [ index ] = '-'\n index += 1\n elif ( Str [ i ] == '(' and i > 0 ) :\n if ( Str [ i - 1 ] == '-' ) :\n x = 0 if ( s [ - 1 ] == 1 ) else 1\n s.append ( x )\n elif ( Str [ i - 1 ] == '+' ) :\n s.append ( s [ - 1 ] )\n elif ( Str [ i ] == ')' ) :\n s.pop ( )\n else :\n res [ index ] = Str [ i ]\n index += 1\n i += 1\n return res\n\n"
},
{
"id": "python-java-CALCULATE_VOLUME_DODECAHEDRON",
"pair": "python-java",
"Code1": "def vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n",
"Code2": "static double vol_of_dodecahedron ( int side ) {\n return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef vol_of_dodecahedron ( side ) :\n return ( ( ( 15 + ( 7 * ( math.sqrt ( 5 ) ) ) ) / 4 ) * ( math.pow ( side , 3 ) ) )\n\n"
},
{
"id": "python-java-WAYS_TRANSFORMING_ONE_STRING_REMOVING_0_CHARACTERS",
"pair": "python-java",
"Code1": "def countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n",
"Code2": "static int countTransformation ( String a , String b ) {\n int n = a . length ( ) , m = b . length ( ) ;\n if ( m == 0 ) {\n return 1 ;\n }\n int dp [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( i == 0 ) {\n if ( j == 0 ) {\n dp [ i ] [ j ] = ( a . charAt ( j ) == b . charAt ( i ) ) ? 1 : 0 ;\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1 ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n else if ( a . charAt ( j ) == b . charAt ( i ) ) {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] ;\n }\n else {\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] ;\n }\n }\n }\n return dp [ m - 1 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countTransformation ( a , b ) :\n n = len ( a )\n m = len ( b )\n if m == 0 :\n return 1\n dp = [ [ 0 ] * ( n + 1 ) for _ in range ( m + 1 ) ]\n for i in range ( m ) :\n for j in range ( i , n ) :\n if i == 0 :\n if j == 0 :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = 1\n else :\n dp [ i ] [ j ] = 0\n elif a [ j ] == b [ i ] :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n else :\n if a [ j ] == b [ i ] :\n dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )\n else :\n dp [ i ] [ j ] = dp [ i ] [ j - 1 ]\n return dp [ m - 1 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-SUM_NODES_K_TH_LEVEL_TREE_REPRESENTED_STRING_1",
"pair": "python-java",
"Code1": "def sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n",
"Code2": "static int sumAtKthLevel ( String tree , int k , int level ) {\n if ( tree . charAt ( i ++ ) == ' ( ' ) {\n if ( tree . charAt ( i ) == ' ) ' ) return 0 ;\n int sum = 0 ;\n if ( level == k ) sum = tree . charAt ( i ) - ' 0 ' ;\n ++ i ;\n int leftsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n int rightsum = sumAtKthLevel ( tree , k , level + 1 ) ;\n ++ i ;\n return sum + leftsum + rightsum ;\n }\n return Integer . MIN_VALUE ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumAtKthLevel ( tree , k , i , level ) :\n if ( tree [ i [ 0 ] ] == '(' ) :\n i [ 0 ] += 1\n if ( tree [ i [ 0 ] ] == ')' ) :\n return 0\n sum = 0\n if ( level == k ) :\n sum = int ( tree [ i [ 0 ] ] )\n i [ 0 ] += 1\n leftsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n rightsum = sumAtKthLevel ( tree , k , i , level + 1 )\n i [ 0 ] += 1\n return sum + leftsum + rightsum\n\n"
},
{
"id": "python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_1",
"pair": "python-java",
"Code1": "def printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int count [ ] = new int [ size ] ;\n int i ;\n System . out . println ( \"Repeated elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( count [ arr [ i ] ] == 1 ) System . out . print ( arr [ i ] + \" \" ) ;\n else count [ arr [ i ] ] ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n count = [ 0 ] * size\n print ( \" Repeating elements are \" , end = \"\" )\n for i in range ( 0 , size ) :\n if ( count [ arr [ i ] ] == 1 ) :\n print ( arr [ i ] , end = \" \" )\n else :\n count [ arr [ i ] ] = count [ arr [ i ] ] + 1\n\n"
},
{
"id": "python-java-COUNT_PAIRS_DIFFERENCE_EQUAL_K_1",
"pair": "python-java",
"Code1": "def countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n",
"Code2": "static int countPairsWithDiffK ( int arr [ ] , int n , int k ) {\n int count = 0 ;\n Arrays . sort ( arr ) ;\n int l = 0 ;\n int r = 0 ;\n while ( r < n ) {\n if ( arr [ r ] - arr [ l ] == k ) {\n count ++ ;\n l ++ ;\n r ++ ;\n }\n else if ( arr [ r ] - arr [ l ] > k ) l ++ ;\n else r ++ ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairsWithDiffK ( arr , n , k ) :\n count = 0\n arr.sort ( )\n l = 0\n r = 0\n while r < n :\n if arr [ r ] - arr [ l ] == k :\n count += 1\n l += 1\n r += 1\n elif arr [ r ] - arr [ l ] > k :\n l += 1\n else :\n r += 1\n return count\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SUBSET_SUM_PROBLEM_1",
"pair": "python-java",
"Code1": "def isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n",
"Code2": "static boolean isSubsetSum ( int set [ ] , int n , int sum ) {\n boolean subset [ ] [ ] = new boolean [ sum + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) subset [ 0 ] [ i ] = true ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) subset [ i ] [ 0 ] = false ;\n for ( int i = 1 ;\n i <= sum ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n subset [ i ] [ j ] = subset [ i ] [ j - 1 ] ;\n if ( i >= set [ j - 1 ] ) subset [ i ] [ j ] = subset [ i ] [ j ] || subset [ i - set [ j - 1 ] ] [ j - 1 ] ;\n }\n }\n return subset [ sum ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSubsetSum ( set , n , sum ) :\n subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )\n for i in range ( n + 1 ) :\n subset [ i ] [ 0 ] = True\n for i in range ( 1 , sum + 1 ) :\n subset [ 0 ] [ i ] = False\n for i in range ( 1 , n + 1 ) :\n for j in range ( 1 , sum + 1 ) :\n if j < set [ i - 1 ] :\n subset [ i ] [ j ] = subset [ i - 1 ] [ j ]\n if j >= set [ i - 1 ] :\n subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )\n return subset [ n ] [ sum ]\n\n"
},
{
"id": "python-java-MAJORITY_ELEMENT_1",
"pair": "python-java",
"Code1": "def findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n",
"Code2": "private static void findMajority ( int [ ] arr ) {\n HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ;\n for ( int i = 0 ;\n i < arr . length ;\n i ++ ) {\n if ( map . containsKey ( arr [ i ] ) ) {\n int count = map . get ( arr [ i ] ) + 1 ;\n if ( count > arr . length / 2 ) {\n System . out . println ( \"Majority found :- \" + arr [ i ] ) ;\n return ;\n }\n else map . put ( arr [ i ] , count ) ;\n }\n else map . put ( arr [ i ] , 1 ) ;\n }\n System . out . println ( \" No Majority element\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMajority ( arr , size ) :\n m = { }\n for i in range ( size ) :\n if arr [ i ] in m :\n m [ arr [ i ] ] += 1\n else :\n m [ arr [ i ] ] = 1\n count = 0\n for key in m :\n if m [ key ] > size / 2 :\n count = 1\n print ( \"Majority found :-\" , key )\n break\n if ( count == 0 ) :\n print ( \"No Majority element\" )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_10_0_1_KNAPSACK_PROBLEM",
"pair": "python-java",
"Code1": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n\n"
},
{
"id": "python-java-PRINT_REVERSE_STRING_REMOVING_VOWELS",
"pair": "python-java",
"Code1": "def replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n",
"Code2": "static void replaceOriginal ( String s , int n ) {\n char r [ ] = new char [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n r [ i ] = s . charAt ( n - 1 - i ) ;\n if ( s . charAt ( i ) != ' a ' && s . charAt ( i ) != ' e ' && s . charAt ( i ) != ' i ' && s . charAt ( i ) != ' o ' && s . charAt ( i ) != ' u ' ) {\n System . out . print ( r [ i ] ) ;\n }\n }\n System . out . println ( \"\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef replaceOriginal ( s , n ) :\n r = [ ' ' ] * n\n for i in range ( n ) :\n r [ i ] = s [ n - 1 - i ]\n if ( s [ i ] != 'a' and s [ i ] != 'e' and s [ i ] != 'i' and s [ i ] != 'o' and s [ i ] != 'u' ) :\n print ( r [ i ] , end = \"\" )\n print ( )\n\n"
},
{
"id": "python-java-FIND_PAIRS_IN_ARRAY_WHOSE_SUMS_ALREADY_EXIST_IN_ARRAY_1",
"pair": "python-java",
"Code1": "def findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n",
"Code2": "public static void findPair ( int [ ] arr , int n ) {\n HashSet < Integer > s = new HashSet < Integer > ( ) ;\n for ( Integer i : arr ) {\n s . add ( i ) ;\n }\n boolean found = false ;\n for ( int i = 0 ;\n i < n - 1 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < n ;\n j ++ ) {\n int sum = arr [ i ] + arr [ j ] ;\n if ( s . contains ( sum ) ) {\n found = true ;\n System . out . println ( arr [ i ] + \" \" + arr [ j ] ) ;\n }\n }\n }\n if ( found == false ) System . out . println ( \"Not Exist \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findPair ( arr , n ) :\n s = { i : 1 for i in arr }\n found = False\n for i in range ( n ) :\n for j in range ( i + 1 , n ) :\n if arr [ i ] + arr [ j ] in s.keys ( ) :\n print ( arr [ i ] , arr [ j ] )\n found = True\n if found == False :\n print ( \"Not exist\" )\n\n"
},
{
"id": "python-java-NUMBER_SUBSTRINGS_STRING",
"pair": "python-java",
"Code1": "def countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n",
"Code2": "static int countNonEmptySubstr ( String str ) {\n int n = str . length ( ) ;\n return n * ( n + 1 ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countNonEmptySubstr ( str ) :\n n = len ( str )\n return int ( n * ( n + 1 ) / 2 )\n\n"
},
{
"id": "python-java-NUMBER_DIGITS_PRODUCT_TWO_NUMBERS",
"pair": "python-java",
"Code1": "def countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n",
"Code2": "static int countDigits ( int a , int b ) {\n int count = 0 ;\n int p = Math . abs ( a * b ) ;\n if ( p == 0 ) return 1 ;\n while ( p > 0 ) {\n count ++ ;\n p = p / 10 ;\n }\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDigits ( a , b ) :\n count = 0\n p = abs ( a * b )\n if ( p == 0 ) :\n return 1\n while ( p > 0 ) :\n count = count + 1\n p = p // 10\n return count\n\n"
},
{
"id": "python-java-MAXIMUM_PROFIT_BY_BUYING_AND_SELLING_A_SHARE_AT_MOST_TWICE",
"pair": "python-java",
"Code1": "def maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n",
"Code2": "static int maxProfit ( int price [ ] , int n ) {\n int profit [ ] = new int [ n ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) profit [ i ] = 0 ;\n int max_price = price [ n - 1 ] ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( price [ i ] > max_price ) max_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i + 1 ] , max_price - price [ i ] ) ;\n }\n int min_price = price [ 0 ] ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( price [ i ] < min_price ) min_price = price [ i ] ;\n profit [ i ] = Math . max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) ) ;\n }\n int result = profit [ n - 1 ] ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProfit ( price , n ) :\n profit = [ 0 ] * n\n max_price = price [ n - 1 ]\n for i in range ( n - 2 , 0 , - 1 ) :\n if price [ i ] > max_price :\n max_price = price [ i ]\n profit [ i ] = max ( profit [ i + 1 ] , max_price - price [ i ] )\n min_price = price [ 0 ]\n for i in range ( 1 , n ) :\n if price [ i ] < min_price :\n min_price = price [ i ]\n profit [ i ] = max ( profit [ i - 1 ] , profit [ i ] + ( price [ i ] - min_price ) )\n result = profit [ n - 1 ]\n return result\n\n"
},
{
"id": "python-java-COUNT_DERANGEMENTS_PERMUTATION_SUCH_THAT_NO_ELEMENT_APPEARS_IN_ITS_ORIGINAL_POSITION_1",
"pair": "python-java",
"Code1": "def countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n",
"Code2": "static int countDer ( int n ) {\n int der [ ] = new int [ n + 1 ] ;\n der [ 0 ] = 1 ;\n der [ 1 ] = 0 ;\n der [ 2 ] = 1 ;\n for ( int i = 3 ;\n i <= n ;\n ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ;\n return der [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countDer ( n ) :\n der = [ 0 for i in range ( n + 1 ) ]\n der [ 0 ] = 1\n der [ 1 ] = 0\n der [ 2 ] = 1\n for i in range ( 3 , n + 1 ) :\n der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] )\n return der [ n ]\n\n"
},
{
"id": "python-java-MAXIMUM_PATH_SUM_MATRIX",
"pair": "python-java",
"Code1": "def findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n",
"Code2": "static int findMaxPath ( int mat [ ] [ ] ) {\n int res = - 1 ;\n for ( int i = 0 ;\n i < M ;\n i ++ ) res = max ( res , mat [ 0 ] [ i ] ) ;\n for ( int i = 1 ;\n i < N ;\n i ++ ) {\n res = - 1 ;\n for ( int j = 0 ;\n j < M ;\n j ++ ) {\n if ( j > 0 && j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) ) ;\n else if ( j > 0 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] ) ;\n else if ( j < M - 1 ) mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] ) ;\n res = max ( mat [ i ] [ j ] , res ) ;\n }\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMaxPath ( mat ) :\n res = - 1\n for i in range ( M ) :\n res = max ( res , mat [ 0 ] [ i ] )\n for i in range ( 1 , N ) :\n res = - 1\n for j in range ( M ) :\n if ( j > 0 and j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , max ( mat [ i - 1 ] [ j - 1 ] , mat [ i - 1 ] [ j + 1 ] ) )\n elif ( j > 0 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j - 1 ] )\n elif ( j < M - 1 ) :\n mat [ i ] [ j ] += max ( mat [ i - 1 ] [ j ] , mat [ i - 1 ] [ j + 1 ] )\n res = max ( mat [ i ] [ j ] , res )\n return res\n\n"
},
{
"id": "python-java-CHECK_WHETHER_ARITHMETIC_PROGRESSION_CAN_FORMED_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n",
"Code2": "static boolean checkIsAP ( int arr [ ] , int n ) {\n if ( n == 1 ) return true ;\n Arrays . sort ( arr ) ;\n int d = arr [ 1 ] - arr [ 0 ] ;\n for ( int i = 2 ;\n i < n ;\n i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkIsAP ( arr , n ) :\n if ( n == 1 ) : return True\n arr.sort ( )\n d = arr [ 1 ] - arr [ 0 ]\n for i in range ( 2 , n ) :\n if ( arr [ i ] - arr [ i - 1 ] != d ) :\n return False\n return True\n\n"
},
{
"id": "python-java-CHECK_LARGE_NUMBER_DIVISIBLE_11_NOT",
"pair": "python-java",
"Code1": "def check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n int oddDigSum = 0 , evenDigSum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 == 0 ) oddDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n else evenDigSum += ( str . charAt ( i ) - ' 0 ' ) ;\n }\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n oddDigSum = 0\n evenDigSum = 0\n for i in range ( 0 , n ) :\n if ( i % 2 == 0 ) :\n oddDigSum = oddDigSum + ( ( int ) ( st [ i ] ) )\n else :\n evenDigSum = evenDigSum + ( ( int ) ( st [ i ] ) )\n return ( ( oddDigSum - evenDigSum ) % 11 == 0 )\n\n"
},
{
"id": "python-java-SWAP_TWO_NUMBERS_WITHOUT_USING_TEMPORARY_VARIABLE",
"pair": "python-java",
"Code1": "def swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n",
"Code2": "static void swap ( int [ ] xp , int [ ] yp ) {\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef swap ( xp , yp ) :\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n yp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n xp [ 0 ] = xp [ 0 ] ^ yp [ 0 ]\n\n"
},
{
"id": "python-java-AREA_SQUARE_CIRCUMSCRIBED_CIRCLE",
"pair": "python-java",
"Code1": "def find_Area ( r ) :\n return ( 2 * r * r )\n",
"Code2": "static int find_Area ( int r ) {\n return ( 2 * r * r ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find_Area ( r ) :\n return ( 2 * r * r )\n\n"
},
{
"id": "python-java-PROGRAM_TO_CHECK_IF_A_GIVEN_NUMBER_IS_LUCKY_ALL_DIGITS_ARE_DIFFERENT",
"pair": "python-java",
"Code1": "def isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n",
"Code2": "static boolean isLucky ( int n ) {\n boolean arr [ ] = new boolean [ 10 ] ;\n for ( int i = 0 ;\n i < 10 ;\n i ++ ) arr [ i ] = false ;\n while ( n > 0 ) {\n int digit = n % 10 ;\n if ( arr [ digit ] ) return false ;\n arr [ digit ] = true ;\n n = n / 10 ;\n }\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isLucky ( n ) :\n ar = [ 0 ] * 10\n while ( n > 0 ) :\n digit = math.floor ( n % 10 )\n if ( ar [ digit ] ) :\n return 0\n ar [ digit ] = 1\n n = n / 10\n return 1\n\n"
},
{
"id": "python-java-COUNT_NUMBER_WAYS_JUMP_REACH_END",
"pair": "python-java",
"Code1": "def countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n",
"Code2": "static void countWaysToJump ( int arr [ ] , int n ) {\n int count_jump [ ] = new int [ n ] ;\n Arrays . fill ( count_jump , 0 ) ;\n for ( int i = n - 2 ;\n i >= 0 ;\n i -- ) {\n if ( arr [ i ] >= n - i - 1 ) count_jump [ i ] ++ ;\n for ( int j = i + 1 ;\n j < n - 1 && j <= arr [ i ] + i ;\n j ++ ) if ( count_jump [ j ] != - 1 ) count_jump [ i ] += count_jump [ j ] ;\n if ( count_jump [ i ] == 0 ) count_jump [ i ] = - 1 ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( count_jump [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countWaysToJump ( arr , n ) :\n count_jump = [ 0 for i in range ( n ) ]\n for i in range ( n - 2 , - 1 , - 1 ) :\n if ( arr [ i ] >= n - i - 1 ) :\n count_jump [ i ] += 1\n j = i + 1\n while ( j < n - 1 and j <= arr [ i ] + i ) :\n if ( count_jump [ j ] != - 1 ) :\n count_jump [ i ] += count_jump [ j ]\n j += 1\n if ( count_jump [ i ] == 0 ) :\n count_jump [ i ] = - 1\n for i in range ( n ) :\n print ( count_jump [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-PROGRAM_DISPLAY_ASTROLOGICAL_SIGN_ZODIAC_SIGN_GIVEN_DATE_BIRTH",
"pair": "python-java",
"Code1": "def zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n",
"Code2": "static void zodiac_sign ( int day , String month ) {\n String astro_sign = \"\" ;\n if ( month == \"december\" ) {\n if ( day < 22 ) astro_sign = \"Sagittarius\" ;\n else astro_sign = \"capricorn\" ;\n }\n else if ( month == \"january\" ) {\n if ( day < 20 ) astro_sign = \"Capricorn\" ;\n else astro_sign = \"aquarius\" ;\n }\n else if ( month == \"february\" ) {\n if ( day < 19 ) astro_sign = \"Aquarius\" ;\n else astro_sign = \"pisces\" ;\n }\n else if ( month == \"march\" ) {\n if ( day < 21 ) astro_sign = \"Pisces\" ;\n else astro_sign = \"aries\" ;\n }\n else if ( month == \"april\" ) {\n if ( day < 20 ) astro_sign = \"Aries\" ;\n else astro_sign = \"taurus\" ;\n }\n else if ( month == \"may\" ) {\n if ( day < 21 ) astro_sign = \"Taurus\" ;\n else astro_sign = \"gemini\" ;\n }\n else if ( month == \"june\" ) {\n if ( day < 21 ) astro_sign = \"Gemini\" ;\n else astro_sign = \"cancer\" ;\n }\n else if ( month == \"july\" ) {\n if ( day < 23 ) astro_sign = \"Cancer\" ;\n else astro_sign = \"leo\" ;\n }\n else if ( month == \"august\" ) {\n if ( day < 23 ) astro_sign = \"Leo\" ;\n else astro_sign = \"virgo\" ;\n }\n else if ( month == \"september\" ) {\n if ( day < 23 ) astro_sign = \"Virgo\" ;\n else astro_sign = \"libra\" ;\n }\n else if ( month == \"october\" ) {\n if ( day < 23 ) astro_sign = \"Libra\" ;\n else astro_sign = \"scorpio\" ;\n }\n else if ( month == \"november\" ) {\n if ( day < 22 ) astro_sign = \"scorpio\" ;\n else astro_sign = \"sagittarius\" ;\n }\n System . out . println ( astro_sign ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef zodiac_sign ( day , month ) :\n if month == 'december' :\n astro_sign = 'Sagittarius' if ( day < 22 ) else 'capricorn'\n elif month == 'january' :\n astro_sign = 'Capricorn' if ( day < 20 ) else 'aquarius'\n elif month == 'february' :\n astro_sign = 'Aquarius' if ( day < 19 ) else 'pisces'\n elif month == 'march' :\n astro_sign = 'Pisces' if ( day < 21 ) else 'aries'\n elif month == 'april' :\n astro_sign = 'Aries' if ( day < 20 ) else 'taurus'\n elif month == 'may' :\n astro_sign = 'Taurus' if ( day < 21 ) else 'gemini'\n elif month == 'june' :\n astro_sign = 'Gemini' if ( day < 21 ) else 'cancer'\n elif month == 'july' :\n astro_sign = 'Cancer' if ( day < 23 ) else 'leo'\n elif month == 'august' :\n astro_sign = 'Leo' if ( day < 23 ) else 'virgo'\n elif month == 'september' :\n astro_sign = 'Virgo' if ( day < 23 ) else 'libra'\n elif month == 'october' :\n astro_sign = 'Libra' if ( day < 23 ) else 'scorpio'\n elif month == 'november' :\n astro_sign = 'scorpio' if ( day < 22 ) else 'sagittarius'\n print ( astro_sign )\n\n"
},
{
"id": "python-java-FIND_NUMBER_OF_SOLUTIONS_OF_A_LINEAR_EQUATION_OF_N_VARIABLES_1",
"pair": "python-java",
"Code1": "def countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n",
"Code2": "static int countSol ( int coeff [ ] , int n , int rhs ) {\n int dp [ ] = new int [ rhs + 1 ] ;\n Arrays . fill ( dp , 0 ) ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = coeff [ i ] ;\n j <= rhs ;\n j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ;\n return dp [ rhs ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSol ( coeff , n , rhs ) :\n dp = [ 0 for i in range ( rhs + 1 ) ]\n dp [ 0 ] = 1\n for i in range ( n ) :\n for j in range ( coeff [ i ] , rhs + 1 ) :\n dp [ j ] += dp [ j - coeff [ i ] ]\n return dp [ rhs ]\n\n"
},
{
"id": "python-java-PROGRAM_TO_CHECK_IF_A_MATRIX_IS_SYMMETRIC",
"pair": "python-java",
"Code1": "def isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n",
"Code2": "static boolean isSymmetric ( int mat [ ] [ ] , int N ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isSymmetric ( mat , N ) :\n for i in range ( N ) :\n for j in range ( N ) :\n if ( mat [ i ] [ j ] != mat [ j ] [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-java-FIND_RECTANGLE_BINARY_MATRIX_CORNERS_1",
"pair": "python-java",
"Code1": "def isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n",
"Code2": "static boolean isRectangle ( int m [ ] [ ] ) {\n int rows = m . length ;\n if ( rows == 0 ) return false ;\n int columns = m [ 0 ] . length ;\n for ( int y1 = 0 ;\n y1 < rows ;\n y1 ++ ) for ( int x1 = 0 ;\n x1 < columns ;\n x1 ++ ) if ( m [ y1 ] [ x1 ] == 1 ) for ( int y2 = y1 + 1 ;\n y2 < rows ;\n y2 ++ ) for ( int x2 = x1 + 1 ;\n x2 < columns ;\n x2 ++ ) if ( m [ y1 ] [ x2 ] == 1 && m [ y2 ] [ x1 ] == 1 && m [ y2 ] [ x2 ] == 1 ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isRectangle ( m ) :\n rows = len ( m )\n if ( rows == 0 ) :\n return False\n columns = len ( m [ 0 ] )\n for y1 in range ( rows ) :\n for x1 in range ( columns ) :\n if ( m [ y1 ] [ x1 ] == 1 ) :\n for y2 in range ( y1 + 1 , rows ) :\n for x2 in range ( x1 + 1 , columns ) :\n if ( m [ y1 ] [ x2 ] == 1 and m [ y2 ] [ x1 ] == 1 and m [ y2 ] [ x2 ] == 1 ) :\n return True\n return False\n\n"
},
{
"id": "python-java-DIVISIBILITY_9_USING_BITWISE_OPERATORS",
"pair": "python-java",
"Code1": "def isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n",
"Code2": "static boolean isDivBy9 ( int n ) {\n if ( n == 0 || n == 9 ) return true ;\n if ( n < 9 ) return false ;\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDivBy9 ( n ) :\n if ( n == 0 or n == 9 ) :\n return True\n if ( n < 9 ) :\n return False\n return isDivBy9 ( ( int ) ( n >> 3 ) - ( int ) ( n & 7 ) )\n\n"
},
{
"id": "python-java-KNAPSACK_PROBLEM",
"pair": "python-java",
"Code1": "def knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n",
"Code2": "static int knapSack ( int W , int wt [ ] , int val [ ] , int n ) {\n if ( n == 0 || W == 0 ) return 0 ;\n if ( wt [ n - 1 ] > W ) return knapSack ( W , wt , val , n - 1 ) ;\n else return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef knapSack ( W , wt , val , n ) :\n if n == 0 or W == 0 :\n return 0\n if ( wt [ n - 1 ] > W ) :\n return knapSack ( W , wt , val , n - 1 )\n else :\n return max ( val [ n - 1 ] + knapSack ( W - wt [ n - 1 ] , wt , val , n - 1 ) , knapSack ( W , wt , val , n - 1 ) )\n\n"
},
{
"id": "python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_2",
"pair": "python-java",
"Code1": "def printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int xor = arr [ 0 ] ;\n int set_bit_no ;\n int i ;\n int n = size - 2 ;\n int x = 0 , y = 0 ;\n for ( i = 1 ;\n i < size ;\n i ++ ) xor ^= arr [ i ] ;\n for ( i = 1 ;\n i <= n ;\n i ++ ) xor ^= i ;\n set_bit_no = ( xor & ~ ( xor - 1 ) ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n int a = arr [ i ] & set_bit_no ;\n if ( a != 0 ) x = x ^ arr [ i ] ;\n else y = y ^ arr [ i ] ;\n }\n for ( i = 1 ;\n i <= n ;\n i ++ ) {\n int a = i & set_bit_no ;\n if ( a != 0 ) x = x ^ i ;\n else y = y ^ i ;\n }\n System . out . println ( \"The two reppeated elements are :\" ) ;\n System . out . println ( x + \" \" + y ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n xor = arr [ 0 ]\n n = size - 2\n x = 0\n y = 0\n for i in range ( 1 , size ) :\n xor ^= arr [ i ]\n for i in range ( 1 , n + 1 ) :\n xor ^= i\n set_bit_no = xor & ~ ( xor - 1 )\n for i in range ( 0 , size ) :\n if ( arr [ i ] & set_bit_no ) :\n x = x ^ arr [ i ]\n else :\n y = y ^ arr [ i ]\n for i in range ( 1 , n + 1 ) :\n if ( i & set_bit_no ) :\n x = x ^ i\n else :\n y = y ^ i\n print ( \"The two repeating\" , \"elements are\" , y , x )\n\n"
},
{
"id": "python-java-COUNT_DISTINCT_OCCURRENCES_AS_A_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n",
"Code2": "static int findSubsequenceCount ( String S , String T ) {\n int m = T . length ( ) ;\n int n = S . length ( ) ;\n if ( m > n ) return 0 ;\n int mat [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) mat [ i ] [ 0 ] = 0 ;\n for ( int j = 0 ;\n j <= n ;\n j ++ ) mat [ 0 ] [ j ] = 1 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n for ( int j = 1 ;\n j <= n ;\n j ++ ) {\n if ( T . charAt ( i - 1 ) != S . charAt ( j - 1 ) ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ] ;\n else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] ;\n }\n }\n return mat [ m ] [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSubsequenceCount ( S , T ) :\n m = len ( T )\n n = len ( S )\n if m > n :\n return 0\n mat = [ [ 0 for _ in range ( n + 1 ) ] for __ in range ( m + 1 ) ]\n for i in range ( 1 , m + 1 ) :\n mat [ i ] [ 0 ] = 0\n for j in range ( n + 1 ) :\n mat [ 0 ] [ j ] = 1\n for i in range ( 1 , m + 1 ) :\n for j in range ( 1 , n + 1 ) :\n if T [ i - 1 ] != S [ j - 1 ] :\n mat [ i ] [ j ] = mat [ i ] [ j - 1 ]\n else :\n mat [ i ] [ j ] = ( mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ] )\n return mat [ m ] [ n ]\n\n"
},
{
"id": "python-java-RECURSIVELY_BREAK_NUMBER_3_PARTS_GET_MAXIMUM_SUM_1",
"pair": "python-java",
"Code1": "def breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n",
"Code2": "static int breakSum ( int n ) {\n int dp [ ] = new int [ n + 1 ] ;\n dp [ 0 ] = 0 ;\n dp [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ;\n return dp [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef breakSum ( n ) :\n dp = [ 0 ] * ( n + 1 )\n dp [ 0 ] = 0\n dp [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n dp [ i ] = max ( dp [ int ( i / 2 ) ] + dp [ int ( i / 3 ) ] + dp [ int ( i / 4 ) ] , i )\n return dp [ n ]\n\n"
},
{
"id": "python-java-PROGRAM_DECIMAL_HEXADECIMAL_CONVERSION",
"pair": "python-java",
"Code1": "def decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n",
"Code2": "static void decToHexa ( int n ) {\n char [ ] hexaDeciNum = new char [ 100 ] ;\n int i = 0 ;\n while ( n != 0 ) {\n int temp = 0 ;\n temp = n % 16 ;\n if ( temp < 10 ) {\n hexaDeciNum [ i ] = ( char ) ( temp + 48 ) ;\n i ++ ;\n }\n else {\n hexaDeciNum [ i ] = ( char ) ( temp + 55 ) ;\n i ++ ;\n }\n n = n / 16 ;\n }\n for ( int j = i - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( hexaDeciNum [ j ] ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef decToHexa ( n ) :\n hexaDeciNum = [ '0' ] * 100\n i = 0\n while ( n != 0 ) :\n temp = 0\n temp = n % 16\n if ( temp < 10 ) :\n hexaDeciNum [ i ] = chr ( temp + 48 )\n i = i + 1\n else :\n hexaDeciNum [ i ] = chr ( temp + 55 )\n i = i + 1\n n = int ( n / 16 )\n j = i - 1\n while ( j >= 0 ) :\n print ( ( hexaDeciNum [ j ] ) , end = \"\" )\n j = j - 1\n\n"
},
{
"id": "python-java-STEINS_ALGORITHM_FOR_FINDING_GCD_1",
"pair": "python-java",
"Code1": "def gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n",
"Code2": "static int gcd ( int a , int b ) {\n if ( a == b ) return a ;\n if ( a == 0 ) return b ;\n if ( b == 0 ) return a ;\n if ( ( ~ a & 1 ) == 1 ) {\n if ( ( b & 1 ) == 1 ) return gcd ( a >> 1 , b ) ;\n else return gcd ( a >> 1 , b >> 1 ) << 1 ;\n }\n if ( ( ~ b & 1 ) == 1 ) return gcd ( a , b >> 1 ) ;\n if ( a > b ) return gcd ( ( a - b ) >> 1 , b ) ;\n return gcd ( ( b - a ) >> 1 , a ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef gcd ( a , b ) :\n if ( a == b ) :\n return a\n if ( a == 0 ) :\n return b\n if ( b == 0 ) :\n return a\n if ( ( ~ a & 1 ) == 1 ) :\n if ( ( b & 1 ) == 1 ) :\n return gcd ( a >> 1 , b )\n else :\n return ( gcd ( a >> 1 , b >> 1 ) << 1 )\n if ( ( ~ b & 1 ) == 1 ) :\n return gcd ( a , b >> 1 )\n if ( a > b ) :\n return gcd ( ( a - b ) >> 1 , b )\n return gcd ( ( b - a ) >> 1 , a )\n\n"
},
{
"id": "python-java-DETECT_IF_TWO_INTEGERS_HAVE_OPPOSITE_SIGNS",
"pair": "python-java",
"Code1": "def oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n",
"Code2": "static boolean oppositeSigns ( int x , int y ) {\n return ( ( x ^ y ) < 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef oppositeSigns ( x , y ) :\n return ( ( x ^ y ) < 0 )\n\n"
},
{
"id": "python-java-PROGRAM_CHECK_ARRAY_SORTED_NOT_ITERATIVE_RECURSIVE_1",
"pair": "python-java",
"Code1": "def arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n",
"Code2": "static boolean arraySortedOrNot ( int arr [ ] , int n ) {\n if ( n == 0 || n == 1 ) return true ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef arraySortedOrNot ( arr , n ) :\n if ( n == 0 or n == 1 ) :\n return True\n for i in range ( 1 , n ) :\n if ( arr [ i - 1 ] > arr [ i ] ) :\n return False\n return True\n\n"
},
{
"id": "python-java-CONVERT_STRING_BINARY_SEQUENCE",
"pair": "python-java",
"Code1": "def strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n",
"Code2": "static void strToBinary ( String s ) {\n int n = s . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int val = Integer . valueOf ( s . charAt ( i ) ) ;\n String bin = \"\" ;\n while ( val > 0 ) {\n if ( val % 2 == 1 ) {\n bin += ' 1 ' ;\n }\n else bin += ' 0 ' ;\n val /= 2 ;\n }\n bin = reverse ( bin ) ;\n System . out . print ( bin + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef strToBinary ( s ) :\n bin_conv = [ ]\n for c in s :\n ascii_val = ord ( c )\n binary_val = bin ( ascii_val )\n bin_conv.append ( binary_val [ 2 : ] )\n return ( ' '.join ( bin_conv ) )\n\n"
},
{
"id": "python-java-GENERATE_PYTHAGORAS_TRIPLET_SINGLE_INTEGER",
"pair": "python-java",
"Code1": "def evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n",
"Code2": "static void evaluate ( int n ) {\n if ( n == 1 || n == 2 ) System . out . println ( \"No Pythagoras \" + \"Triplet exists\" ) ;\n else if ( n % 2 == 0 ) {\n int var = 1 * n * n / 4 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var - 1 + \" \" ) ;\n System . out . println ( var + 1 + \" \" ) ;\n }\n else if ( n % 2 != 0 ) {\n int var = 1 * n * n + 1 ;\n System . out . print ( \"Pythagoras Triplets \" + \"exist i.e. \" ) ;\n System . out . print ( n + \" \" ) ;\n System . out . print ( var / 2 - 1 + \" \" ) ;\n System . out . println ( var / 2 + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef evaluate ( n ) :\n if ( n == 1 or n == 2 ) :\n print ( \"No Pythagoras\" + \" Triplet exists\" )\n elif ( n % 2 == 0 ) :\n var = n * n / 4\n print ( \"Pythagoras Triplets\" + \" exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var - 1 ) , \"\" , int ( var + 1 ) )\n elif ( n % 2 != 0 ) :\n var = n * n + 1\n print ( \"Pythagoras Triplets \" + \"exist i.e.\" , end = \"\" )\n print ( int ( n ) , \"\" , int ( var / 2 - 1 ) , \"\" , int ( var / 2 ) )\n\n"
},
{
"id": "python-java-CHECK_INTEGER_OVERFLOW_MULTIPLICATION",
"pair": "python-java",
"Code1": "def isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n",
"Code2": "static Boolean isOverflow ( long a , long b ) {\n if ( a == 0 || b == 0 ) return false ;\n long result = a * b ;\n if ( a == result / b ) return false ;\n else return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isOverflow ( a , b ) :\n if ( a == 0 or b == 0 ) :\n return False\n result = a * b\n if ( result >= 9223372036854775807 or result <= - 9223372036854775808 ) :\n result = 0\n if ( a == ( result // b ) ) :\n print ( result // b )\n return False\n else :\n return True\n\n"
},
{
"id": "python-java-FIND_EXPRESSION_DUPLICATE_PARENTHESIS_NOT",
"pair": "python-java",
"Code1": "def findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n",
"Code2": "static boolean findDuplicateparenthesis ( String s ) {\n Stack < Character > Stack = new Stack < > ( ) ;\n char [ ] str = s . toCharArray ( ) ;\n for ( char ch : str ) {\n if ( ch == ' ) ' ) {\n char top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n int elementsInside = 0 ;\n while ( top != ' ( ' ) {\n elementsInside ++ ;\n top = Stack . peek ( ) ;\n Stack . pop ( ) ;\n }\n if ( elementsInside < 1 ) {\n return true ;\n }\n }\n else {\n Stack . push ( ch ) ;\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findDuplicateparenthesis ( string ) :\n Stack = [ ]\n for ch in string :\n if ch == ')' :\n top = Stack.pop ( )\n elementsInside = 0\n while top != '(' :\n elementsInside += 1\n top = Stack.pop ( )\n if elementsInside < 1 :\n return True\n else :\n Stack.append ( ch )\n return False\n\n"
},
{
"id": "python-java-COUNT_ROTATIONS_DIVISIBLE_4",
"pair": "python-java",
"Code1": "def countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n",
"Code2": "static int countRotations ( String n ) {\n int len = n . length ( ) ;\n if ( len == 1 ) {\n int oneDigit = n . charAt ( 0 ) - ' 0 ' ;\n if ( oneDigit % 4 == 0 ) return 1 ;\n return 0 ;\n }\n int twoDigit , count = 0 ;\n for ( int i = 0 ;\n i < ( len - 1 ) ;\n i ++ ) {\n twoDigit = ( n . charAt ( i ) - ' 0 ' ) * 10 + ( n . charAt ( i + 1 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n }\n twoDigit = ( n . charAt ( len - 1 ) - ' 0 ' ) * 10 + ( n . charAt ( 0 ) - ' 0 ' ) ;\n if ( twoDigit % 4 == 0 ) count ++ ;\n return count ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countRotations ( n ) :\n l = len ( n )\n if ( l == 1 ) :\n oneDigit = ( int ) ( n [ 0 ] )\n if ( oneDigit % 4 == 0 ) :\n return 1\n return 0\n count = 0\n for i in range ( 0 , l - 1 ) :\n twoDigit = ( int ) ( n [ i ] ) * 10 + ( int ) ( n [ i + 1 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n twoDigit = ( int ) ( n [ l - 1 ] ) * 10 + ( int ) ( n [ 0 ] )\n if ( twoDigit % 4 == 0 ) :\n count = count + 1\n return count\n\n"
},
{
"id": "python-java-FIND_DISTINCT_INTEGERS_FOR_A_TRIPLET_WITH_GIVEN_PRODUCT",
"pair": "python-java",
"Code1": "def findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n",
"Code2": "static void findTriplets ( int x ) {\n Vector < Integer > fact = new Vector < Integer > ( ) ;\n HashSet < Integer > factors = new HashSet < Integer > ( ) ;\n for ( int i = 2 ;\n i <= Math . sqrt ( x ) ;\n i ++ ) {\n if ( x % i == 0 ) {\n fact . add ( i ) ;\n if ( x / i != i ) fact . add ( x / i ) ;\n factors . add ( i ) ;\n factors . add ( x / i ) ;\n }\n }\n boolean found = false ;\n int k = fact . size ( ) ;\n for ( int i = 0 ;\n i < k ;\n i ++ ) {\n int a = fact . get ( i ) ;\n for ( int j = 0 ;\n j < k ;\n j ++ ) {\n int b = fact . get ( j ) ;\n if ( ( a != b ) && ( x % ( a * b ) == 0 ) && ( x / ( a * b ) != a ) && ( x / ( a * b ) != b ) && ( x / ( a * b ) != 1 ) ) {\n System . out . print ( a + \" \" + b + \" \" + ( x / ( a * b ) ) ) ;\n found = true ;\n break ;\n }\n }\n if ( found ) break ;\n }\n if ( ! found ) System . out . print ( \"-1\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findTriplets ( x ) :\n fact = [ ]\n factors = set ( )\n for i in range ( 2 , int ( sqrt ( x ) ) ) :\n if ( x % i == 0 ) :\n fact.append ( i )\n if ( x / i != i ) :\n fact.append ( x // i )\n factors.add ( i )\n factors.add ( x // i )\n found = False\n k = len ( fact )\n for i in range ( k ) :\n a = fact [ i ]\n for j in range ( k ) :\n b = fact [ j ]\n if ( ( a != b ) and ( x % ( a * b ) == 0 ) and ( x / ( a * b ) != a ) and ( x / ( a * b ) != b ) and ( x / ( a * b ) != 1 ) ) :\n print ( a , b , x // ( a * b ) )\n found = True\n break\n if ( found ) :\n break\n if ( not found ) :\n print ( \"-1\" )\n\n"
},
{
"id": "python-java-PRINT_WAYS_BREAK_STRING_BRACKET_FORM",
"pair": "python-java",
"Code1": "def findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n",
"Code2": "static void findCombinations ( String str , int index , String out ) {\n if ( index == str . length ( ) ) System . out . println ( out ) ;\n for ( int i = index ;\n i < str . length ( ) ;\n i ++ ) findCombinations ( str , i + 1 , out + \"(\" + str . substring ( index , i + 1 ) + \")\" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findCombinations ( string , index , out ) :\n if index == len ( string ) :\n print ( out )\n for i in range ( index , len ( string ) , 1 ) :\n findCombinations ( string , i + 1 , out + \"(\" + string [ index : i + 1 ] + \")\" )\n\n"
},
{
"id": "python-java-EFFICIENT_SEARCH_IN_AN_ARRAY_WHERE_DIFFERENCE_BETWEEN_ADJACENT_IS_1",
"pair": "python-java",
"Code1": "def search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n",
"Code2": "static int search ( int arr [ ] , int n , int x ) {\n int i = 0 ;\n while ( i <= n - 1 ) {\n if ( arr [ i ] == x ) return i ;\n i += Math . abs ( arr [ i ] - x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , n , x ) :\n i = 0\n while ( i <= n - 1 ) :\n if ( arr [ i ] == x ) :\n return i\n i += abs ( arr [ i ] - x )\n return - 1\n\n"
},
{
"id": "python-java-FIND_ELEMENTS_PRESENT_FIRST_ARRAY_NOT_SECOND_1",
"pair": "python-java",
"Code1": "def findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n",
"Code2": "static void findMissing ( int a [ ] , int b [ ] , int n , int m ) {\n HashSet < Integer > s = new HashSet < > ( ) ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) s . add ( b [ i ] ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMissing ( a , b , n , m ) :\n s = dict ( )\n for i in range ( m ) :\n s [ b [ i ] ] = 1\n for i in range ( n ) :\n if a [ i ] not in s.keys ( ) :\n print ( a [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-COUNT_CHARACTERS_STRING_DISTANCE_ENGLISH_ALPHABETS_1",
"pair": "python-java",
"Code1": "def countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n",
"Code2": "static int countPairs ( String str ) {\n int result = 0 ;\n int n = str . length ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 1 ;\n ( i + j ) < n && j <= MAX_CHAR ;\n j ++ ) if ( ( Math . abs ( str . charAt ( i + j ) - str . charAt ( i ) ) == j ) ) result ++ ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countPairs ( str1 ) :\n result = 0 ;\n n = len ( str1 )\n for i in range ( 0 , n ) :\n for j in range ( 1 , MAX_CHAR + 1 ) :\n if ( ( i + j ) < n ) :\n if ( ( abs ( ord ( str1 [ i + j ] ) - ord ( str1 [ i ] ) ) == j ) ) :\n result += 1 ;\n return result\n\n"
},
{
"id": "python-java-FIND_MAXIMUM_SUM_POSSIBLE_EQUAL_SUM_THREE_STACKS",
"pair": "python-java",
"Code1": "def maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n",
"Code2": "public static int maxSum ( int stack1 [ ] , int stack2 [ ] , int stack3 [ ] , int n1 , int n2 , int n3 ) {\n int sum1 = 0 , sum2 = 0 , sum3 = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) sum1 += stack1 [ i ] ;\n for ( int i = 0 ;\n i < n2 ;\n i ++ ) sum2 += stack2 [ i ] ;\n for ( int i = 0 ;\n i < n3 ;\n i ++ ) sum3 += stack3 [ i ] ;\n int top1 = 0 , top2 = 0 , top3 = 0 ;\n int ans = 0 ;\n while ( true ) {\n if ( top1 == n1 || top2 == n2 || top3 == n3 ) return 0 ;\n if ( sum1 == sum2 && sum2 == sum3 ) return sum1 ;\n if ( sum1 >= sum2 && sum1 >= sum3 ) sum1 -= stack1 [ top1 ++ ] ;\n else if ( sum2 >= sum3 && sum2 >= sum3 ) sum2 -= stack2 [ top2 ++ ] ;\n else if ( sum3 >= sum2 && sum3 >= sum1 ) sum3 -= stack3 [ top3 ++ ] ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( stack1 , stack2 , stack3 , n1 , n2 , n3 ) :\n sum1 , sum2 , sum3 = 0 , 0 , 0\n for i in range ( n1 ) :\n sum1 += stack1 [ i ]\n for i in range ( n2 ) :\n sum2 += stack2 [ i ]\n for i in range ( n3 ) :\n sum3 += stack3 [ i ]\n top1 , top2 , top3 = 0 , 0 , 0\n ans = 0\n while ( 1 ) :\n if ( top1 == n1 or top2 == n2 or top3 == n3 ) :\n return 0\n if ( sum1 == sum2 and sum2 == sum3 ) :\n return sum1\n if ( sum1 >= sum2 and sum1 >= sum3 ) :\n sum1 -= stack1 [ top1 ]\n top1 = top1 + 1\n elif ( sum2 >= sum3 and sum2 >= sum3 ) :\n sum2 -= stack2 [ top2 ]\n top2 = top2 + 1\n elif ( sum3 >= sum2 and sum3 >= sum1 ) :\n sum3 -= stack3 [ top3 ]\n top3 = top3 + 1\n\n"
},
{
"id": "python-java-MINIMUM_SUM_TWO_NUMBERS_FORMED_DIGITS_ARRAY",
"pair": "python-java",
"Code1": "def solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n",
"Code2": "static int solve ( int arr [ ] , int n ) {\n Arrays . sort ( arr ) ;\n int a = 0 , b = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( i % 2 != 0 ) a = a * 10 + arr [ i ] ;\n else b = b * 10 + arr [ i ] ;\n }\n return a + b ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef solve ( arr , n ) :\n arr.sort ( )\n a = 0 b = 0\n for i in range ( n ) :\n if ( i % 2 != 0 ) :\n a = a * 10 + arr [ i ]\n else :\n b = b * 10 + arr [ i ]\n return a + b\n\n"
},
{
"id": "python-java-FIND_FIRST_NATURAL_NUMBER_WHOSE_FACTORIAL_DIVISIBLE_X",
"pair": "python-java",
"Code1": "def firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n",
"Code2": "static int firstFactorialDivisibleNumber ( int x ) {\n int i = 1 ;\n int fact = 1 ;\n for ( i = 1 ;\n i < x ;\n i ++ ) {\n fact = fact * i ;\n if ( fact % x == 0 ) break ;\n }\n return i ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstFactorialDivisibleNumber ( x ) :\n i = 1\n fact = 1\n for i in range ( 1 , x ) :\n fact = fact * i\n if ( fact % x == 0 ) :\n break\n return i\n\n"
},
{
"id": "python-java-COUNT_MINIMUM_STEPS_GET_GIVEN_DESIRED_ARRAY",
"pair": "python-java",
"Code1": "def countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n",
"Code2": "static int countMinOperations ( int n ) {\n int result = 0 ;\n while ( true ) {\n int zero_count = 0 ;\n int i ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr [ i ] % 2 == 1 ) break ;\n else if ( arr [ i ] == 0 ) zero_count ++ ;\n }\n if ( zero_count == n ) return result ;\n if ( i == n ) {\n for ( int j = 0 ;\n j < n ;\n j ++ ) arr [ j ] = arr [ j ] / 2 ;\n result ++ ;\n }\n for ( int j = i ;\n j < n ;\n j ++ ) {\n if ( arr [ j ] % 2 == 1 ) {\n arr [ j ] -- ;\n result ++ ;\n }\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countMinOperations ( target , n ) :\n result = 0\n while ( True ) :\n zero_count = 0\n i = 0\n while ( i < n ) :\n if ( ( target [ i ] & 1 ) > 0 ) :\n break\n elif ( target [ i ] == 0 ) :\n zero_count += 1\n i += 1\n if ( zero_count == n ) :\n return result\n if ( i == n ) :\n for j in range ( n ) :\n target [ j ] = target [ j ] // 2\n result += 1\n for j in range ( i , n ) :\n if ( target [ j ] & 1 ) :\n target [ j ] -= 1\n result += 1\n\n"
},
{
"id": "python-java-SORT_ARRAY_CONTAIN_1_N_VALUES",
"pair": "python-java",
"Code1": "def sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n",
"Code2": "static void sortit ( int [ ] arr , int n ) {\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n arr [ i ] = i + 1 ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortit ( arr , n ) :\n for i in range ( n ) :\n arr [ i ] = i + 1\n\n"
},
{
"id": "python-java-CHANGE_BITS_CAN_MADE_ONE_FLIP",
"pair": "python-java",
"Code1": "def canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n",
"Code2": "static boolean canMakeAllSame ( String str ) {\n int zeros = 0 , ones = 0 ;\n for ( int i = 0 ;\n i < str . length ( ) ;\n i ++ ) {\n char ch = str . charAt ( i ) ;\n if ( ch == ' 0 ' ) ++ zeros ;\n else ++ ones ;\n }\n return ( zeros == 1 || ones == 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef canMakeAllSame ( str ) :\n zeros = 0\n ones = 0\n for i in range ( 0 , len ( str ) ) :\n ch = str [ i ]\n if ( ch == '0' ) :\n zeros = zeros + 1\n else :\n ones = ones + 1\n return ( zeros == 1 or ones == 1 )\n\n"
},
{
"id": "python-java-SUM_ELEMENTS_K1TH_K2TH_SMALLEST_ELEMENTS_1",
"pair": "python-java",
"Code1": "def minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n",
"Code2": "static void minheapify ( int [ ] a , int index ) {\n int small = index ;\n int l = 2 * index + 1 ;\n int r = 2 * index + 2 ;\n if ( l < n && a [ l ] < a [ small ] ) small = l ;\n if ( r < n && a [ r ] < a [ small ] ) small = r ;\n if ( small != index ) {\n int t = a [ small ] ;\n a [ small ] = a [ index ] ;\n a [ index ] = t ;\n minheapify ( a , small ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minheapify ( a , index ) :\n small = index\n l = 2 * index + 1\n r = 2 * index + 2\n if ( l < n and a [ l ] < a [ small ] ) :\n small = l\n if ( r < n and a [ r ] < a [ small ] ) :\n small = r\n if ( small != index ) :\n ( a [ small ] , a [ index ] ) = ( a [ index ] , a [ small ] )\n minheapify ( a , small )\n\n"
},
{
"id": "python-java-FIND_MINIMUM_SHIFT_LONGEST_COMMON_PREFIX",
"pair": "python-java",
"Code1": "def KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n",
"Code2": "static void KMP ( int m , int n , String str2 , String str1 ) {\n int pos = 0 , len = 0 ;\n int [ ] p = new int [ m + 1 ] ;\n int k = 0 ;\n char [ ] ch1 = str1 . toCharArray ( ) ;\n char [ ] ch2 = str2 . toCharArray ( ) ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ;\n if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ;\n p [ i ] = k ;\n }\n for ( int j = 0 , i = 0 ;\n i < m ;\n i ++ ) {\n while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ;\n if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ;\n if ( j > len ) {\n len = j ;\n pos = i - j + 1 ;\n }\n }\n System . out . println ( \"Shift = \" + pos ) ;\n System . out . println ( \"Prefix = \" + str1 . substring ( 0 , len ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef KMP ( m , n , str2 , str1 ) :\n pos = 0\n Len = 0\n p = [ 0 for i in range ( m + 1 ) ]\n k = 0\n for i in range ( 2 , n + 1 ) :\n while ( k > 0 and str1 [ k ] != str1 [ i - 1 ] ) :\n k = p [ k ]\n if ( str1 [ k ] == str1 [ i - 1 ] ) :\n k += 1\n p [ i ] = k\n j = 0\n for i in range ( m ) :\n while ( j > 0 and j < n and str1 [ j ] != str2 [ i ] ) :\n j = p [ j ]\n if ( j < n and str1 [ j ] == str2 [ i ] ) :\n j += 1\n if ( j > Len ) :\n Len = j\n pos = i - j + 1\n print ( \"Shift = \" , pos )\n print ( \"Prefix = \" , str1 [ : Len ] )\n\n"
},
{
"id": "python-java-SWAP_MAJOR_MINOR_DIAGONALS_SQUARE_MATRIX",
"pair": "python-java",
"Code1": "def swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n",
"Code2": "static void swapDiagonal ( int matrix [ ] [ ] ) {\n for ( int i = 0 ;\n i < N ;\n i ++ ) {\n int temp = matrix [ i ] [ i ] ;\n matrix [ i ] [ i ] = matrix [ i ] [ N - i - 1 ] ;\n matrix [ i ] [ N - i - 1 ] = temp ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef swapDiagonal ( matrix ) :\n for i in range ( N ) :\n matrix [ i ] [ i ] , matrix [ i ] [ N - i - 1 ] = \\\n matrix [ i ] [ N - i - 1 ] , matrix [ i ] [ i ]\n\n"
},
{
"id": "python-java-REPRESENT_NUMBER_SUM_MINIMUM_POSSIBLE_PSUEDOBINARY_NUMBERS",
"pair": "python-java",
"Code1": "def psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n",
"Code2": "public static void psuedoBinary ( int n ) {\n while ( n != 0 ) {\n int temp = n , m = 0 , p = 1 ;\n while ( temp != 0 ) {\n int rem = temp % 10 ;\n temp = temp / 10 ;\n if ( rem != 0 ) m += p ;\n p *= 10 ;\n }\n System . out . print ( m + \" \" ) ;\n n = n - m ;\n }\n System . out . println ( \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef psuedoBinary ( n ) :\n while ( n > 0 ) :\n temp = n\n m = 0\n p = 1\n while ( temp ) :\n rem = temp % 10\n temp = int ( temp / 10 )\n if ( rem != 0 ) :\n m += p\n p *= 10\n print ( m , end = \" \" )\n n = n - m\n\n"
},
{
"id": "python-java-MINIMUM_NUMBER_POINTS_REMOVED_GET_REMAINING_POINTS_ONE_SIDE_AXIS",
"pair": "python-java",
"Code1": "def findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n",
"Code2": "static int findmin ( Point p [ ] , int n ) {\n int a = 0 , b = 0 , c = 0 , d = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( p [ i ] . x <= 0 ) a ++ ;\n else if ( p [ i ] . x >= 0 ) b ++ ;\n if ( p [ i ] . y >= 0 ) c ++ ;\n else if ( p [ i ] . y <= 0 ) d ++ ;\n }\n return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findmin ( p , n ) :\n a , b , c , d = 0 , 0 , 0 , 0\n for i in range ( n ) :\n if ( p [ i ] [ 0 ] <= 0 ) :\n a += 1\n elif ( p [ i ] [ 0 ] >= 0 ) :\n b += 1\n if ( p [ i ] [ 1 ] >= 0 ) :\n c += 1\n elif ( p [ i ] [ 1 ] <= 0 ) :\n d += 1\n return min ( [ a , b , c , d ] )\n\n"
},
{
"id": "python-java-FIND_MINIMUM_NUMBER_OF_COINS_THAT_MAKE_A_CHANGE_1",
"pair": "python-java",
"Code1": "def minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n",
"Code2": "static int minCoins ( int coins [ ] , int m , int V ) {\n int table [ ] = new int [ V + 1 ] ;\n table [ 0 ] = 0 ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) table [ i ] = Integer . MAX_VALUE ;\n for ( int i = 1 ;\n i <= V ;\n i ++ ) {\n for ( int j = 0 ;\n j < m ;\n j ++ ) if ( coins [ j ] <= i ) {\n int sub_res = table [ i - coins [ j ] ] ;\n if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ;\n }\n }\n return table [ V ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minCoins ( coins , m , V ) :\n table = [ 0 for i in range ( V + 1 ) ]\n table [ 0 ] = 0\n for i in range ( 1 , V + 1 ) :\n table [ i ] = sys.maxsize\n for i in range ( 1 , V + 1 ) :\n for j in range ( m ) :\n if ( coins [ j ] <= i ) :\n sub_res = table [ i - coins [ j ] ]\n if ( sub_res != sys.maxsize and sub_res + 1 < table [ i ] ) :\n table [ i ] = sub_res + 1\n return table [ V ]\n\n"
},
{
"id": "python-java-MAKE_LARGEST_PALINDROME_CHANGING_K_DIGITS",
"pair": "python-java",
"Code1": "def maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n",
"Code2": "static String maximumPalinUsingKChanges ( String str , int k ) {\n char palin [ ] = str . toCharArray ( ) ;\n String ans = \"\" ;\n int l = 0 ;\n int r = str . length ( ) - 1 ;\n while ( l < r ) {\n if ( str . charAt ( l ) != str . charAt ( r ) ) {\n palin [ l ] = palin [ r ] = ( char ) Math . max ( str . charAt ( l ) , str . charAt ( r ) ) ;\n k -- ;\n }\n l ++ ;\n r -- ;\n }\n if ( k < 0 ) {\n return \"Not possible\" ;\n }\n l = 0 ;\n r = str . length ( ) - 1 ;\n while ( l <= r ) {\n if ( l == r ) {\n if ( k > 0 ) {\n palin [ l ] = ' 9 ' ;\n }\n }\n if ( palin [ l ] < ' 9 ' ) {\n if ( k >= 2 && palin [ l ] == str . charAt ( l ) && palin [ r ] == str . charAt ( r ) ) {\n k -= 2 ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n else if ( k >= 1 && ( palin [ l ] != str . charAt ( l ) || palin [ r ] != str . charAt ( r ) ) ) {\n k -- ;\n palin [ l ] = palin [ r ] = ' 9 ' ;\n }\n }\n l ++ ;\n r -- ;\n }\n for ( int i = 0 ;\n i < palin . length ;\n i ++ ) ans += palin [ i ] ;\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maximumPalinUsingKChanges ( strr , k ) :\n palin = strr\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( strr [ l ] != strr [ r ] ) :\n palin [ l ] = palin [ r ] = max ( strr [ l ] , strr [ r ] )\n k -= 1\n l += 1\n r -= 1\n if ( k < 0 ) :\n return \"Not possible\"\n l = 0\n r = len ( strr ) - 1\n while ( l <= r ) :\n if ( l == r ) :\n if ( k > 0 ) :\n palin [ l ] = '9'\n if ( palin [ l ] < '9' ) :\n if ( k >= 2 and palin [ l ] == strr [ l ] and palin [ r ] == strr [ r ] ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n elif ( k >= 1 and ( palin [ l ] != strr [ l ] or palin [ r ] != strr [ r ] ) ) :\n k -= 1\n palin [ l ] = palin [ r ] = '9'\n l += 1\n r -= 1\n return palin\n\n"
},
{
"id": "python-java-MINIMUM_ROOMS_FOR_M_EVENTS_OF_N_BATCHES_WITH_GIVEN_SCHEDULE",
"pair": "python-java",
"Code1": "def findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n",
"Code2": "static int findMinRooms ( String slots [ ] , int n , int m ) {\n int counts [ ] = new int [ m ] ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) counts [ i ] = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < m ;\n j ++ ) if ( slots [ i ] . charAt ( j ) == ' 1 ' ) counts [ j ] ++ ;\n int max = - 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) if ( max < counts [ i ] ) max = counts [ i ] ;\n return max ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinRooms ( slots , n , m ) :\n counts = [ 0 ] * m\n for i in range ( n ) :\n for j in range ( m ) :\n if ( slots [ i ] [ j ] == '1' ) :\n counts [ j ] += 1\n return max ( counts )\n\n"
},
{
"id": "python-java-MAXIMUM_PATH_SUM_POSITION_JUMPS_DIVISIBILITY_CONDITION",
"pair": "python-java",
"Code1": "def printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n",
"Code2": "static void printMaxSum ( int arr [ ] , int n ) {\n int dp [ ] = new int [ n ] ;\n Arrays . fill ( dp , 0 ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n dp [ i ] = arr [ i ] ;\n int maxi = 0 ;\n for ( int j = 1 ;\n j <= Math . sqrt ( i + 1 ) ;\n j ++ ) {\n if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) {\n if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ;\n if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ;\n }\n }\n dp [ i ] += maxi ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) System . out . print ( dp [ i ] + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printMaxSum ( arr , n ) :\n dp = [ 0 for i in range ( n ) ]\n for i in range ( n ) :\n dp [ i ] = arr [ i ]\n maxi = 0\n for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) :\n if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) :\n if ( dp [ j - 1 ] > maxi ) :\n maxi = dp [ j - 1 ]\n if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) :\n maxi = dp [ ( i + 1 ) // j - 1 ]\n dp [ i ] += maxi\n for i in range ( n ) :\n print ( dp [ i ] , end = ' ' )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_ALTERNATING_SUBSEQUENCE_SUM",
"pair": "python-java",
"Code1": "def maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n",
"Code2": "static int maxAlternateSum ( int arr [ ] , int n ) {\n if ( n == 1 ) return arr [ 0 ] ;\n int dec [ ] = new int [ n ] ;\n int inc [ ] = new int [ n ] ;\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ;\n int flag = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n for ( int j = 0 ;\n j < i ;\n j ++ ) {\n if ( arr [ j ] > arr [ i ] ) {\n dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ;\n flag = 1 ;\n }\n else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ;\n }\n }\n int result = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( result < inc [ i ] ) result = inc [ i ] ;\n if ( result < dec [ i ] ) result = dec [ i ] ;\n }\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxAlternateSum ( arr , n ) :\n if ( n == 1 ) :\n return arr [ 0 ]\n dec = [ 0 for i in range ( n + 1 ) ]\n inc = [ 0 for i in range ( n + 1 ) ]\n dec [ 0 ] = inc [ 0 ] = arr [ 0 ]\n flag = 0\n for i in range ( 1 , n ) :\n for j in range ( i ) :\n if ( arr [ j ] > arr [ i ] ) :\n dec [ i ] = max ( dec [ i ] , inc [ j ] + arr [ i ] )\n flag = 1\n elif ( arr [ j ] < arr [ i ] and flag == 1 ) :\n inc [ i ] = max ( inc [ i ] , dec [ j ] + arr [ i ] )\n result = - 2147483648\n for i in range ( n ) :\n if ( result < inc [ i ] ) :\n result = inc [ i ]\n if ( result < dec [ i ] ) :\n result = dec [ i ]\n return result\n\n"
},
{
"id": "python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i , j ;\n System . out . println ( \"Repeated Elements are :\" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n for ( j = i + 1 ;\n j < size ;\n j ++ ) {\n if ( arr [ i ] == arr [ j ] ) System . out . print ( arr [ i ] + \" \" ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n print ( \"Repeating elements are \" , end = '' )\n for i in range ( 0 , size ) :\n for j in range ( i + 1 , size ) :\n if arr [ i ] == arr [ j ] :\n print ( arr [ i ] , end = ' ' )\n\n"
},
{
"id": "python-java-MINIMUM_PRODUCT_K_INTEGERS_ARRAY_POSITIVE_INTEGERS",
"pair": "python-java",
"Code1": "def minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n",
"Code2": "public static int minProduct ( int [ ] arr , int n , int k ) {\n PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) pq . add ( arr [ i ] ) ;\n int count = 0 , ans = 1 ;\n while ( pq . isEmpty ( ) == false && count < k ) {\n ans = ans * pq . element ( ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minProduct ( arr , n , k ) :\n heapq.heapify ( arr )\n count = 0\n ans = 1\n while ( arr ) and count < k :\n x = heapq.heappop ( arr )\n ans = ans * x\n count = count + 1\n return ans\n\n"
},
{
"id": "python-java-C_PROGRAM_FIND_LARGEST_ELEMENT_ARRAY_1",
"pair": "python-java",
"Code1": "def largest ( arr , n ) :\n return max ( arr )\n",
"Code2": "static int largest ( int [ ] arr , int n ) {\n Arrays . sort ( arr ) ;\n return arr [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef largest ( arr , n ) :\n return max ( arr )\n\n"
},
{
"id": "python-java-PROGRAM_TO_EFFICIENTLY_CALCULATE_EX",
"pair": "python-java",
"Code1": "def exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n",
"Code2": "static float exponential ( int n , float x ) {\n float sum = 1 ;\n for ( int i = n - 1 ;\n i > 0 ;\n -- i ) sum = 1 + x * sum / i ;\n return sum ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef exponential ( n , x ) :\n sum = 1.0\n for i in range ( n , 0 , - 1 ) :\n sum = 1 + x * sum / i\n print ( \"e^x =\" , sum )\n\n"
},
{
"id": "python-java-FIRST_ELEMENT_OCCURRING_K_TIMES_ARRAY",
"pair": "python-java",
"Code1": "def firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n",
"Code2": "static int firstElement ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > count_map = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n int a = 0 ;\n if ( count_map . get ( arr [ i ] ) != null ) {\n a = count_map . get ( arr [ i ] ) ;\n }\n count_map . put ( arr [ i ] , a + 1 ) ;\n }\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( count_map . get ( arr [ i ] ) == k ) {\n return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef firstElement ( arr , n , k ) :\n count_map = { }\n for i in range ( 0 , n ) :\n if ( arr [ i ] in count_map.keys ( ) ) :\n count_map [ arr [ i ] ] += 1\n else :\n count_map [ arr [ i ] ] = 1\n i += 1\n for i in range ( 0 , n ) :\n if ( count_map [ arr [ i ] ] == k ) :\n return arr [ i ]\n i += 1\n return - 1\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_36_CUT_A_ROPE_TO_MAXIMIZE_PRODUCT_1",
"pair": "python-java",
"Code1": "def maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n",
"Code2": "static int maxProd ( int n ) {\n if ( n == 2 || n == 3 ) return ( n - 1 ) ;\n int res = 1 ;\n while ( n > 4 ) {\n n -= 3 ;\n res *= 3 ;\n }\n return ( n * res ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxProd ( n ) :\n if ( n == 2 or n == 3 ) :\n return ( n - 1 )\n res = 1\n while ( n > 4 ) :\n n -= 3\n res *= 3\n return ( n * res )\n\n"
},
{
"id": "python-java-MAXIMUM_SUM_2_X_N_GRID_NO_TWO_ELEMENTS_ADJACENT",
"pair": "python-java",
"Code1": "def maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n",
"Code2": "public static int maxSum ( int grid [ ] [ ] , int n ) {\n int incl = Math . max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] ) ;\n int excl = 0 , excl_new ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n excl_new = Math . max ( excl , incl ) ;\n incl = excl + Math . max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] ) ;\n excl = excl_new ;\n }\n return Math . max ( excl , incl ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxSum ( grid , n ) :\n incl = max ( grid [ 0 ] [ 0 ] , grid [ 1 ] [ 0 ] )\n excl = 0\n for i in range ( 1 , n ) :\n excl_new = max ( excl , incl )\n incl = excl + max ( grid [ 0 ] [ i ] , grid [ 1 ] [ i ] )\n excl = excl_new\n return max ( excl , incl )\n\n"
},
{
"id": "python-java-FIND_ROTATION_COUNT_ROTATED_SORTED_ARRAY_1",
"pair": "python-java",
"Code1": "def countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n",
"Code2": "static int countRotations ( int arr [ ] , int low , int high ) {\n if ( high < low ) return 0 ;\n if ( high == low ) return low ;\n int mid = low + ( high - low ) / 2 ;\n if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ;\n if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ;\n if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ;\n return countRotations ( arr , mid + 1 , high ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countRotations ( arr , low , high ) :\n if ( high < low ) :\n return 0\n if ( high == low ) :\n return low\n mid = low + ( high - low ) / 2\n mid = int ( mid )\n if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :\n return ( mid + 1 )\n if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :\n return mid\n if ( arr [ high ] > arr [ mid ] ) :\n return countRotations ( arr , low , mid - 1 )\n return countRotations ( arr , mid + 1 , high )\n\n"
},
{
"id": "python-java-SUM_MATRIX_ELEMENT_ELEMENT_INTEGER_DIVISION_ROW_COLUMN_1",
"pair": "python-java",
"Code1": "def findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n",
"Code2": "static int findSum ( int n ) {\n int ans = 0 , temp = 0 , num ;\n for ( int i = 1 ;\n i <= n && temp < n ;\n i ++ ) {\n temp = i - 1 ;\n num = 1 ;\n while ( temp < n ) {\n if ( temp + i <= n ) ans += ( i * num ) ;\n else ans += ( ( n - temp ) * num ) ;\n temp += i ;\n num ++ ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( n ) :\n ans = 0 temp = 0\n for i in range ( 1 , n + 1 ) :\n if temp < n :\n temp = i - 1\n num = 1\n while temp < n :\n if temp + i <= n :\n ans += i * num\n else :\n ans += ( n - temp ) * num\n temp += i\n num += 1\n return ans\n\n"
},
{
"id": "python-java-CHECK_HALF_STRING_CHARACTER_FREQUENCY_CHARACTER",
"pair": "python-java",
"Code1": "def checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n",
"Code2": "static boolean checkCorrectOrNot ( String s ) {\n int [ ] count1 = new int [ MAX_CHAR ] ;\n int [ ] count2 = new int [ MAX_CHAR ] ;\n int n = s . length ( ) ;\n if ( n == 1 ) return true ;\n for ( int i = 0 , j = n - 1 ;\n i < j ;\n i ++ , j -- ) {\n count1 [ s . charAt ( i ) - ' a ' ] ++ ;\n count2 [ s . charAt ( j ) - ' a ' ] ++ ;\n }\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) if ( count1 [ i ] != count2 [ i ] ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkCorrectOrNot ( s ) :\n global MAX_CHAR\n count1 = [ 0 ] * MAX_CHAR\n count2 = [ 0 ] * MAX_CHAR\n n = len ( s )\n if n == 1 :\n return true\n i = 0 j = n - 1\n while ( i < j ) :\n count1 [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n count2 [ ord ( s [ j ] ) - ord ( 'a' ) ] += 1\n i += 1 j -= 1\n for i in range ( MAX_CHAR ) :\n if count1 [ i ] != count2 [ i ] :\n return False\n return True\n\n"
},
{
"id": "python-java-SUM_FACTORS_NUMBER",
"pair": "python-java",
"Code1": "def divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n",
"Code2": "static int divSum ( int n ) {\n int result = 0 ;\n for ( int i = 2 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n if ( n % i == 0 ) {\n if ( i == ( n / i ) ) result += i ;\n else result += ( i + n / i ) ;\n }\n }\n return ( result + n + 1 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef divSum ( n ) :\n result = 0\n for i in range ( 2 , ( int ) ( math.sqrt ( n ) ) + 1 ) :\n if ( n % i == 0 ) :\n if ( i == ( n / i ) ) :\n result = result + i\n else :\n result = result + ( i + n // i )\n return ( result + n + 1 )\n\n"
},
{
"id": "python-java-ROTATE_MATRIX_180_DEGREE",
"pair": "python-java",
"Code1": "def rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n",
"Code2": "static void rotateMatrix ( int mat [ ] [ ] ) {\n for ( int i = N - 1 ;\n i >= 0 ;\n i -- ) {\n for ( int j = N - 1 ;\n j >= 0 ;\n j -- ) System . out . print ( mat [ i ] [ j ] + \" \" ) ;\n System . out . println ( ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef rotateMatrix ( mat ) :\n i = N - 1\n while ( i >= 0 ) :\n j = N - 1\n while ( j >= 0 ) :\n print ( mat [ i ] [ j ] , end = \" \" )\n j = j - 1\n print ( )\n i = i - 1\n\n"
},
{
"id": "python-java-PRINT_MATRIX_SPIRAL_FORM_STARTING_POINT",
"pair": "python-java",
"Code1": "def printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n",
"Code2": "static void printSpiral ( int [ ] [ ] mat , int r , int c ) {\n int i , a = 0 , b = 2 ;\n int low_row = ( 0 > a ) ? 0 : a ;\n int low_column = ( 0 > b ) ? 0 : b - 1 ;\n int high_row = ( ( a + 1 ) >= r ) ? r - 1 : a + 1 ;\n int high_column = ( ( b + 1 ) >= c ) ? c - 1 : b + 1 ;\n while ( ( low_row > 0 - r && low_column > 0 - c ) ) {\n for ( i = low_column + 1 ;\n i <= high_column && i < c && low_row >= 0 ;\n ++ i ) System . out . print ( mat [ low_row ] [ i ] + \" \" ) ;\n low_row -= 1 ;\n for ( i = low_row + 2 ;\n i <= high_row && i < r && high_column < c ;\n ++ i ) System . out . print ( mat [ i ] [ high_column ] + \" \" ) ;\n high_column += 1 ;\n for ( i = high_column - 2 ;\n i >= low_column && i >= 0 && high_row < r ;\n -- i ) System . out . print ( mat [ high_row ] [ i ] + \" \" ) ;\n high_row += 1 ;\n for ( i = high_row - 2 ;\n i > low_row && i >= 0 && low_column >= 0 ;\n -- i ) System . out . print ( mat [ i ] [ low_column ] + \" \" ) ;\n low_column -= 1 ;\n }\n System . out . println ( ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSpiral ( mat , r , c ) :\n a = 0\n b = 2\n low_row = 0 if ( 0 > a ) else a\n low_column = 0 if ( 0 > b ) else b - 1\n high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1\n high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1\n while ( ( low_row > 0 - r and low_column > 0 - c ) ) :\n i = low_column + 1\n while ( i <= high_column and i < c and low_row >= 0 ) :\n print ( mat [ low_row ] [ i ] , end = \" \" )\n i += 1\n low_row -= 1\n i = low_row + 2\n while ( i <= high_row and i < r and high_column < c ) :\n print ( mat [ i ] [ high_column ] , end = \" \" )\n i += 1\n high_column += 1\n i = high_column - 2\n while ( i >= low_column and i >= 0 and high_row < r ) :\n print ( mat [ high_row ] [ i ] , end = \" \" )\n i -= 1\n high_row += 1\n i = high_row - 2\n while ( i > low_row and i >= 0 and low_column >= 0 ) :\n print ( mat [ i ] [ low_column ] , end = \" \" )\n i -= 1\n low_column -= 1\n print ( )\n\n"
},
{
"id": "python-java-COUNT_EVEN_LENGTH_BINARY_SEQUENCES_WITH_SAME_SUM_OF_FIRST_AND_SECOND_HALF_BITS_1",
"pair": "python-java",
"Code1": "def countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n",
"Code2": "static int countSeq ( int n ) {\n int nCr = 1 , res = 1 ;\n for ( int r = 1 ;\n r <= n ;\n r ++ ) {\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n }\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSeq ( n ) :\n nCr = 1\n res = 1\n for r in range ( 1 , n + 1 ) :\n nCr = ( nCr * ( n + 1 - r ) ) / r ;\n res += nCr * nCr ;\n return res ;\n\n"
},
{
"id": "python-java-PROGRAM_CALCULATE_AREA_OCTAGON",
"pair": "python-java",
"Code1": "def areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n",
"Code2": "static double areaOctagon ( double side ) {\n return ( float ) ( 2 * ( 1 + Math . sqrt ( 2 ) ) * side * side ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef areaOctagon ( side ) :\n return ( 2 * ( 1 + ( math.sqrt ( 2 ) ) ) * side * side )\n\n"
},
{
"id": "python-java-MAXIMUM_CONSECUTIVE_NUMBERS_PRESENT_ARRAY",
"pair": "python-java",
"Code1": "def findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n",
"Code2": "static int findLongestConseqSubseq ( int arr [ ] , int n ) {\n HashSet < Integer > S = new HashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) S . add ( arr [ i ] ) ;\n int ans = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( S . contains ( arr [ i ] ) ) {\n int j = arr [ i ] ;\n while ( S . contains ( j ) ) j ++ ;\n ans = Math . max ( ans , j - arr [ i ] ) ;\n }\n }\n return ans ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findLongestConseqSubseq ( arr , n ) :\n S = set ( )\n for i in range ( n ) :\n S.add ( arr [ i ] )\n ans = 0\n for i in range ( n ) :\n if S.__contains__ ( arr [ i ] ) :\n j = arr [ i ]\n while ( S.__contains__ ( j ) ) :\n j += 1\n ans = max ( ans , j - arr [ i ] )\n return ans\n\n"
},
{
"id": "python-java-SHORTEST_POSSIBLE_COMBINATION_TWO_STRINGS",
"pair": "python-java",
"Code1": "def printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n",
"Code2": "static void printSuperSeq ( String a , String b ) {\n int m = a . length ( ) , n = b . length ( ) ;\n int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ;\n for ( int i = 0 ;\n i <= m ;\n i ++ ) {\n for ( int j = 0 ;\n j <= n ;\n j ++ ) {\n if ( i == 0 ) dp [ i ] [ j ] = j ;\n else if ( j == 0 ) dp [ i ] [ j ] = i ;\n else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ;\n else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;\n }\n }\n String res = \"\" ;\n int i = m , j = n ;\n while ( i > 0 && j > 0 ) {\n if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n j -- ;\n }\n else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n else {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n }\n while ( i > 0 ) {\n res = a . charAt ( i - 1 ) + res ;\n i -- ;\n }\n while ( j > 0 ) {\n res = b . charAt ( j - 1 ) + res ;\n j -- ;\n }\n System . out . println ( res ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printSuperSeq ( a , b ) :\n m = len ( a )\n n = len ( b )\n dp = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]\n for i in range ( 0 , m + 1 ) :\n for j in range ( 0 , n + 1 ) :\n if not i :\n dp [ i ] [ j ] = j\n elif not j :\n dp [ i ] [ j ] = i\n elif ( a [ i - 1 ] == b [ j - 1 ] ) :\n dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]\n else :\n dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )\n index = dp [ m ] [ n ]\n res = [ \"\" ] * ( index )\n i = m\n j = n\n while ( i > 0 and j > 0 ) :\n if ( a [ i - 1 ] == b [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n j -= 1\n index -= 1\n elif ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n else :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n while ( i > 0 ) :\n res [ index - 1 ] = a [ i - 1 ]\n i -= 1\n index -= 1\n while ( j > 0 ) :\n res [ index - 1 ] = b [ j - 1 ]\n j -= 1\n index -= 1\n print ( \"\".join ( res ) )\n\n"
},
{
"id": "python-java-COUNT_POSSIBLE_PATHS_TOP_LEFT_BOTTOM_RIGHT_NXM_MATRIX_2",
"pair": "python-java",
"Code1": "def numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n",
"Code2": "static int numberOfPaths ( int m , int n ) {\n int [ ] dp = new int [ n ] ;\n dp [ 0 ] = 1 ;\n for ( int i = 0 ;\n i < m ;\n i ++ ) {\n for ( int j = 1 ;\n j < n ;\n j ++ ) {\n dp [ j ] += dp [ j - 1 ] ;\n }\n }\n return dp [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfPaths ( p , q ) :\n dp = [ 1 for i in range ( q ) ]\n for i in range ( p - 1 ) :\n for j in range ( 1 , q ) :\n dp [ j ] += dp [ j - 1 ]\n return dp [ q - 1 ]\n\n"
},
{
"id": "python-java-FIND_WHETHER_A_GIVEN_NUMBER_IS_A_POWER_OF_4_OR_NOT_1",
"pair": "python-java",
"Code1": "def isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n",
"Code2": "static int isPowerOfFour ( int n ) {\n int count = 0 ;\n int x = n & ( n - 1 ) ;\n if ( n > 0 && x == 0 ) {\n while ( n > 1 ) {\n n >>= 1 ;\n count += 1 ;\n }\n return ( count % 2 == 0 ) ? 1 : 0 ;\n }\n return 0 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPowerOfFour ( n ) :\n count = 0\n if ( n and ( not ( n & ( n - 1 ) ) ) ) :\n while ( n > 1 ) :\n n >>= 1\n count += 1\n if ( count % 2 == 0 ) :\n return True\n else :\n return False\n\n"
},
{
"id": "python-java-FIND_SUM_ODD_FACTORS_NUMBER",
"pair": "python-java",
"Code1": "def sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n",
"Code2": "static int sumofoddFactors ( int n ) {\n int res = 1 ;\n while ( n % 2 == 0 ) n = n / 2 ;\n for ( int i = 3 ;\n i <= Math . sqrt ( n ) ;\n i ++ ) {\n int count = 0 , curr_sum = 1 ;\n int curr_term = 1 ;\n while ( n % i == 0 ) {\n count ++ ;\n n = n / i ;\n curr_term *= i ;\n curr_sum += curr_term ;\n }\n res *= curr_sum ;\n }\n if ( n >= 2 ) res *= ( 1 + n ) ;\n return res ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sumofoddFactors ( n ) :\n res = 1\n while n % 2 == 0 :\n n = n // 2\n for i in range ( 3 , int ( math.sqrt ( n ) + 1 ) ) :\n count = 0\n curr_sum = 1\n curr_term = 1\n while n % i == 0 :\n count += 1\n n = n // i\n curr_term *= i\n curr_sum += curr_term\n res *= curr_sum\n if n >= 2 :\n res *= ( 1 + n )\n return res\n\n"
},
{
"id": "python-java-FIND_THE_ELEMENT_BEFORE_WHICH_ALL_THE_ELEMENTS_ARE_SMALLER_THAN_IT_AND_AFTER_WHICH_ALL_ARE_GREATER_THAN_IT",
"pair": "python-java",
"Code1": "def findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n",
"Code2": "static int findElement ( int [ ] arr , int n ) {\n int [ ] leftMax = new int [ n ] ;\n leftMax [ 0 ] = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) leftMax [ i ] = Math . max ( leftMax [ i - 1 ] , arr [ i - 1 ] ) ;\n int rightMin = Integer . MAX_VALUE ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n if ( leftMax [ i ] < arr [ i ] && rightMin > arr [ i ] ) return i ;\n rightMin = Math . min ( rightMin , arr [ i ] ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findElement ( arr , n ) :\n leftMax = [ None ] * n\n leftMax [ 0 ] = float ( '-inf' )\n for i in range ( 1 , n ) :\n leftMax [ i ] = max ( leftMax [ i - 1 ] , arr [ i - 1 ] )\n rightMin = float ( 'inf' )\n for i in range ( n - 1 , - 1 , - 1 ) :\n if leftMax [ i ] < arr [ i ] and rightMin > arr [ i ] :\n return i\n rightMin = min ( rightMin , arr [ i ] )\n return - 1\n\n"
},
{
"id": "python-java-SEARCH_AN_ELEMENT_IN_A_SORTED_AND_PIVOTED_ARRAY",
"pair": "python-java",
"Code1": "def search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n",
"Code2": "static int search ( int arr [ ] , int l , int h , int key ) {\n if ( l > h ) return - 1 ;\n int mid = ( l + h ) / 2 ;\n if ( arr [ mid ] == key ) return mid ;\n if ( arr [ l ] <= arr [ mid ] ) {\n if ( key >= arr [ l ] && key <= arr [ mid ] ) return search ( arr , l , mid - 1 , key ) ;\n return search ( arr , mid + 1 , h , key ) ;\n }\n if ( key >= arr [ mid ] && key <= arr [ h ] ) return search ( arr , mid + 1 , h , key ) ;\n return search ( arr , l , mid - 1 , key ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef search ( arr , l , h , key ) :\n if l > h :\n return - 1\n mid = ( l + h ) // 2\n if arr [ mid ] == key :\n return mid\n if arr [ l ] <= arr [ mid ] :\n if key >= arr [ l ] and key <= arr [ mid ] :\n return search ( arr , l , mid - 1 , key )\n return search ( arr , mid + 1 , h , key )\n if key >= arr [ mid ] and key <= arr [ h ] :\n return search ( a , mid + 1 , h , key )\n return search ( arr , l , mid - 1 , key )\n\n"
},
{
"id": "python-java-EXPONENTIAL_SQUARING_FAST_MODULO_MULTIPLICATION",
"pair": "python-java",
"Code1": "def exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n",
"Code2": "static long exponentiation ( long base , long exp ) {\n if ( exp == 0 ) return 1 ;\n if ( exp == 1 ) return base % N ;\n long t = exponentiation ( base , exp / 2 ) ;\n t = ( t * t ) % N ;\n if ( exp % 2 == 0 ) return t ;\n else return ( ( base % N ) * t ) % N ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef exponentiation ( bas , exp ) :\n if ( exp == 0 ) :\n return 1\n if ( exp == 1 ) :\n return bas % N\n t = exponentiation ( bas , int ( exp / 2 ) )\n t = ( t * t ) % N\n if ( exp % 2 == 0 ) :\n return t\n else :\n return ( ( bas % N ) * t ) % N\n\n"
},
{
"id": "python-java-DIVISIBILITY_CHECK",
"pair": "python-java",
"Code1": "def divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n",
"Code2": "static void divisibilityCheck ( List < Integer > arr , int n ) {\n List < Integer > s = new ArrayList < Integer > ( ) ;\n int max_ele = Integer . MIN_VALUE ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n s . add ( arr . get ( i ) ) ;\n max_ele = Math . max ( max_ele , arr . get ( i ) ) ;\n }\n LinkedHashSet < Integer > res = new LinkedHashSet < Integer > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( arr . get ( i ) != 0 ) for ( int j = arr . get ( i ) * 2 ;\n j <= max_ele ;\n j += arr . get ( i ) ) {\n if ( s . contains ( j ) ) res . add ( j ) ;\n }\n }\n List < Integer > list = new ArrayList < Integer > ( res ) ;\n Collections . reverse ( list ) ;\n for ( Integer temp : list ) System . out . print ( temp + \" \" ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef divisibilityCheck ( arr , n ) :\n s = dict ( )\n max_ele = - 10 ** 9\n for i in range ( n ) :\n s [ arr [ i ] ] = 1\n max_ele = max ( max_ele , arr [ i ] )\n res = dict ( )\n for i in range ( n ) :\n if ( arr [ i ] != 0 ) :\n for j in range ( arr [ i ] * 2 , max_ele + 1 , arr [ i ] ) :\n if ( j in s.keys ( ) ) :\n res [ j ] = 1\n for x in res :\n print ( x , end = \" \" )\n\n"
},
{
"id": "python-java-FIND_THE_TWO_REPEATING_ELEMENTS_IN_A_GIVEN_ARRAY_3",
"pair": "python-java",
"Code1": "def printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n",
"Code2": "void printRepeating ( int arr [ ] , int size ) {\n int i ;\n System . out . println ( \"The repeating elements are : \" ) ;\n for ( i = 0 ;\n i < size ;\n i ++ ) {\n if ( arr [ Math . abs ( arr [ i ] ) ] > 0 ) arr [ Math . abs ( arr [ i ] ) ] = - arr [ Math . abs ( arr [ i ] ) ] ;\n else System . out . print ( Math . abs ( arr [ i ] ) + \" \" ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printRepeating ( arr , size ) :\n print ( \" The repeating elements are\" , end = \" \" )\n for i in range ( 0 , size ) :\n if ( arr [ abs ( arr [ i ] ) ] > 0 ) :\n arr [ abs ( arr [ i ] ) ] = ( - 1 ) * arr [ abs ( arr [ i ] ) ]\n else :\n print ( abs ( arr [ i ] ) , end = \" \" )\n\n"
},
{
"id": "python-java-DYNAMIC_PROGRAMMING_SET_17_PALINDROME_PARTITIONING",
"pair": "python-java",
"Code1": "def minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n",
"Code2": "static int minPalPartion ( String str ) {\n int n = str . length ( ) ;\n int [ ] [ ] C = new int [ n ] [ n ] ;\n boolean [ ] [ ] P = new boolean [ n ] [ n ] ;\n int i , j , k , L ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n P [ i ] [ i ] = true ;\n C [ i ] [ i ] = 0 ;\n }\n for ( L = 2 ;\n L <= n ;\n L ++ ) {\n for ( i = 0 ;\n i < n - L + 1 ;\n i ++ ) {\n j = i + L - 1 ;\n if ( L == 2 ) P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) ;\n else P [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) ) && P [ i + 1 ] [ j - 1 ] ;\n if ( P [ i ] [ j ] == true ) C [ i ] [ j ] = 0 ;\n else {\n C [ i ] [ j ] = Integer . MAX_VALUE ;\n for ( k = i ;\n k <= j - 1 ;\n k ++ ) C [ i ] [ j ] = Integer . min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 ) ;\n }\n }\n }\n return C [ 0 ] [ n - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minPalPartion ( str ) :\n n = len ( str )\n C = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]\n P = [ [ False for i in range ( n ) ] for i in range ( n ) ]\n j = 0\n k = 0\n L = 0\n for i in range ( n ) :\n P [ i ] [ i ] = True\n C [ i ] [ i ] = 0\n for L in range ( 2 , n + 1 ) :\n for i in range ( n - L + 1 ) :\n j = i + L - 1\n if L == 2 :\n P [ i ] [ j ] = ( str [ i ] == str [ j ] )\n else :\n P [ i ] [ j ] = ( ( str [ i ] == str [ j ] ) and P [ i + 1 ] [ j - 1 ] )\n if P [ i ] [ j ] == True :\n C [ i ] [ j ] = 0\n else :\n C [ i ] [ j ] = 100000000\n for k in range ( i , j ) :\n C [ i ] [ j ] = min ( C [ i ] [ j ] , C [ i ] [ k ] + C [ k + 1 ] [ j ] + 1 )\n return C [ 0 ] [ n - 1 ]\n\n"
},
{
"id": "python-java-HEIGHT_COMPLETE_BINARY_TREE_HEAP_N_NODES",
"pair": "python-java",
"Code1": "def height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n",
"Code2": "static int height ( int N ) {\n return ( int ) Math . ceil ( Math . log ( N + 1 ) / Math . log ( 2 ) ) - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef height ( N ) :\n return math.ceil ( math.log2 ( N + 1 ) ) - 1\n\n"
},
{
"id": "python-java-DISTRIBUTING_ITEMS_PERSON_CANNOT_TAKE_TWO_ITEMS_TYPE_1",
"pair": "python-java",
"Code1": "def checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n",
"Code2": "static boolean checkCount ( int arr [ ] , int n , int k ) {\n HashMap < Integer , Integer > hash = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) {\n if ( ! hash . containsKey ( arr [ i ] ) ) hash . put ( arr [ i ] , 0 ) ;\n hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ;\n }\n for ( Map . Entry x : hash . entrySet ( ) ) if ( ( int ) x . getValue ( ) > 2 * k ) return false ;\n return true ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef checkCount ( arr , n , k ) :\n mp = defaultdict ( lambda : 0 )\n for i in range ( n ) :\n mp [ arr [ i ] ] += 1\n for key , values in mp.items ( ) :\n if values > 2 * k :\n return False\n return True\n\n"
},
{
"id": "python-java-REMOVE_CONSECUTIVE_DUPLICATES_STRING",
"pair": "python-java",
"Code1": "def removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n",
"Code2": "static void removeDuplicates ( char [ ] S ) {\n int n = S . length ;\n if ( n < 2 ) {\n return ;\n }\n int j = 0 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) {\n if ( S [ j ] != S [ i ] ) {\n j ++ ;\n S [ j ] = S [ i ] ;\n }\n }\n System . out . println ( Arrays . copyOfRange ( S , 0 , j + 1 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef removeDuplicates ( S ) :\n n = len ( S )\n if ( n < 2 ) :\n return\n j = 0\n for i in range ( n ) :\n if ( S [ j ] != S [ i ] ) :\n j += 1\n S [ j ] = S [ i ]\n j += 1\n S = S [ : j ]\n return S\n\n"
},
{
"id": "python-java-THIRD_LARGEST_ELEMENT_ARRAY_DISTINCT_ELEMENTS_1",
"pair": "python-java",
"Code1": "def thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n",
"Code2": "static void thirdLargest ( int arr [ ] , int arr_size ) {\n if ( arr_size < 3 ) {\n System . out . printf ( \" Invalid Input \" ) ;\n return ;\n }\n int first = arr [ 0 ] , second = Integer . MIN_VALUE , third = Integer . MIN_VALUE ;\n for ( int i = 1 ;\n i < arr_size ;\n i ++ ) {\n if ( arr [ i ] > first ) {\n third = second ;\n second = first ;\n first = arr [ i ] ;\n }\n else if ( arr [ i ] > second ) {\n third = second ;\n second = arr [ i ] ;\n }\n else if ( arr [ i ] > third ) {\n third = arr [ i ] ;\n }\n }\n System . out . printf ( \"The third Largest element is %d\\n\" , third ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef thirdLargest ( arr , arr_size ) :\n if ( arr_size < 3 ) :\n print ( \" Invalid Input \" )\n return\n first = arr [ 0 ]\n second = - sys.maxsize\n third = - sys.maxsize\n for i in range ( 1 , arr_size ) :\n if ( arr [ i ] > first ) :\n third = second\n second = first\n first = arr [ i ]\n elif ( arr [ i ] > second ) :\n third = second\n second = arr [ i ]\n elif ( arr [ i ] > third ) :\n third = arr [ i ]\n print ( \"The third Largest\" , \"element is\" , third )\n\n"
},
{
"id": "python-java-LONGEST_INCREASING_ODD_EVEN_SUBSEQUENCE",
"pair": "python-java",
"Code1": "def longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n",
"Code2": "public static int longOddEvenIncSeq ( int arr [ ] , int n ) {\n int [ ] lioes = new int [ n ] ;\n int maxLen = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) lioes [ i ] = 1 ;\n for ( int i = 1 ;\n i < n ;\n i ++ ) for ( int j = 0 ;\n j < i ;\n j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ;\n return maxLen ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef longOddEvenIncSeq ( arr , n ) :\n lioes = list ( )\n maxLen = 0\n for i in range ( n ) :\n lioes.append ( 1 )\n i = 1\n for i in range ( n ) :\n for j in range ( i ) :\n if ( arr [ i ] > arr [ j ] and ( arr [ i ] + arr [ j ] ) % 2 != 0 and lioes [ i ] < lioes [ j ] + 1 ) :\n lioes [ i ] = lioes [ j ] + 1\n for i in range ( n ) :\n if maxLen < lioes [ i ] :\n maxLen = lioes [ i ]\n return maxLen\n\n"
},
{
"id": "python-java-ADD_1_TO_A_GIVEN_NUMBER_1",
"pair": "python-java",
"Code1": "def addOne ( x ) :\n return ( - ( ~ x ) )\n",
"Code2": "static int addOne ( int x ) {\n return ( - ( ~ x ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef addOne ( x ) :\n return ( - ( ~ x ) )\n\n"
},
{
"id": "python-java-NUMBER_DECIMAL_NUMBERS_LENGTH_K_STRICT_MONOTONE",
"pair": "python-java",
"Code1": "def getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n",
"Code2": "static int getNumStrictMonotone ( int len ) {\n int [ ] [ ] DP = new int [ len ] [ DP_s ] ;\n for ( int i = 0 ;\n i < DP_s ;\n ++ i ) DP [ 0 ] [ i ] = i + 1 ;\n for ( int i = 1 ;\n i < len ;\n ++ i ) for ( int j = 1 ;\n j < DP_s ;\n ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ;\n return DP [ len - 1 ] [ DP_s - 1 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getNumStrictMonotone ( ln ) :\n DP = [ [ 0 ] * DP_s for _ in range ( ln ) ]\n for i in range ( DP_s ) :\n DP [ 0 ] [ i ] = i + 1\n for i in range ( 1 , ln ) :\n for j in range ( 1 , DP_s ) :\n DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ]\n return DP [ ln - 1 ] [ DP_s - 1 ]\n\n"
},
{
"id": "python-java-SEARCH_ALMOST_SORTED_ARRAY",
"pair": "python-java",
"Code1": "def binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n",
"Code2": "int binarySearch ( int arr [ ] , int l , int r , int x ) {\n if ( r >= l ) {\n int mid = l + ( r - l ) / 2 ;\n if ( arr [ mid ] == x ) return mid ;\n if ( mid > l && arr [ mid - 1 ] == x ) return ( mid - 1 ) ;\n if ( mid < r && arr [ mid + 1 ] == x ) return ( mid + 1 ) ;\n if ( arr [ mid ] > x ) return binarySearch ( arr , l , mid - 2 , x ) ;\n return binarySearch ( arr , mid + 2 , r , x ) ;\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef binarySearch ( arr , l , r , x ) :\n if ( r >= l ) :\n mid = int ( l + ( r - l ) / 2 )\n if ( arr [ mid ] == x ) : return mid\n if ( mid > l and arr [ mid - 1 ] == x ) :\n return ( mid - 1 )\n if ( mid < r and arr [ mid + 1 ] == x ) :\n return ( mid + 1 )\n if ( arr [ mid ] > x ) :\n return binarySearch ( arr , l , mid - 2 , x )\n return binarySearch ( arr , mid + 2 , r , x )\n return - 1\n\n"
},
{
"id": "python-java-BRESENHAMS_LINE_GENERATION_ALGORITHM",
"pair": "python-java",
"Code1": "def bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n",
"Code2": "static void bresenham ( int x1 , int y1 , int x2 , int y2 ) {\n int m_new = 2 * ( y2 - y1 ) ;\n int slope_error_new = m_new - ( x2 - x1 ) ;\n for ( int x = x1 , y = y1 ;\n x <= x2 ;\n x ++ ) {\n System . out . print ( \"(\" + x + \",\" + y + \")\\n\" ) ;\n slope_error_new += m_new ;\n if ( slope_error_new >= 0 ) {\n y ++ ;\n slope_error_new -= 2 * ( x2 - x1 ) ;\n }\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef bresenham ( x1 , y1 , x2 , y2 ) :\n m_new = 2 * ( y2 - y1 )\n slope_error_new = m_new - ( x2 - x1 )\n y = y1\n for x in range ( x1 , x2 + 1 ) :\n print ( \"(\" , x , \",\" , y , \")\\n\" )\n slope_error_new = slope_error_new + m_new\n if ( slope_error_new >= 0 ) :\n y = y + 1\n slope_error_new = slope_error_new - 2 * ( x2 - x1 )\n\n"
},
{
"id": "python-java-HIGHWAY_BILLBOARD_PROBLEM",
"pair": "python-java",
"Code1": "def maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n",
"Code2": "static int maxRevenue ( int m , int [ ] x , int [ ] revenue , int n , int t ) {\n int [ ] maxRev = new int [ m + 1 ] ;\n for ( int i = 0 ;\n i < m + 1 ;\n i ++ ) maxRev [ i ] = 0 ;\n int nxtbb = 0 ;\n for ( int i = 1 ;\n i <= m ;\n i ++ ) {\n if ( nxtbb < n ) {\n if ( x [ nxtbb ] != i ) maxRev [ i ] = maxRev [ i - 1 ] ;\n else {\n if ( i <= t ) maxRev [ i ] = Math . max ( maxRev [ i - 1 ] , revenue [ nxtbb ] ) ;\n else maxRev [ i ] = Math . max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] ) ;\n nxtbb ++ ;\n }\n }\n else maxRev [ i ] = maxRev [ i - 1 ] ;\n }\n return maxRev [ m ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef maxRevenue ( m , x , revenue , n , t ) :\n maxRev = [ 0 ] * ( m + 1 )\n nxtbb = 0\n for i in range ( 1 , m + 1 ) :\n if ( nxtbb < n ) :\n if ( x [ nxtbb ] != i ) :\n maxRev [ i ] = maxRev [ i - 1 ]\n else :\n if ( i <= t ) :\n maxRev [ i ] = max ( maxRev [ i - 1 ] , revenue [ nxtbb ] )\n else :\n maxRev [ i ] = max ( maxRev [ i - t - 1 ] + revenue [ nxtbb ] , maxRev [ i - 1 ] )\n nxtbb += 1\n else :\n maxRev [ i ] = maxRev [ i - 1 ]\n return maxRev [ m ]\n\n"
},
{
"id": "python-java-PROGRAM_FIND_LINE_PASSING_2_POINTS",
"pair": "python-java",
"Code1": "def lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n",
"Code2": "static void lineFromPoints ( Pair P , Pair Q ) {\n int a = Q . second - P . second ;\n int b = P . first - Q . first ;\n int c = a * ( P . first ) + b * ( P . second ) ;\n if ( b < 0 ) {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x \" + b + \"y = \" + c ) ;\n }\n else {\n System . out . println ( \"The line passing through points P and Q is: \" + a + \"x + \" + b + \"y = \" + c ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef lineFromPoints ( P , Q ) :\n a = Q [ 1 ] - P [ 1 ]\n b = P [ 0 ] - Q [ 0 ]\n c = a * ( P [ 0 ] ) + b * ( P [ 1 ] )\n if ( b < 0 ) :\n print ( \"The line passing through points P and Q is:\" , a , \"x \" , b , \"y = \" , c , \"\\n\" )\n else :\n print ( \"The line passing through points P and Q is: \" , a , \"x + \" , b , \"y = \" , c , \"\\n\" )\n\n"
},
{
"id": "python-java-CHINESE_REMAINDER_THEOREM_SET_1_INTRODUCTION",
"pair": "python-java",
"Code1": "def findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n",
"Code2": "static int findMinX ( int num [ ] , int rem [ ] , int k ) {\n int x = 1 ;\n while ( true ) {\n int j ;\n for ( j = 0 ;\n j < k ;\n j ++ ) if ( x % num [ j ] != rem [ j ] ) break ;\n if ( j == k ) return x ;\n x ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMinX ( num , rem , k ) :\n x = 1\n while ( True ) :\n j = 0\n while ( j < k ) :\n if ( x % num [ j ] != rem [ j ] ) :\n break\n j += 1\n if ( j == k ) :\n return x\n x += 1\n\n"
},
{
"id": "python-java-FIND_A_TRIPLET_THAT_SUM_TO_A_GIVEN_VALUE",
"pair": "python-java",
"Code1": "def find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n",
"Code2": "boolean find3Numbers ( int A [ ] , int arr_size , int sum ) {\n int l , r ;\n for ( int i = 0 ;\n i < arr_size - 2 ;\n i ++ ) {\n for ( int j = i + 1 ;\n j < arr_size - 1 ;\n j ++ ) {\n for ( int k = j + 1 ;\n k < arr_size ;\n k ++ ) {\n if ( A [ i ] + A [ j ] + A [ k ] == sum ) {\n System . out . print ( \"Triplet is \" + A [ i ] + \", \" + A [ j ] + \", \" + A [ k ] ) ;\n return true ;\n }\n }\n }\n }\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef find3Numbers ( A , arr_size , sum ) :\n for i in range ( 0 , arr_size - 2 ) :\n for j in range ( i + 1 , arr_size - 1 ) :\n for k in range ( j + 1 , arr_size ) :\n if A [ i ] + A [ j ] + A [ k ] == sum :\n print ( \"Triplet is\" , A [ i ] , \", \" , A [ j ] , \", \" , A [ k ] )\n return True\n return False\n\n"
},
{
"id": "python-java-K_MAXIMUM_SUM_COMBINATIONS_TWO_ARRAYS",
"pair": "python-java",
"Code1": "def KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n",
"Code2": "static void KMaxCombinations ( int A [ ] , int B [ ] , int N , int K ) {\n PriorityQueue < Integer > pq = new PriorityQueue < Integer > ( Collections . reverseOrder ( ) ) ;\n for ( int i = 0 ;\n i < N ;\n i ++ ) for ( int j = 0 ;\n j < N ;\n j ++ ) pq . add ( A [ i ] + B [ j ] ) ;\n int count = 0 ;\n while ( count < K ) {\n System . out . println ( pq . peek ( ) ) ;\n pq . remove ( ) ;\n count ++ ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef KMaxCombinations ( A , B , N , K ) :\n pq = PriorityQueue ( )\n for i in range ( 0 , N ) :\n for j in range ( 0 , N ) :\n a = A [ i ] + B [ j ]\n pq.put ( ( - a , a ) )\n count = 0\n while ( count < K ) :\n print ( pq.get ( ) [ 1 ] )\n count = count + 1\n\n"
},
{
"id": "python-java-TRIANGULAR_MATCHSTICK_NUMBER",
"pair": "python-java",
"Code1": "def numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n",
"Code2": "public static int numberOfSticks ( int x ) {\n return ( 3 * x * ( x + 1 ) ) / 2 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef numberOfSticks ( x ) :\n return ( 3 * x * ( x + 1 ) ) / 2\n\n"
},
{
"id": "python-java-COUNT_SUBSTRINGS_WITH_SAME_FIRST_AND_LAST_CHARACTERS_1",
"pair": "python-java",
"Code1": "def countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n",
"Code2": "static int countSubstringWithEqualEnds ( String s ) {\n int result = 0 ;\n int n = s . length ( ) ;\n int [ ] count = new int [ MAX_CHAR ] ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < MAX_CHAR ;\n i ++ ) result += ( count [ i ] * ( count [ i ] + 1 ) / 2 ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef countSubstringWithEqualEnds ( s ) :\n result = 0\n n = len ( s )\n count = [ 0 ] * MAX_CHAR\n for i in range ( n ) :\n count [ ord ( s [ i ] ) - ord ( 'a' ) ] += 1\n for i in range ( MAX_CHAR ) :\n result += ( count [ i ] * ( count [ i ] + 1 ) / 2 )\n return result\n\n"
},
{
"id": "python-java-DIVISIBILITY_BY_7",
"pair": "python-java",
"Code1": "def isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n",
"Code2": "static boolean isDivisibleBy7 ( int num ) {\n if ( num < 0 ) return isDivisibleBy7 ( - num ) ;\n if ( num == 0 || num == 7 ) return true ;\n if ( num < 10 ) return false ;\n return isDivisibleBy7 ( num / 10 - 2 * ( num - num / 10 * 10 ) ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isDivisibleBy7 ( num ) :\n if num < 0 :\n return isDivisibleBy7 ( - num )\n if ( num == 0 or num == 7 ) :\n return True\n if ( num < 10 ) :\n return False\n return isDivisibleBy7 ( num // 10 - 2 * ( num - num // 10 * 10 ) )\n\n"
},
{
"id": "python-java-FIND_ONE_MULTIPLE_REPEATING_ELEMENTS_READ_ARRAY",
"pair": "python-java",
"Code1": "def findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n",
"Code2": "static int findRepeatingNumber ( int [ ] arr , int n ) {\n int sq = ( int ) Math . sqrt ( n ) ;\n int range = ( n / sq ) + 1 ;\n int [ ] count = new int [ range ] ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n count [ ( arr [ i ] - 1 ) / sq ] ++ ;\n }\n int selected_block = range - 1 ;\n for ( int i = 0 ;\n i < range - 1 ;\n i ++ ) {\n if ( count [ i ] > sq ) {\n selected_block = i ;\n break ;\n }\n }\n HashMap < Integer , Integer > m = new HashMap < > ( ) ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) {\n m . put ( arr [ i ] , 1 ) ;\n if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ;\n }\n }\n return - 1 ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRepeatingNumber ( arr , n ) :\n sq = sqrt ( n )\n range__ = int ( ( n / sq ) + 1 )\n count = [ 0 for i in range ( range__ ) ]\n for i in range ( 0 , n + 1 , 1 ) :\n count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1\n selected_block = range__ - 1\n for i in range ( 0 , range__ - 1 , 1 ) :\n if ( count [ i ] > sq ) :\n selected_block = i\n break\n m = { i : 0 for i in range ( n ) }\n for i in range ( 0 , n + 1 , 1 ) :\n if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :\n m [ arr [ i ] ] += 1\n if ( m [ arr [ i ] ] > 1 ) :\n return arr [ i ]\n return - 1\n\n"
},
{
"id": "python-java-FIND_N_TH_ELEMENT_FROM_STERNS_DIATOMIC_SERIES",
"pair": "python-java",
"Code1": "def findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n",
"Code2": "static int findSDSFunc ( int n ) {\n int DP [ ] = new int [ n + 1 ] ;\n DP [ 0 ] = 0 ;\n DP [ 1 ] = 1 ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n if ( i % 2 == 0 ) DP [ i ] = DP [ i / 2 ] ;\n else DP [ i ] = DP [ ( i - 1 ) / 2 ] + DP [ ( i + 1 ) / 2 ] ;\n }\n return DP [ n ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSDSFunc ( n ) :\n DP = [ 0 ] * ( n + 1 )\n DP [ 0 ] = 0\n DP [ 1 ] = 1\n for i in range ( 2 , n + 1 ) :\n if ( int ( i % 2 ) == 0 ) :\n DP [ i ] = DP [ int ( i / 2 ) ]\n else :\n DP [ i ] = ( DP [ int ( ( i - 1 ) / 2 ) ] + DP [ int ( ( i + 1 ) / 2 ) ] )\n return DP [ n ]\n\n"
},
{
"id": "python-java-RECURSIVE_C_PROGRAM_LINEARLY_SEARCH_ELEMENT_GIVEN_ARRAY",
"pair": "python-java",
"Code1": "def recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n",
"Code2": "static int recSearch ( int arr [ ] , int l , int r , int x ) {\n if ( r < l ) return - 1 ;\n if ( arr [ l ] == x ) return l ;\n if ( arr [ r ] == x ) return r ;\n return recSearch ( arr , l + 1 , r - 1 , x ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef recSearch ( arr , l , r , x ) :\n if r < l :\n return - 1\n if arr [ l ] == x :\n return l\n if arr [ r ] == x :\n return r\n return recSearch ( arr , l + 1 , r - 1 , x )\n\n"
},
{
"id": "python-java-CHECK_LARGE_NUMBER_DIVISIBLE_4_NOT",
"pair": "python-java",
"Code1": "def check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n",
"Code2": "static boolean check ( String str ) {\n int n = str . length ( ) ;\n if ( n == 0 ) return false ;\n if ( n == 1 ) return ( ( str . charAt ( 0 ) - ' 0 ' ) % 4 == 0 ) ;\n int last = str . charAt ( n - 1 ) - ' 0 ' ;\n int second_last = str . charAt ( n - 2 ) - ' 0 ' ;\n return ( ( second_last * 10 + last ) % 4 == 0 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef check ( st ) :\n n = len ( st )\n if ( n == 0 ) :\n return False\n if ( n == 1 ) :\n return ( ( st [ 0 ] - '0' ) % 4 == 0 )\n last = ( int ) ( st [ n - 1 ] )\n second_last = ( int ) ( st [ n - 2 ] )\n return ( ( second_last * 10 + last ) % 4 == 0 )\n\n"
},
{
"id": "python-java-LOWER_CASE_UPPER_CASE_INTERESTING_FACT",
"pair": "python-java",
"Code1": "def to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n",
"Code2": "static String to_upper ( char [ ] in ) {\n for ( int i = 0 ;\n i < in . length ;\n i ++ ) {\n if ( ' a ' <= in [ i ] & in [ i ] <= ' z ' ) {\n in [ i ] = ( char ) ( in [ i ] - ' a ' + ' A ' ) ;\n }\n }\n return String . valueOf ( in ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef to_upper ( string ) :\n for i in range ( len ( string ) ) :\n if ( 'a' <= string [ i ] <= 'z' ) :\n string = ( string [ 0 : i ] + chr ( ord ( string [ i ] ) - ord ( 'a' ) + ord ( 'A' ) ) + string [ i + 1 : ] )\n return string\n\n"
},
{
"id": "python-java-REMOVE_MINIMUM_NUMBER_CHARACTERS_TWO_STRINGS_BECOME_ANAGRAM",
"pair": "python-java",
"Code1": "def remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n",
"Code2": "static int remAnagram ( String str1 , String str2 ) {\n int count1 [ ] = new int [ 26 ] ;\n int count2 [ ] = new int [ 26 ] ;\n for ( int i = 0 ;\n i < str1 . length ( ) ;\n i ++ ) count1 [ str1 . charAt ( i ) - ' a ' ] ++ ;\n for ( int i = 0 ;\n i < str2 . length ( ) ;\n i ++ ) count2 [ str2 . charAt ( i ) - ' a ' ] ++ ;\n int result = 0 ;\n for ( int i = 0 ;\n i < 26 ;\n i ++ ) result += Math . abs ( count1 [ i ] - count2 [ i ] ) ;\n return result ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef remAnagram ( str1 , str2 ) :\n count1 = [ 0 ] * CHARS\n count2 = [ 0 ] * CHARS\n i = 0\n while i < len ( str1 ) :\n count1 [ ord ( str1 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n i = 0\n while i < len ( str2 ) :\n count2 [ ord ( str2 [ i ] ) - ord ( 'a' ) ] += 1\n i += 1\n result = 0\n for i in range ( 26 ) :\n result += abs ( count1 [ i ] - count2 [ i ] )\n return result\n\n"
},
{
"id": "python-java-SORT_ARRAY_WAVE_FORM_2_1",
"pair": "python-java",
"Code1": "def sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n",
"Code2": "void sortInWave ( int arr [ ] , int n ) {\n for ( int i = 0 ;\n i < n ;\n i += 2 ) {\n if ( i > 0 && arr [ i - 1 ] > arr [ i ] ) swap ( arr , i - 1 , i ) ;\n if ( i < n - 1 && arr [ i ] < arr [ i + 1 ] ) swap ( arr , i , i + 1 ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef sortInWave ( arr , n ) :\n for i in range ( 0 , n , 2 ) :\n if ( i > 0 and arr [ i ] < arr [ i - 1 ] ) :\n arr [ i ] , arr [ i - 1 ] = arr [ i - 1 ] , arr [ i ]\n if ( i < n - 1 and arr [ i ] < arr [ i + 1 ] ) :\n arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ]\n\n"
},
{
"id": "python-java-FORM_MINIMUM_NUMBER_FROM_GIVEN_SEQUENCE_1",
"pair": "python-java",
"Code1": "def getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n",
"Code2": "static String getMinNumberForPattern ( String seq ) {\n int n = seq . length ( ) ;\n if ( n >= 9 ) return \"-1\" ;\n char result [ ] = new char [ n + 1 ] ;\n int count = 1 ;\n for ( int i = 0 ;\n i <= n ;\n i ++ ) {\n if ( i == n || seq . charAt ( i ) == ' I ' ) {\n for ( int j = i - 1 ;\n j >= - 1 ;\n j -- ) {\n result [ j + 1 ] = ( char ) ( ( int ) ' 0 ' + count ++ ) ;\n if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ;\n }\n }\n }\n return new String ( result ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getMinNumberForPattern ( seq ) :\n n = len ( seq )\n if ( n >= 9 ) :\n return \"-1\"\n result = [ None ] * ( n + 1 )\n count = 1\n for i in range ( n + 1 ) :\n if ( i == n or seq [ i ] == 'I' ) :\n for j in range ( i - 1 , - 2 , - 1 ) :\n result [ j + 1 ] = int ( '0' + str ( count ) )\n count += 1\n if ( j >= 0 and seq [ j ] == 'I' ) :\n break\n return result\n\n"
},
{
"id": "python-java-CHECK_IF_STRING_REMAINS_PALINDROME_AFTER_REMOVING_GIVEN_NUMBER_OF_CHARACTERS",
"pair": "python-java",
"Code1": "def isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n",
"Code2": "static boolean isPossible ( String str , int n ) {\n int len = str . length ( ) ;\n if ( len >= n ) return true ;\n return false ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef isPossible ( str , n ) :\n l = len ( str )\n if ( l >= n ) :\n return True\n return False\n\n"
},
{
"id": "python-java-FIND_CENTER_CIRCLE_USING_ENDPOINTS_DIAMETER",
"pair": "python-java",
"Code1": "def center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n",
"Code2": "static void center ( int x1 , int x2 , int y1 , int y2 ) {\n System . out . print ( ( float ) ( x1 + x2 ) / 2 + \", \" + ( float ) ( y1 + y2 ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef center ( x1 , x2 , y1 , y2 ) :\n print ( int ( ( x1 + x2 ) / 2 ) , end = \"\" )\n print ( \",\" , int ( ( y1 + y2 ) / 2 ) )\n\n"
},
{
"id": "python-java-GREEDY_ALGORITHM_TO_FIND_MINIMUM_NUMBER_OF_COINS",
"pair": "python-java",
"Code1": "def findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n",
"Code2": "static void findMin ( int V ) {\n Vector < Integer > ans = new Vector < > ( ) ;\n for ( int i = n - 1 ;\n i >= 0 ;\n i -- ) {\n while ( V >= deno [ i ] ) {\n V -= deno [ i ] ;\n ans . add ( deno [ i ] ) ;\n }\n }\n for ( int i = 0 ;\n i < ans . size ( ) ;\n i ++ ) {\n System . out . print ( \" \" + ans . elementAt ( i ) ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findMin ( V ) :\n deno = [ 1 , 2 , 5 , 10 , 20 , 50 , 100 , 500 , 1000 ]\n n = len ( deno )\n ans = [ ]\n i = n - 1\n while ( i >= 0 ) :\n while ( V >= deno [ i ] ) :\n V -= deno [ i ]\n ans.append ( deno [ i ] )\n i -= 1\n for i in range ( len ( ans ) ) :\n print ( ans [ i ] , end = \" \" )\n\n"
},
{
"id": "python-java-HOW_TO_AVOID_OVERFLOW_IN_MODULAR_MULTIPLICATION",
"pair": "python-java",
"Code1": "def mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n",
"Code2": "static long mulmod ( long a , long b , long mod ) {\n long res = 0 ;\n a = a % mod ;\n while ( b > 0 ) {\n if ( b % 2 == 1 ) {\n res = ( res + a ) % mod ;\n }\n a = ( a * 2 ) % mod ;\n b /= 2 ;\n }\n return res % mod ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef mulmod ( a , b , mod ) :\n res = 0\n a = a % mod\n while ( b > 0 ) :\n if ( b % 2 == 1 ) :\n res = ( res + a ) % mod\n a = ( a * 2 ) % mod\n b //= 2\n return res % mod\n\n"
},
{
"id": "python-java-FIND_NTH_TERM_DRAGON_CURVE_SEQUENCE",
"pair": "python-java",
"Code1": "def Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n",
"Code2": "static String Dragon_Curve_Sequence ( int n ) {\n String s = \"1\" ;\n for ( int i = 2 ;\n i <= n ;\n i ++ ) {\n String temp = \"1\" ;\n char prev = ' 1 ' , zero = ' 0 ' , one = ' 1 ' ;\n for ( int j = 0 ;\n j < s . length ( ) ;\n j ++ ) {\n temp += s . charAt ( j ) ;\n if ( prev == ' 0 ' ) {\n temp += one ;\n prev = one ;\n }\n else {\n temp += zero ;\n prev = zero ;\n }\n }\n s = temp ;\n }\n return s ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef Dragon_Curve_Sequence ( n ) :\n s = \"1\"\n for i in range ( 2 , n + 1 ) :\n temp = \"1\"\n prev = '1'\n zero = '0'\n one = '1'\n for j in range ( len ( s ) ) :\n temp += s [ j ]\n if ( prev == '0' ) :\n temp += one\n prev = one\n else :\n temp += zero\n prev = zero\n s = temp\n return s\n\n"
},
{
"id": "python-java-MINIMUM_POSITIVE_POINTS_TO_REACH_DESTINATION",
"pair": "python-java",
"Code1": "def minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n",
"Code2": "static int minInitialPoints ( int points [ ] [ ] , int R , int C ) {\n int dp [ ] [ ] = new int [ R ] [ C ] ;\n int m = R , n = C ;\n dp [ m - 1 ] [ n - 1 ] = points [ m - 1 ] [ n - 1 ] > 0 ? 1 : Math . abs ( points [ m - 1 ] [ n - 1 ] ) + 1 ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) dp [ i ] [ n - 1 ] = Math . max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 ) ;\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) dp [ m - 1 ] [ j ] = Math . max ( dp [ m - 1 ] [ j + 1 ] - points [ m - 1 ] [ j ] , 1 ) ;\n for ( int i = m - 2 ;\n i >= 0 ;\n i -- ) {\n for ( int j = n - 2 ;\n j >= 0 ;\n j -- ) {\n int min_points_on_exit = Math . min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] ) ;\n dp [ i ] [ j ] = Math . max ( min_points_on_exit - points [ i ] [ j ] , 1 ) ;\n }\n }\n return dp [ 0 ] [ 0 ] ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef minInitialPoints ( points ) :\n dp = [ [ 0 for x in range ( C + 1 ) ] for y in range ( R + 1 ) ]\n m , n = R , C\n if points [ m - 1 ] [ n - 1 ] > 0 :\n dp [ m - 1 ] [ n - 1 ] = 1\n else :\n dp [ m - 1 ] [ n - 1 ] = abs ( points [ m - 1 ] [ n - 1 ] ) + 1\n for i in range ( m - 2 , - 1 , - 1 ) :\n dp [ i ] [ n - 1 ] = max ( dp [ i + 1 ] [ n - 1 ] - points [ i ] [ n - 1 ] , 1 )\n for i in range ( 2 , - 1 , - 1 ) :\n dp [ m - 1 ] [ i ] = max ( dp [ m - 1 ] [ i + 1 ] - points [ m - 1 ] [ i ] , 1 )\n for i in range ( m - 2 , - 1 , - 1 ) :\n for j in range ( n - 2 , - 1 , - 1 ) :\n min_points_on_exit = min ( dp [ i + 1 ] [ j ] , dp [ i ] [ j + 1 ] )\n dp [ i ] [ j ] = max ( min_points_on_exit - points [ i ] [ j ] , 1 )\n return dp [ 0 ] [ 0 ]\n\n"
},
{
"id": "python-java-FIND_REPETITIVE_ELEMENT_1_N_1",
"pair": "python-java",
"Code1": "def findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n",
"Code2": "static int findRepeating ( int [ ] arr , int n ) {\n int sum = 0 ;\n for ( int i = 0 ;\n i < n ;\n i ++ ) sum += arr [ i ] ;\n return sum - ( ( ( n - 1 ) * n ) / 2 ) ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findRepeating ( arr , n ) :\n return sum ( arr ) - ( ( ( n - 1 ) * n ) // 2 )\n\n"
},
{
"id": "python-java-C_PROGRAM_FIND_SECOND_FREQUENT_CHARACTER",
"pair": "python-java",
"Code1": "def getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n",
"Code2": "static char getSecondMostFreq ( String str ) {\n int [ ] count = new int [ NO_OF_CHARS ] ;\n int i ;\n for ( i = 0 ;\n i < str . length ( ) ;\n i ++ ) ( count [ str . charAt ( i ) ] ) ++ ;\n int first = 0 , second = 0 ;\n for ( i = 0 ;\n i < NO_OF_CHARS ;\n i ++ ) {\n if ( count [ i ] > count [ first ] ) {\n second = first ;\n first = i ;\n }\n else if ( count [ i ] > count [ second ] && count [ i ] != count [ first ] ) second = i ;\n }\n return ( char ) second ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef getSecondMostFreq ( str ) :\n NO_OF_CHARS = 256\n count = [ 0 ] * NO_OF_CHARS\n for i in range ( len ( str ) ) :\n count [ ord ( str [ i ] ) ] += 1\n first , second = 0 , 0\n for i in range ( NO_OF_CHARS ) :\n if count [ i ] > count [ first ] :\n second = first\n first = i\n elif ( count [ i ] > count [ second ] and count [ i ] != count [ first ] ) :\n second = i\n return chr ( second )\n\n"
},
{
"id": "python-java-SUM_TWO_LARGE_NUMBERS",
"pair": "python-java",
"Code1": "def findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n",
"Code2": "static String findSum ( String str1 , String str2 ) {\n if ( str1 . length ( ) > str2 . length ( ) ) {\n String t = str1 ;\n str1 = str2 ;\n str2 = t ;\n }\n String str = \"\" ;\n int n1 = str1 . length ( ) , n2 = str2 . length ( ) ;\n str1 = new StringBuilder ( str1 ) . reverse ( ) . toString ( ) ;\n str2 = new StringBuilder ( str2 ) . reverse ( ) . toString ( ) ;\n int carry = 0 ;\n for ( int i = 0 ;\n i < n1 ;\n i ++ ) {\n int sum = ( ( int ) ( str1 . charAt ( i ) - ' 0 ' ) + ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n for ( int i = n1 ;\n i < n2 ;\n i ++ ) {\n int sum = ( ( int ) ( str2 . charAt ( i ) - ' 0 ' ) + carry ) ;\n str += ( char ) ( sum % 10 + ' 0 ' ) ;\n carry = sum / 10 ;\n }\n if ( carry > 0 ) str += ( char ) ( carry + ' 0 ' ) ;\n str = new StringBuilder ( str ) . reverse ( ) . toString ( ) ;\n return str ;\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef findSum ( str1 , str2 ) :\n if ( len ( str1 ) > len ( str2 ) ) :\n t = str1\n str1 = str2\n str2 = t\n str = \"\"\n n1 = len ( str1 )\n n2 = len ( str2 )\n str1 = str1 [ : : - 1 ]\n str2 = str2 [ : : - 1 ]\n carry = 0\n for i in range ( n1 ) :\n sum = ( ( ord ( str1 [ i ] ) - 48 ) + ( ( ord ( str2 [ i ] ) - 48 ) + carry ) )\n str += chr ( sum % 10 + 48 )\n carry = int ( sum / 10 )\n for i in range ( n1 , n2 ) :\n sum = ( ( ord ( str2 [ i ] ) - 48 ) + carry )\n str += chr ( sum % 10 + 48 )\n carry = ( int ) ( sum / 10 )\n if ( carry ) :\n str += chr ( carry + 48 )\n str = str [ : : - 1 ]\n return str\n\n"
},
{
"id": "python-java-NEXT_GREATER_ELEMENT",
"pair": "python-java",
"Code1": "def printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n",
"Code2": "static void printNGE ( int arr [ ] , int n ) {\n int next , i , j ;\n for ( i = 0 ;\n i < n ;\n i ++ ) {\n next = - 1 ;\n for ( j = i + 1 ;\n j < n ;\n j ++ ) {\n if ( arr [ i ] < arr [ j ] ) {\n next = arr [ j ] ;\n break ;\n }\n }\n System . out . println ( arr [ i ] + \" -- \" + next ) ;\n }\n}\n",
"instruction": "Translate the given code from python to java. The input Code is marked with and .",
"input": "\ndef printNGE ( arr ) :\n for i in range ( 0 , len ( arr ) , 1 ) :\n next = - 1\n for j in range ( i + 1 , len ( arr ) , 1 ) :\n if arr [ i ] < arr [ j ] :\n next = arr [ j ]\n break\n print ( str ( arr [ i ] ) + \" -- \" + str ( next ) )\n\n"
}
]