class Funny { static boolean checkFunny ( String word ) { int i = 1 ; int j = word . length ( ) - 2 ; word = word . toLowerCase ( ) ; while ( i <= j ) { if ( ( Math . abs ( word . charAt ( i ) - word . charAt ( i - 1 ) ) ) != Math . abs ( ( word . charAt ( j ) - word . charAt ( j + 1 ) ) ) ) return false ; i ++ ; j -- ; } return true ; } static void printFunnyWords ( String str ) { str = str + " ▁ " ; String word = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch != ' ▁ ' ) word = word + ch ; else { if ( Funny . checkFunny ( word ) ) System . out . println ( word ) ; word = " " ; } } } public static void main ( String [ ] args ) { Funny . printFunnyWords ( " Miss ▁ Arora ▁ teaches ▁ us ▁ malayalam ▁ bdwy ▁ " ) ; } }

def checkFunny ( word ) : NEW_LINE INDENT i = 1 NEW_LINE j = len ( word ) - 2 NEW_LINE word = word . lower ( ) NEW_LINE while ( i <= j ) : NEW_LINE INDENT if ( ( abs ( ord ( word [ i ] ) - ord ( word [ i - 1 ] ) ) ) != abs ( ( ord ( word [ j ] ) - ord ( word [ j + 1 ] ) ) ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = i + 1 NEW_LINE j = j - 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def printFunnyWords ( str ) : NEW_LINE INDENT str = str + " ▁ " NEW_LINE word = " " NEW_LINE i = 0 NEW_LINE for i in range ( len ( str ) ) : NEW_LINE INDENT ch = str [ i ] NEW_LINE if ( ch != ' ▁ ' ) : NEW_LINE INDENT word = word + ch NEW_LINE DEDENT else : NEW_LINE INDENT if ( checkFunny ( word ) ) : NEW_LINE INDENT print ( word ) NEW_LINE DEDENT word = " " NEW_LINE DEDENT DEDENT DEDENT printFunnyWords ( " Miss ▁ Arora ▁ teaches ▁ us ▁ malayalam ▁ bdwy ▁ " ) NEW_LINE


class GFG { static String find_Square_369 ( String num ) { char a , b , c , d ; if ( num . charAt ( 0 ) == '3' ) { a = '1' ; b = '0' ; c = '8' ; d = '9' ; } else if ( num . charAt ( 0 ) == '6' ) { a = '4' ; b = '3' ; c = '5' ; d = '6' ; } else { a = '9' ; b = '8' ; c = '0' ; d = '1' ; } String result = " " ; int size = num . length ( ) ; for ( int i = 1 ; i < size ; i ++ ) result += a ; result += b ; for ( int i = 1 ; i < size ; i ++ ) result += c ; result += d ; return result ; } public static void main ( String [ ] args ) { String num_3 , num_6 , num_9 ; num_3 = "3333" ; num_6 = "6666" ; num_9 = "9999" ; String result = " " ; result = find_Square_369 ( num_3 ) ; System . out . println ( " Square ▁ of ▁ " + num_3 + " ▁ is ▁ : ▁ " + result ) ; result = find_Square_369 ( num_6 ) ; System . out . println ( " Square ▁ of ▁ " + num_9 + " ▁ is ▁ : ▁ " + result ) ; result = find_Square_369 ( num_9 ) ; System . out . println ( " Square ▁ of ▁ " + num_9 + " ▁ is ▁ : ▁ " + result ) ; } }

def find_Square_369 ( num ) : NEW_LINE INDENT if ( num [ 0 ] == '3' ) : NEW_LINE INDENT a = '1' NEW_LINE b = '0' NEW_LINE c = '8' NEW_LINE d = '9' NEW_LINE DEDENT elif ( num [ 0 ] == '6' ) : NEW_LINE INDENT a = '4' NEW_LINE b = '3' NEW_LINE c = '5' NEW_LINE d = '6' NEW_LINE DEDENT else : NEW_LINE INDENT a = '9' NEW_LINE b = '8' NEW_LINE c = '0' NEW_LINE d = '1' NEW_LINE DEDENT result = " " NEW_LINE size = len ( num ) NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT result += a NEW_LINE DEDENT result += b NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT result += c NEW_LINE DEDENT result += d NEW_LINE return result NEW_LINE DEDENT num_3 = "3333" NEW_LINE num_6 = "6666" NEW_LINE num_9 = "9999" NEW_LINE result = " " NEW_LINE result = find_Square_369 ( num_3 ) NEW_LINE print ( " Square ▁ of ▁ " + num_3 + " ▁ is ▁ : ▁ " + result ) ; NEW_LINE result = find_Square_369 ( num_6 ) NEW_LINE print ( " Square ▁ of ▁ " + num_6 + " ▁ is ▁ : ▁ " + result ) ; NEW_LINE result = find_Square_369 ( num_9 ) NEW_LINE print ( " Square ▁ of ▁ " + num_9 + " ▁ is ▁ : ▁ " + result ) ; NEW_LINE


class GFG { static int longestAlternatingSubarray ( int a [ ] , int n ) { int longest = 1 ; int cnt = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] * a [ i - 1 ] < 0 ) { cnt ++ ; longest = Math . max ( longest , cnt ) ; } else cnt = 1 ; } return longest ; } public static void main ( String [ ] args ) { int a [ ] = { - 5 , - 1 , - 1 , 2 , - 2 , - 3 } ; int n = a . length ; System . out . println ( longestAlternatingSubarray ( a , n ) ) ; } }

def longestAlternatingSubarray ( a , n ) : NEW_LINE INDENT longest = 1 NEW_LINE cnt = 1 NEW_LINE i = 1 NEW_LINE while i < n : NEW_LINE INDENT if ( a [ i ] * a [ i - 1 ] < 0 ) : NEW_LINE INDENT cnt = cnt + 1 NEW_LINE longest = max ( longest , cnt ) NEW_LINE DEDENT else : NEW_LINE INDENT cnt = 1 NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT return longest NEW_LINE DEDENT a = [ - 5 , - 1 , - 1 , 2 , - 2 , - 3 ] NEW_LINE n = len ( a ) NEW_LINE print ( longestAlternatingSubarray ( a , n ) ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class Main { static void converthenumber ( int n ) { String s = Integer . toString ( n ) ; String res = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' || s . charAt ( i ) == '3' || s . charAt ( i ) == '5' || s . charAt ( i ) == '7' || s . charAt ( i ) == '9' ) res += s . charAt ( i ) ; if ( res . length ( ) == 2 ) break ; } if ( res . length ( ) == 2 ) System . out . println ( res ) ; else System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { int n = 18720 ; converthenumber ( n ) ; } }

def converthenumber ( n ) : NEW_LINE INDENT s = str ( n ) ; NEW_LINE res = " " ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] == '1' or s [ i ] == '3' or s [ i ] == '5' or s [ i ] == '7' or s [ i ] == '9' ) : NEW_LINE INDENT res += s [ i ] ; NEW_LINE DEDENT if ( len ( res ) == 2 ) : NEW_LINE INDENT break ; NEW_LINE DEDENT DEDENT if ( len ( res ) == 2 ) : NEW_LINE INDENT print ( res ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " - 1" ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 18720 ; NEW_LINE converthenumber ( n ) ; NEW_LINE DEDENT


class GFG { static long productAscii ( String str ) { long prod = 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { prod *= str . charAt ( i ) ; } return prod ; } public static void main ( String [ ] args ) { String str = " GfG " ; System . out . println ( productAscii ( str ) ) ; } }

def productAscii ( str ) : NEW_LINE INDENT prod = 1 NEW_LINE for i in range ( 0 , len ( str ) ) : NEW_LINE INDENT prod = prod * ord ( str [ i ] ) NEW_LINE DEDENT return prod NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " GfG " NEW_LINE print ( productAscii ( str ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int count_carry ( String a , String b ) { int carry = 0 ; int count = 0 ; int len_a = a . length ( ) , len_b = b . length ( ) ; while ( len_a != 0 || len_b != 0 ) { int x = 0 , y = 0 ; if ( len_a > 0 ) { x = a . charAt ( len_a - 1 ) - '0' ; len_a -- ; } if ( len_b > 0 ) { y = b . charAt ( len_b - 1 ) - '0' ; len_b -- ; } int sum = x + y + carry ; if ( sum >= 10 ) { carry = 1 ; count ++ ; } else carry = 0 ; } return count ; } public static void main ( String [ ] args ) { String a = "9555" , b = "555" ; int count = count_carry ( a , b ) ; if ( count == 0 ) System . out . println ( "0 \n " ) ; else if ( count == 1 ) System . out . println ( "1 \n " ) ; else System . out . println ( count ) ; } }

def count_carry ( a , b ) : NEW_LINE INDENT carry = 0 ; NEW_LINE count = 0 ; NEW_LINE len_a = len ( a ) ; NEW_LINE len_b = len ( b ) ; NEW_LINE while ( len_a != 0 or len_b != 0 ) : NEW_LINE INDENT x = 0 ; NEW_LINE y = 0 ; NEW_LINE if ( len_a > 0 ) : NEW_LINE INDENT x = int ( a [ len_a - 1 ] ) + int ( '0' ) ; NEW_LINE len_a -= 1 ; NEW_LINE DEDENT if ( len_b > 0 ) : NEW_LINE INDENT y = int ( b [ len_b - 1 ] ) + int ( '0' ) ; NEW_LINE len_b -= 1 ; NEW_LINE DEDENT sum = x + y + carry ; NEW_LINE if ( sum >= 10 ) : NEW_LINE INDENT carry = 1 ; NEW_LINE count += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT carry = 0 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT a = "9555" ; NEW_LINE b = "555" ; NEW_LINE count = count_carry ( a , b ) ; NEW_LINE if ( count == 0 ) : NEW_LINE INDENT print ( "0" ) ; NEW_LINE DEDENT elif ( count == 1 ) : NEW_LINE INDENT print ( "1" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( count ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int xorPairSum ( int ar [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) sum = sum ^ ( ar [ i ] + ar [ j ] ) ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . print ( xorPairSum ( arr , n ) ) ; } }

def xor_pair_sum ( ar , n ) : NEW_LINE INDENT total = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT total = total ^ ( ar [ i ] + ar [ j ] ) NEW_LINE DEDENT DEDENT return total NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT data = [ 1 , 2 , 3 ] NEW_LINE print ( xor_pair_sum ( data , len ( data ) ) ) NEW_LINE DEDENT


class MaximumDiffrence { int maxDiff ( int arr [ ] , int n ) { int diff [ ] = new int [ n - 1 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) diff [ i ] = arr [ i + 1 ] - arr [ i ] ; int max_diff = diff [ 0 ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( diff [ i - 1 ] > 0 ) diff [ i ] += diff [ i - 1 ] ; if ( max_diff < diff [ i ] ) max_diff = diff [ i ] ; } return max_diff ; } public static void main ( String [ ] args ) { MaximumDiffrence mxdif = new MaximumDiffrence ( ) ; int arr [ ] = { 80 , 2 , 6 , 3 , 100 } ; int size = arr . length ; System . out . println ( mxdif . maxDiff ( arr , size ) ) ; } }

def maxDiff ( arr , n ) : NEW_LINE INDENT diff = [ 0 ] * ( n - 1 ) NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT diff [ i ] = arr [ i + 1 ] - arr [ i ] NEW_LINE DEDENT max_diff = diff [ 0 ] NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( diff [ i - 1 ] > 0 ) : NEW_LINE INDENT diff [ i ] += diff [ i - 1 ] NEW_LINE DEDENT if ( max_diff < diff [ i ] ) : NEW_LINE INDENT max_diff = diff [ i ] NEW_LINE DEDENT DEDENT return max_diff NEW_LINE DEDENT arr = [ 80 , 2 , 6 , 3 , 100 ] NEW_LINE size = len ( arr ) NEW_LINE print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , size ) ) NEW_LINE


import java . io . * ; import java . lang . * ; public class GFG { static int perfectSquare ( String s ) { int n = s . length ( ) ; int ans = - 1 ; String num = " " ; for ( int i = 1 ; i < ( 1 << n ) ; i ++ ) { String str = " " ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( ( i >> j ) & 1 ) == 1 ) { str += s . charAt ( j ) ; } } if ( str . charAt ( 0 ) != '0' ) { int temp = 0 ; for ( int j = 0 ; j < str . length ( ) ; j ++ ) temp = temp * 10 + ( int ) ( str . charAt ( j ) - '0' ) ; int k = ( int ) Math . sqrt ( temp ) ; if ( k * k == temp ) { if ( ans < ( int ) str . length ( ) ) { ans = ( int ) str . length ( ) ; num = str ; } } } } if ( ans == - 1 ) return ans ; else { System . out . print ( num + " ▁ " ) ; return n - ans ; } } public static void main ( String args [ ] ) { System . out . println ( perfectSquare ( "8314" ) ) ; System . out . println ( perfectSquare ( "753" ) ) ; } }

import math NEW_LINE def perfectSquare ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE ans = - 1 NEW_LINE num = " " NEW_LINE for i in range ( 1 , ( 1 << n ) ) : NEW_LINE INDENT str = " " NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT if ( ( i >> j ) & 1 ) : NEW_LINE INDENT str = str + s [ j ] NEW_LINE DEDENT DEDENT if ( str [ 0 ] != '0' ) : NEW_LINE INDENT temp = 0 ; NEW_LINE for j in range ( 0 , len ( str ) ) : NEW_LINE INDENT temp = ( temp * 10 + ( ord ( str [ j ] ) - ord ( '0' ) ) ) NEW_LINE DEDENT k = int ( math . sqrt ( temp ) ) NEW_LINE if ( k * k == temp ) : NEW_LINE INDENT if ( ans < len ( str ) ) : NEW_LINE INDENT ans = len ( str ) NEW_LINE num = str NEW_LINE DEDENT DEDENT DEDENT DEDENT if ( ans == - 1 ) : NEW_LINE INDENT return ans NEW_LINE DEDENT else : NEW_LINE INDENT print ( " { } ▁ " . format ( num ) , end = " " ) NEW_LINE return n - ans NEW_LINE DEDENT DEDENT print ( perfectSquare ( "8314" ) ) NEW_LINE print ( perfectSquare ( "753" ) ) ; NEW_LINE


import java . util . * ; class GFG { static int MAX = 1000 ; static int numofArray ( int n , int m ) { int [ ] [ ] dp = new int [ MAX ] [ MAX ] ; Vector < Integer > [ ] di = new Vector [ MAX ] ; Vector < Integer > [ ] mu = new Vector [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < MAX ; i ++ ) { di [ i ] = new Vector < > ( ) ; mu [ i ] = new Vector < > ( ) ; } for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 2 * i ; j <= m ; j += i ) { di [ j ] . add ( i ) ; mu [ i ] . add ( j ) ; } di [ i ] . add ( i ) ; } for ( int i = 1 ; i <= m ; i ++ ) dp [ 1 ] [ i ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { dp [ i ] [ j ] = 0 ; for ( Integer x : di [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ; for ( Integer x : mu [ j ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ x ] ; } } int ans = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { ans += dp [ n ] [ i ] ; di [ i ] . clear ( ) ; mu [ i ] . clear ( ) ; } return ans ; } public static void main ( String [ ] args ) { int n = 3 , m = 3 ; System . out . println ( numofArray ( n , m ) ) ; } }

MAX = 1000 NEW_LINE def numofArray ( n , m ) : NEW_LINE INDENT dp = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ] NEW_LINE di = [ [ ] for i in range ( MAX ) ] NEW_LINE mu = [ [ ] for i in range ( MAX ) ] NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT for j in range ( 2 * i , m + 1 , i ) : NEW_LINE INDENT di [ j ] . append ( i ) NEW_LINE mu [ i ] . append ( j ) NEW_LINE DEDENT di [ i ] . append ( i ) NEW_LINE DEDENT for i in range ( 1 , m + 1 ) : NEW_LINE INDENT dp [ 1 ] [ i ] = 1 NEW_LINE DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , m + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] = 0 NEW_LINE for x in di [ j ] : NEW_LINE INDENT dp [ i ] [ j ] += dp [ i - 1 ] [ x ] NEW_LINE DEDENT for x in mu [ j ] : NEW_LINE INDENT dp [ i ] [ j ] += dp [ i - 1 ] [ x ] NEW_LINE DEDENT DEDENT DEDENT ans = 0 NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT ans += dp [ n ] [ i ] NEW_LINE di [ i ] . clear ( ) NEW_LINE mu [ i ] . clear ( ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = m = 3 NEW_LINE print ( numofArray ( n , m ) ) NEW_LINE DEDENT


class GFG { static int lis ( int arr [ ] , int n ) { int result = 0 ; int [ ] lis = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; for ( int i = 0 ; i < n ; i ++ ) if ( result < lis [ i ] ) result = lis [ i ] ; return result ; } static int minimumNumberOfDeletions ( int arr [ ] , int n ) { int len = lis ( arr , n ) ; return ( n - len ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 30 , 40 , 2 , 5 , 1 , 7 , 45 , 50 , 8 } ; int n = arr . length ; System . out . println ( " Minimum ▁ number ▁ of " + " ▁ deletions ▁ = ▁ " + minimumNumberOfDeletions ( arr , n ) ) ; } }

def lis ( arr , n ) : NEW_LINE INDENT result = 0 NEW_LINE lis = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT lis [ i ] = 1 NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( i ) : NEW_LINE INDENT if ( arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 ) : NEW_LINE INDENT lis [ i ] = lis [ j ] + 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( result < lis [ i ] ) : NEW_LINE INDENT result = lis [ i ] NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT def minimumNumberOfDeletions ( arr , n ) : NEW_LINE INDENT len = lis ( arr , n ) NEW_LINE return ( n - len ) NEW_LINE DEDENT arr = [ 30 , 40 , 2 , 5 , 1 , 7 , 45 , 50 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Minimum ▁ number ▁ of ▁ deletions ▁ = ▁ " , minimumNumberOfDeletions ( arr , n ) ) NEW_LINE


import java . util . * ; class GFG { static void printNonConsecutive ( int n ) { int p = ( 1 << n ) ; for ( int i = 1 ; i < p ; i ++ ) if ( ( i & ( i << 1 ) ) == 0 ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 3 ; printNonConsecutive ( n ) ; } }

def printNonConsecutive ( n ) : NEW_LINE INDENT p = ( 1 << n ) NEW_LINE for i in range ( 1 , p ) : NEW_LINE INDENT if ( ( i & ( i << 1 ) ) == 0 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT n = 3 NEW_LINE printNonConsecutive ( n ) NEW_LINE


import java . util . * ; class solution { static long getNthTerm ( long N ) { return ( 7 * ( int ) Math . pow ( N , 2 ) - 19 * N + 15 ) ; } public static void main ( String arr [ ] ) { long N = 4 ; System . out . println ( getNthTerm ( N ) ) ; } }

def getNthTerm ( N ) : NEW_LINE INDENT return ( 7 * pow ( N , 2 ) - 19 * N + 15 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 NEW_LINE print ( getNthTerm ( N ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static final int N = 4 ; static final int M = 4 ; static boolean isPairWithDiff ( int mat [ ] [ ] , int k ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) s . add ( mat [ i ] [ j ] ) ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) if ( s . contains ( k + mat [ i ] [ j ] ) && k + mat [ i ] [ j ] != ( int ) s . toArray ( ) [ s . size ( ) - 1 ] ) return true ; return false ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 5 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 100 } } ; int k = 85 ; System . out . println ( isPairWithDiff ( mat , k ) == true ? " YES " : " NO " ) ; } }

N = 4 NEW_LINE M = 4 NEW_LINE def isPairWithDiff ( mat , k ) : NEW_LINE INDENT s = dict ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT s [ mat [ i ] [ j ] ] = 1 NEW_LINE DEDENT DEDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if k + mat [ i ] [ j ] in s : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT n , m = 4 , 4 NEW_LINE mat = [ [ 5 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 100 ] ] NEW_LINE k = 85 NEW_LINE if isPairWithDiff ( mat , k ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


public class GFG { static final int MAX = 256 ; static boolean compare ( char arr1 [ ] , char arr2 [ ] ) { for ( int i = 0 ; i < MAX ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } static void search ( String pat , String txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; char [ ] countP = new char [ MAX ] ; char [ ] countTW = new char [ MAX ] ; for ( int i = 0 ; i < M ; i ++ ) { ( countP [ pat . charAt ( i ) ] ) ++ ; ( countTW [ txt . charAt ( i ) ] ) ++ ; } for ( int i = M ; i < N ; i ++ ) { if ( compare ( countP , countTW ) ) System . out . println ( " Found ▁ at ▁ Index ▁ " + ( i - M ) ) ; ( countTW [ txt . charAt ( i ) ] ) ++ ; countTW [ txt . charAt ( i - M ) ] -- ; } if ( compare ( countP , countTW ) ) System . out . println ( " Found ▁ at ▁ Index ▁ " + ( N - M ) ) ; } public static void main ( String args [ ] ) { String txt = " BACDGABCDA " ; String pat = " ABCD " ; search ( pat , txt ) ; } }

MAX = 256 NEW_LINE def compare ( arr1 , arr2 ) : NEW_LINE INDENT for i in range ( MAX ) : NEW_LINE INDENT if arr1 [ i ] != arr2 [ i ] : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def search ( pat , txt ) : NEW_LINE INDENT M = len ( pat ) NEW_LINE N = len ( txt ) NEW_LINE countP = [ 0 ] * MAX NEW_LINE countTW = [ 0 ] * MAX NEW_LINE for i in range ( M ) : NEW_LINE INDENT ( countP [ ord ( pat [ i ] ) ] ) += 1 NEW_LINE ( countTW [ ord ( txt [ i ] ) ] ) += 1 NEW_LINE DEDENT for i in range ( M , N ) : NEW_LINE INDENT if compare ( countP , countTW ) : NEW_LINE INDENT print ( " Found ▁ at ▁ Index " , ( i - M ) ) NEW_LINE DEDENT ( countTW [ ord ( txt [ i ] ) ] ) += 1 NEW_LINE ( countTW [ ord ( txt [ i - M ] ) ] ) -= 1 NEW_LINE DEDENT if compare ( countP , countTW ) : NEW_LINE INDENT print ( " Found ▁ at ▁ Index " , N - M ) NEW_LINE DEDENT DEDENT txt = " BACDGABCDA " NEW_LINE pat = " ABCD " NEW_LINE search ( pat , txt ) NEW_LINE


class GFG { static void countPairs ( int arr [ ] , int n ) { int even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) even ++ ; else odd ++ ; } System . out . println ( ( even ) * ( n - 1 ) ) ; System . out . println ( ( odd ) * ( n - 1 ) ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 4 , 5 } ; int n = arr . length ; countPairs ( arr , n ) ; } }

def countPairs ( arr , n ) : NEW_LINE INDENT odd = 0 NEW_LINE even = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT even += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd += 1 NEW_LINE DEDENT DEDENT odd_pairs = odd * ( n - 1 ) NEW_LINE even_pairs = even * ( n - 1 ) NEW_LINE print ( odd_pairs ) NEW_LINE print ( even_pairs ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE countPairs ( arr , n ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int MAX = 10000 ; static HashSet < Integer > s = new HashSet < Integer > ( ) ; static void SieveOfEratosthenes ( ) { boolean [ ] prime = new boolean [ MAX ] ; Arrays . fill ( prime , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } int product = 1 ; for ( int p = 2 ; p < MAX ; p ++ ) { if ( prime [ p ] ) { product = product * p ; s . add ( product + 1 ) ; } } } static boolean isEuclid ( int n ) { if ( s . contains ( n ) ) return true ; else return false ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int n = 31 ; if ( isEuclid ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; n = 42 ; if ( isEuclid ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

MAX = 10000 NEW_LINE s = set ( ) NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime = [ True ] * ( MAX ) NEW_LINE prime [ 0 ] , prime [ 1 ] = False , False NEW_LINE for p in range ( 2 , 100 ) : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT for i in range ( p * 2 , MAX , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT product = 1 NEW_LINE for p in range ( 2 , MAX ) : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT product = product * p NEW_LINE s . add ( product + 1 ) NEW_LINE DEDENT DEDENT DEDENT def isEuclid ( n ) : NEW_LINE INDENT if n in s : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE n = 31 NEW_LINE if isEuclid ( n ) == True : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT n = 42 NEW_LINE if isEuclid ( n ) == True : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int n = 5 ; static int largestSideLen ( int matrix [ ] [ ] ) { int result = 1 ; for ( int i = 0 ; i < ( n / 2 ) ; i ++ ) { int element = matrix [ i ] [ i ] ; int isSquare = 1 ; for ( int j = i ; j < n - i ; j ++ ) { if ( matrix [ i ] [ j ] != element ) isSquare = 0 ; if ( matrix [ n - i - 1 ] [ j ] != element ) isSquare = 0 ; if ( matrix [ j ] [ i ] != element ) isSquare = 0 ; if ( matrix [ j ] [ n - i - 1 ] != element ) isSquare = 0 ; } if ( isSquare > 0 ) return n - ( 2 * i ) ; } return result ; } public static void main ( String [ ] args ) { int matrix [ ] [ ] = { { 1 , 1 , 1 , 1 , 1 } , { 1 , 2 , 2 , 2 , 1 } , { 1 , 2 , 1 , 2 , 1 } , { 1 , 2 , 2 , 2 , 1 } , { 1 , 1 , 1 , 1 , 1 } } ; System . out . println ( largestSideLen ( matrix ) ) ; } }

n = 5 NEW_LINE def largestSideLen ( matrix ) : NEW_LINE INDENT result = 1 NEW_LINE for i in range ( int ( n / 2 ) ) : NEW_LINE INDENT element = matrix [ i ] [ i ] NEW_LINE isSquare = 1 NEW_LINE for j in range ( i , n - i ) : NEW_LINE INDENT if ( matrix [ i ] [ j ] != element ) : NEW_LINE INDENT isSquare = 0 NEW_LINE DEDENT if ( matrix [ n - i - 1 ] [ j ] != element ) : NEW_LINE INDENT isSquare = 0 NEW_LINE DEDENT if ( matrix [ j ] [ i ] != element ) : NEW_LINE INDENT isSquare = 0 NEW_LINE DEDENT if ( matrix [ j ] [ n - i - 1 ] != element ) : NEW_LINE INDENT isSquare = 0 NEW_LINE DEDENT DEDENT if ( isSquare ) : NEW_LINE INDENT return n - 2 * i NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT matrix = [ [ 1 , 1 , 1 , 1 , 1 ] , [ 1 , 2 , 2 , 2 , 1 ] , [ 1 , 2 , 1 , 2 , 1 ] , [ 1 , 2 , 2 , 2 , 1 ] , [ 1 , 1 , 1 , 1 , 1 ] ] NEW_LINE print ( largestSideLen ( matrix ) ) NEW_LINE DEDENT


class GFG { static float calcAngle ( int hh , int mm ) { float hour_angle = 0.5f * ( hh * 60 + mm ) ; float minute_angle = 6 * mm ; float angle = Math . abs ( hour_angle - minute_angle ) ; angle = Math . min ( 360 - angle , angle ) ; return angle ; } static void printTime ( float theta ) { for ( int hh = 0 ; hh < 12 ; hh ++ ) { for ( int mm = 0 ; mm < 60 ; mm ++ ) { if ( calcAngle ( hh , mm ) == theta ) { System . out . println ( hh + " : " + mm ) ; return ; } } } System . out . println ( " Input ▁ angle ▁ not ▁ valid . " ) ; return ; } public static void main ( String [ ] args ) { float theta = 90.0f ; printTime ( theta ) ; } }

def calcAngle ( hh , mm ) : NEW_LINE INDENT hour_angle = 0.5 * ( hh * 60 + mm ) NEW_LINE minute_angle = 6 * mm NEW_LINE angle = abs ( hour_angle - minute_angle ) NEW_LINE angle = min ( 360 - angle , angle ) NEW_LINE return angle NEW_LINE DEDENT def printTime ( theta ) : NEW_LINE INDENT for hh in range ( 0 , 12 ) : NEW_LINE INDENT for mm in range ( 0 , 60 ) : NEW_LINE INDENT if ( calcAngle ( hh , mm ) == theta ) : NEW_LINE INDENT print ( hh , " : " , mm , sep = " " ) NEW_LINE return NEW_LINE DEDENT DEDENT DEDENT print ( " Input ▁ angle ▁ not ▁ valid . " ) NEW_LINE return NEW_LINE DEDENT theta = 90.0 NEW_LINE printTime ( theta ) NEW_LINE


import java . util . * ; class GFG { static void findMin ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; Arrays . sort ( arr ) ; int min = arr [ 0 ] ; int max = 0 ; for ( int i = n - 1 ; i >= 1 ; i -- ) { int num = arr [ i ] ; int total = num + min ; int j ; for ( j = 2 ; j <= num ; j ++ ) { if ( num % j == 0 ) { int d = j ; int now = ( num / d ) + ( min * d ) ; int reduce = total - now ; if ( reduce > max ) max = reduce ; } } } System . out . println ( sum - max ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; findMin ( arr , n ) ; } }

def findMin ( arr , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sum = sum + arr [ i ] NEW_LINE DEDENT arr . sort ( ) NEW_LINE min = arr [ 0 ] NEW_LINE max = 0 NEW_LINE for i in range ( n - 1 , 0 , - 1 ) : NEW_LINE INDENT num = arr [ i ] NEW_LINE total = num + min NEW_LINE for j in range ( 2 , num + 1 ) : NEW_LINE INDENT if ( num % j == 0 ) : NEW_LINE INDENT d = j NEW_LINE now = ( num // d ) + ( min * d ) NEW_LINE reduce = total - now NEW_LINE if ( reduce > max ) : NEW_LINE INDENT max = reduce NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( sum - max ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE findMin ( arr , n ) NEW_LINE


import java . util . * ; class GFG { static String findNumber ( int s , int d ) { String num = " " ; int val = s / d ; int rem = s % d ; int i ; for ( i = 1 ; i <= d - rem ; i ++ ) { num = num + String . valueOf ( val ) ; } if ( rem > 0 ) { val ++ ; for ( i = d - rem + 1 ; i <= d ; i ++ ) { num = num + String . valueOf ( val ) ; } } return num ; } public static void main ( String [ ] args ) { int s = 25 , d = 4 ; System . out . print ( findNumber ( s , d ) ) ; } }

def findNumber ( s , d ) : NEW_LINE INDENT num = " " ; NEW_LINE val = s // d ; NEW_LINE rem = s % d ; NEW_LINE for i in range ( 1 , d - rem + 1 ) : NEW_LINE INDENT num = num + str ( val ) ; NEW_LINE DEDENT if ( rem ) : NEW_LINE INDENT val += 1 ; NEW_LINE for i in range ( d - rem + 1 , d + 1 ) : NEW_LINE INDENT num = num + str ( val ) ; NEW_LINE DEDENT DEDENT return num ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = 25 ; d = 4 ; NEW_LINE print ( findNumber ( s , d ) ) ; NEW_LINE DEDENT


import java . util . * ; class Point { int x , y ; Point ( int x , int y ) { this . x = x ; this . y = y ; } } class GFG { public static int orientation ( Point p , Point q , Point r ) { int val = ( q . y - p . y ) * ( r . x - q . x ) - ( q . x - p . x ) * ( r . y - q . y ) ; if ( val == 0 ) return 0 ; return ( val > 0 ) ? 1 : 2 ; } public static void convexHull ( Point points [ ] , int n ) { if ( n < 3 ) return ; Vector < Point > hull = new Vector < Point > ( ) ; int l = 0 ; for ( int i = 1 ; i < n ; i ++ ) if ( points [ i ] . x < points [ l ] . x ) l = i ; int p = l , q ; do { hull . add ( points [ p ] ) ; q = ( p + 1 ) % n ; for ( int i = 0 ; i < n ; i ++ ) { if ( orientation ( points [ p ] , points [ i ] , points [ q ] ) == 2 ) q = i ; } p = q ; } while ( p != l ) ; for ( Point temp : hull ) System . out . println ( " ( " + temp . x + " , ▁ " + temp . y + " ) " ) ; } public static void main ( String [ ] args ) { Point points [ ] = new Point [ 7 ] ; points [ 0 ] = new Point ( 0 , 3 ) ; points [ 1 ] = new Point ( 2 , 3 ) ; points [ 2 ] = new Point ( 1 , 1 ) ; points [ 3 ] = new Point ( 2 , 1 ) ; points [ 4 ] = new Point ( 3 , 0 ) ; points [ 5 ] = new Point ( 0 , 0 ) ; points [ 6 ] = new Point ( 3 , 3 ) ; int n = points . length ; convexHull ( points , n ) ; } }

class Point : NEW_LINE INDENT def __init__ ( self , x , y ) : NEW_LINE INDENT self . x = x NEW_LINE self . y = y NEW_LINE DEDENT DEDENT def Left_index ( points ) : NEW_LINE INDENT minn = 0 NEW_LINE for i in range ( 1 , len ( points ) ) : NEW_LINE INDENT if points [ i ] . x < points [ minn ] . x : NEW_LINE INDENT minn = i NEW_LINE DEDENT elif points [ i ] . x == points [ minn ] . x : NEW_LINE INDENT if points [ i ] . y > points [ minn ] . y : NEW_LINE INDENT minn = i NEW_LINE DEDENT DEDENT DEDENT return minn NEW_LINE DEDENT def orientation ( p , q , r ) : NEW_LINE INDENT val = ( q . y - p . y ) * ( r . x - q . x ) -   \ NEW_LINE INDENT ( q . x - p . x ) * ( r . y - q . y ) NEW_LINE DEDENT if val == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif val > 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 2 NEW_LINE DEDENT DEDENT def convexHull ( points , n ) : NEW_LINE INDENT if n < 3 : NEW_LINE INDENT return NEW_LINE DEDENT l = Left_index ( points ) NEW_LINE hull = [ ] NEW_LINE p = l NEW_LINE q = 0 NEW_LINE while ( True ) : NEW_LINE INDENT hull . append ( p ) NEW_LINE q = ( p + 1 ) % n NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( orientation ( points [ p ] , points [ i ] , points [ q ] ) == 2 ) : NEW_LINE INDENT q = i NEW_LINE DEDENT DEDENT p = q NEW_LINE if ( p == l ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT for each in hull : NEW_LINE INDENT print ( points [ each ] . x , points [ each ] . y ) NEW_LINE DEDENT DEDENT points = [ ] NEW_LINE points . append ( Point ( 0 , 3 ) ) NEW_LINE points . append ( Point ( 2 , 2 ) ) NEW_LINE points . append ( Point ( 1 , 1 ) ) NEW_LINE points . append ( Point ( 2 , 1 ) ) NEW_LINE points . append ( Point ( 3 , 0 ) ) NEW_LINE points . append ( Point ( 0 , 0 ) ) NEW_LINE points . append ( Point ( 3 , 3 ) ) NEW_LINE convexHull ( points , len ( points ) ) NEW_LINE


import java . io . * ; class GFG { static int numberOfSolutions ( int n ) { int c = 0 ; while ( n > 0 ) { c += n % 2 ; n /= 2 ; } return ( int ) Math . pow ( 2 , c ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( numberOfSolutions ( n ) ) ; } }

from math import * NEW_LINE def numberOfSolutions ( n ) : NEW_LINE INDENT c = 0 NEW_LINE while ( n ) : NEW_LINE INDENT c += n % 2 NEW_LINE n //= 2 NEW_LINE DEDENT return int ( pow ( 2 , c ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 NEW_LINE print ( numberOfSolutions ( n ) ) NEW_LINE DEDENT


class GFG { static int countWays ( int [ ] arr , int n ) { int max_val = 0 ; for ( int i = 0 ; i < n ; i ++ ) max_val = Math . max ( max_val , arr [ i ] ) ; int [ ] freq = new int [ max_val + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; int ans = 0 ; ans += freq [ 0 ] * ( freq [ 0 ] - 1 ) * ( freq [ 0 ] - 2 ) / 6 ; for ( int i = 1 ; i <= max_val ; i ++ ) ans += freq [ 0 ] * freq [ i ] * ( freq [ i ] - 1 ) / 2 ; for ( int i = 1 ; 2 * i <= max_val ; i ++ ) ans += freq [ i ] * ( freq [ i ] - 1 ) / 2 * freq [ 2 * i ] ; for ( int i = 1 ; i <= max_val ; i ++ ) { for ( int j = i + 1 ; i + j <= max_val ; j ++ ) ans += freq [ i ] * freq [ j ] * freq [ i + j ] ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( countWays ( arr , n ) ) ; } }

import math as mt NEW_LINE def countWays ( arr , n ) : NEW_LINE INDENT max_val = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT max_val = max ( max_val , arr [ i ] ) NEW_LINE DEDENT freq = [ 0 for i in range ( max_val + 1 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ arr [ i ] ] += 1 NEW_LINE DEDENT ans = 0 NEW_LINE ans += ( freq [ 0 ] * ( freq [ 0 ] - 1 ) * ( freq [ 0 ] - 2 ) // 6 ) NEW_LINE for i in range ( 1 , max_val + 1 ) : NEW_LINE INDENT ans += ( freq [ 0 ] * freq [ i ] * ( freq [ i ] - 1 ) // 2 ) NEW_LINE DEDENT for i in range ( 1 , ( max_val + 1 ) // 2 ) : NEW_LINE INDENT ans += ( freq [ i ] * ( freq [ i ] - 1 ) // 2 * freq [ 2 * i ] ) NEW_LINE DEDENT for i in range ( 1 , max_val + 1 ) : NEW_LINE INDENT for j in range ( i + 1 , max_val - i + 1 ) : NEW_LINE INDENT ans += freq [ i ] * freq [ j ] * freq [ i + j ] NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countWays ( arr , n ) ) NEW_LINE


import java . util . * ; class GFG { static void SieveOfEratosthenes ( boolean prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int maxPrimeSubarray ( int arr [ ] , int n ) { int max_ele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; boolean prime [ ] = new boolean [ max_ele + 1 ] ; Arrays . fill ( prime , true ) ; SieveOfEratosthenes ( prime , max_ele ) ; int current_max = 0 , max_so_far = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] == false ) current_max = 0 ; else { current_max ++ ; max_so_far = Math . max ( current_max , max_so_far ) ; } } return max_so_far ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 2 , 4 , 3 , 29 , 11 , 7 , 8 , 9 } ; int n = arr . length ; System . out . print ( maxPrimeSubarray ( arr , n ) ) ; } }

def SieveOfEratosthenes ( prime , p_size ) : NEW_LINE INDENT prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE for p in range ( 2 , p_size + 1 ) : NEW_LINE INDENT if ( p * p > p_size ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( prime [ p ] ) : NEW_LINE INDENT i = p * 2 NEW_LINE while ( i <= p_size ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE i = i + p NEW_LINE DEDENT DEDENT DEDENT DEDENT def maxPrimeSubarray ( arr , n ) : NEW_LINE INDENT max_ele = max ( arr ) NEW_LINE prime = [ True ] * ( max_ele + 1 ) NEW_LINE SieveOfEratosthenes ( prime , max_ele ) NEW_LINE current_max = 0 NEW_LINE max_so_far = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( prime [ arr [ i ] ] == False ) : NEW_LINE INDENT current_max = 0 NEW_LINE DEDENT else : NEW_LINE INDENT current_max = current_max + 1 NEW_LINE max_so_far = max ( current_max , max_so_far ) NEW_LINE DEDENT DEDENT return max_so_far NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 0 , 2 , 4 , 3 , 29 , 11 , 7 , 8 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxPrimeSubarray ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void printCompositions ( int arr [ ] , int n , int i ) { int MAX_POINT = 3 ; if ( n == 0 ) { printArray ( arr , i ) ; } else if ( n > 0 ) { for ( int k = 1 ; k <= MAX_POINT ; k ++ ) { arr [ i ] = k ; printCompositions ( arr , n - k , i + 1 ) ; } } } static void printArray ( int arr [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int n = 5 ; int size = 100 ; int [ ] arr = new int [ size ] ; System . out . println ( " Different ▁ compositions ▁ formed ▁ by ▁ 1 , ▁ 2 ▁ and ▁ 3 ▁ of ▁ " + n + " ▁ are " ) ; printCompositions ( arr , n , 0 ) ; } }

MAX_POINT = 3 ; NEW_LINE ARR_SIZE = 100 ; NEW_LINE arr = [ 0 ] * ARR_SIZE ; NEW_LINE def printCompositions ( n , i ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT printArray ( arr , i ) ; NEW_LINE DEDENT elif ( n > 0 ) : NEW_LINE INDENT for k in range ( 1 , MAX_POINT + 1 ) : NEW_LINE INDENT arr [ i ] = k ; NEW_LINE printCompositions ( n - k , i + 1 ) ; NEW_LINE DEDENT DEDENT DEDENT def printArray ( arr , arr_size ) : NEW_LINE INDENT for i in range ( arr_size ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT n = 5 ; NEW_LINE print ( " Different ▁ compositions ▁ formed ▁ " + " by ▁ 1 , ▁ 2 ▁ and ▁ 3 ▁ of " , n , " ▁ are " ) ; NEW_LINE printCompositions ( n , 0 ) ; NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static void reverseorder ( int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int i = n ; i >= 2 ; i -- ) if ( prime [ i ] == true ) System . out . print ( i + " ▁ " ) ; } public static void main ( String args [ ] ) { int N = 25 ; System . out . println ( " Prime ▁ number ▁ in ▁ reverse ▁ order " ) ; if ( N == 1 ) System . out . println ( " No ▁ prime ▁ no ▁ exist ▁ in ▁ this ▁ range " ) ; else reverseorder ( N ) ; } }

def Reverseorder ( n ) : NEW_LINE INDENT prime = [ True ] * ( n + 1 ) ; NEW_LINE p = 2 ; NEW_LINE while ( p * p <= n ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( ( p * 2 ) , ( n + 1 ) , p ) : NEW_LINE INDENT prime [ i ] = False ; NEW_LINE DEDENT DEDENT p += 1 ; NEW_LINE DEDENT for p in range ( n , 1 , - 1 ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT print ( p , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT N = 25 ; NEW_LINE print ( " Prime ▁ number ▁ in ▁ reverse ▁ order " ) ; NEW_LINE if ( N == 1 ) : NEW_LINE INDENT print ( " No ▁ prime ▁ no ▁ exist ▁ in ▁ this ▁ range " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT Reverseorder ( N ) ; NEW_LINE DEDENT


class Solution { static int Triplets ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = i ; j <= n ; ++ j ) { int x = i * i + j * j ; int y = ( int ) Math . sqrt ( x ) ; if ( y * y == x && y <= n ) ++ ans ; } } return ans ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( Triplets ( n ) ) ; } }

import math NEW_LINE def Triplets ( n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( i , n + 1 ) : NEW_LINE INDENT x = i * i + j * j NEW_LINE y = int ( math . sqrt ( x ) ) NEW_LINE if ( y * y == x and y <= n ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 10 NEW_LINE print ( Triplets ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; String string1 = in . nextLine ( ) ; System . out . println ( " Enter ▁ the ▁ first ▁ string : ▁ " + string1 ) ; String string2 = in . nextLine ( ) ; System . out . println ( " Enter ▁ the ▁ second ▁ string ▁ : " + string2 ) ; System . out . println ( " \n Are ▁ both ▁ strings ▁ same : ▁ " ) ; if ( string1 . equals ( string2 ) == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string1 = input ( " Enter ▁ the ▁ first ▁ string : ▁ " ) NEW_LINE print ( string1 , end = " \n " ) NEW_LINE string2 = input ( " Enter ▁ the ▁ second ▁ string : ▁ " ) NEW_LINE print ( string2 , end = " \n " ) NEW_LINE print ( " Are ▁ both ▁ strings ▁ same : ▁ " , end = " ▁ " ) NEW_LINE if ( string1 == string2 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . util . * ; import java . lang . * ; class GFG { static int findBitonicity ( int [ ] arr , int n ) { int bt = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) bt ++ ; else if ( arr [ i ] < arr [ i - 1 ] ) bt -- ; } return bt ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 4 , 3 } ; int n = arr . length ; System . out . print ( " Bitonicity ▁ = ▁ " + findBitonicity ( arr , n ) ) ; } }

def findBitonicity ( arr , n ) : NEW_LINE INDENT bt = 0 NEW_LINE for i in range ( 1 , n , 1 ) : NEW_LINE INDENT if ( arr [ i ] > arr [ i - 1 ] ) : NEW_LINE INDENT bt += 1 NEW_LINE DEDENT elif ( arr [ i ] < arr [ i - 1 ] ) : NEW_LINE INDENT bt -= 1 NEW_LINE DEDENT DEDENT return bt NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 4 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Bitonicity ▁ = " , findBitonicity ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static long countOfMultiples ( long n ) { return ( n / 3 + n / 5 - n / 15 ) ; } static public void main ( String [ ] args ) { System . out . println ( countOfMultiples ( 6 ) ) ; System . out . println ( countOfMultiples ( 16 ) ) ; } }

def countOfMultiples ( n ) : NEW_LINE INDENT return ( int ( n / 3 ) + int ( n / 5 ) - int ( n / 15 ) ) ; NEW_LINE DEDENT print ( countOfMultiples ( 6 ) ) NEW_LINE print ( countOfMultiples ( 16 ) ) NEW_LINE


class GFG { static long modPower ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long gcd ( long a , long b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static long gcdPow ( long a , long n , long c ) { if ( a % c == 0 ) return c ; long modexpo = modPower ( a , n , c ) ; return gcd ( modexpo , c ) ; } public static void main ( String [ ] args ) { long a = 10248585 , n = 1000000 , c = 12564 ; System . out . println ( gcdPow ( a , n , c ) ) ; } }

def modPower ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def gcd ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : NEW_LINE INDENT return a NEW_LINE DEDENT return gcd ( b , a % b ) NEW_LINE DEDENT def gcdPow ( a , n , c ) : NEW_LINE INDENT if ( a % c == 0 ) : NEW_LINE INDENT return c NEW_LINE DEDENT modexpo = modPower ( a , n , c ) NEW_LINE return gcd ( modexpo , c ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 10248585 NEW_LINE n = 1000000 NEW_LINE c = 12564 NEW_LINE print ( gcdPow ( a , n , c ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int sum = 0 ; static int compositeCount ( int arr [ ] , int n ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; Vector < Boolean > prime = new Vector < Boolean > ( max_val + 1 ) ; for ( int i = 0 ; i < max_val + 1 ; i ++ ) { prime . add ( i , Boolean . TRUE ) ; } prime . add ( 0 , Boolean . TRUE ) ; prime . add ( 1 , Boolean . TRUE ) ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime . get ( p ) == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) { prime . add ( i , Boolean . FALSE ) ; } } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! prime . get ( arr [ i ] ) ) { count ++ ; sum = sum + arr [ i ] ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int n = arr . length ; System . out . print ( " Count ▁ of ▁ Composite ▁ Numbers ▁ = ▁ " + compositeCount ( arr , n ) ) ; System . out . print ( " \n Sum ▁ of ▁ Composite ▁ Numbers ▁ = ▁ " + sum ) ; } }

def compositeCount ( arr , n ) : NEW_LINE INDENT Sum = 0 NEW_LINE max_val = max ( arr ) NEW_LINE prime = [ True for i in range ( max_val + 1 ) ] NEW_LINE prime [ 0 ] = True NEW_LINE prime [ 1 ] = True NEW_LINE for p in range ( 2 , max_val + 1 ) : NEW_LINE INDENT if p * p > max_val : NEW_LINE INDENT break NEW_LINE DEDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( prime [ arr [ i ] ] == False ) : NEW_LINE INDENT count += 1 NEW_LINE Sum = Sum + arr [ i ] NEW_LINE DEDENT DEDENT return count , Sum NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE count , Sum = compositeCount ( arr , n ) NEW_LINE print ( " Count ▁ of ▁ Composite ▁ Numbers ▁ = ▁ " , count ) NEW_LINE print ( " Sum ▁ of ▁ Composite ▁ Numbers ▁ = ▁ " , Sum ) NEW_LINE // This code is contributed by Mohit Kumar NEW_LINE


import java . io . * ; class GFG { static double nthHarmonic ( int N ) { float harmonic = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } public static void main ( String [ ] args ) { int N = 8 ; System . out . print ( nthHarmonic ( N ) ) ; } }

def nthHarmonic ( N ) : NEW_LINE INDENT harmonic = 1.00 NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT harmonic += 1 / i NEW_LINE DEDENT return harmonic NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 8 NEW_LINE print ( round ( nthHarmonic ( N ) , 5 ) ) NEW_LINE DEDENT


import java . math . * ; class GFG { static int firstDigit ( int n ) { int digits = ( int ) ( Math . log10 ( n ) ) ; n = ( int ) ( n / ( int ) ( Math . pow ( 10 , digits ) ) ) ; return n ; } static int lastDigit ( int n ) { return ( n % 10 ) ; } public static void main ( String args [ ] ) { int n = 98562 ; System . out . println ( firstDigit ( n ) + " ▁ " + lastDigit ( n ) ) ; } }

import math NEW_LINE def firstDigit ( n ) : NEW_LINE INDENT digits = ( int ) ( math . log10 ( n ) ) NEW_LINE n = ( int ) ( n / pow ( 10 , digits ) ) NEW_LINE return n ; NEW_LINE DEDENT def lastDigit ( n ) : NEW_LINE INDENT return ( n % 10 ) NEW_LINE DEDENT n = 98562 ; NEW_LINE print ( firstDigit ( n ) , end = " ▁ " ) NEW_LINE print ( lastDigit ( n ) ) NEW_LINE


import java . io . * ; class GFG { static void find_set ( int n ) { if ( n <= 2 ) { System . out . println ( " - 1" ) ; return ; } int sum1 = ( n * ( n - 1 ) ) / 2 ; int sum2 = n ; System . out . println ( sum1 + " ▁ " + sum2 ) ; } public static void main ( String [ ] args ) { int n = 8 ; find_set ( n ) ; } }

def find_set ( n ) : NEW_LINE INDENT if ( n <= 2 ) : NEW_LINE INDENT print ( " - 1" ) ; NEW_LINE return ; NEW_LINE DEDENT sum1 = ( n * ( n - 1 ) ) / 2 ; NEW_LINE sum2 = n ; NEW_LINE print ( sum1 , " ▁ " , sum2 ) ; NEW_LINE DEDENT n = 8 ; NEW_LINE find_set ( n ) ; NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static int min_sum ( int n , int k , int a [ ] ) { Arrays . sort ( a ) ; if ( a [ 0 ] < 0 ) return - 1 ; if ( k == 0 ) { if ( a [ 0 ] == a [ n - 1 ] ) return ( n * a [ 0 ] ) ; else return - 1 ; } else { int f = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int p = a [ i ] - a [ 0 ] ; if ( p % k == 0 ) continue ; else { f = 1 ; break ; } } if ( f > 0 ) return - 1 ; else { if ( k == 1 ) return n ; else return ( n * ( a [ 0 ] % k ) ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 } ; int K = 1 ; int N = arr . length ; System . out . println ( min_sum ( N , K , arr ) ) ; } }

def min_sum ( n , k , a ) : NEW_LINE INDENT a . sort ( reverse = False ) NEW_LINE if ( a [ 0 ] < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ( k == 0 ) : NEW_LINE INDENT if ( a [ 0 ] == a [ n - 1 ] ) : NEW_LINE INDENT return ( n * a [ 0 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT f = 0 NEW_LINE for i in range ( 1 , n , 1 ) : NEW_LINE INDENT p = a [ i ] - a [ 0 ] NEW_LINE if ( p % k == 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT f = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if ( f ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( k == 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT else : NEW_LINE INDENT return ( n * ( a [ 0 ] % k ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 4 , 5 ] NEW_LINE K = 1 NEW_LINE N = len ( arr ) NEW_LINE print ( min_sum ( N , K , arr ) ) NEW_LINE DEDENT


class GFG { public static int countDigits ( int a , int b ) { if ( a == 0 || b == 0 ) return 1 ; return ( int ) Math . floor ( Math . log10 ( Math . abs ( a ) ) + Math . log10 ( Math . abs ( b ) ) ) + 1 ; } public static void main ( String [ ] args ) { int a = 33 ; int b = - 24 ; System . out . print ( countDigits ( a , b ) ) ; } }

import math NEW_LINE def countDigits ( a , b ) : NEW_LINE INDENT if ( a == 0 or b == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return math . floor ( math . log10 ( abs ( a ) ) + math . log10 ( abs ( b ) ) ) + 1 NEW_LINE DEDENT a = 33 NEW_LINE b = - 24 NEW_LINE print ( countDigits ( a , b ) ) NEW_LINE


class PairInSortedRotated { static boolean pairInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) return true ; if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 15 , 6 , 8 , 9 , 10 } ; int sum = 16 ; int n = arr . length ; if ( pairInSortedRotated ( arr , n , sum ) ) System . out . print ( " Array ▁ has ▁ two ▁ elements " + " ▁ with ▁ sum ▁ 16" ) ; else System . out . print ( " Array ▁ doesn ' t ▁ have ▁ two " + " ▁ elements ▁ with ▁ sum ▁ 16 ▁ " ) ; } }

def pairInSortedRotated ( arr , n , x ) : NEW_LINE INDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if ( arr [ i ] > arr [ i + 1 ] ) : NEW_LINE INDENT break ; NEW_LINE DEDENT DEDENT l = ( i + 1 ) % n NEW_LINE r = i NEW_LINE while ( l != r ) : NEW_LINE INDENT if ( arr [ l ] + arr [ r ] == x ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT if ( arr [ l ] + arr [ r ] < x ) : NEW_LINE INDENT l = ( l + 1 ) % n ; NEW_LINE DEDENT else : NEW_LINE INDENT r = ( n + r - 1 ) % n ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT arr = [ 11 , 15 , 26 , 38 , 9 , 10 ] NEW_LINE sum = 16 NEW_LINE n = len ( arr ) NEW_LINE if ( pairInSortedRotated ( arr , n , sum ) ) : NEW_LINE INDENT print ( " Array ▁ has ▁ two ▁ elements ▁ with ▁ sum ▁ 16" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Array ▁ doesn ' t ▁ have ▁ two ▁ elements ▁ with ▁ sum ▁ 16 ▁ " ) NEW_LINE DEDENT


import java . util . HashSet ; public class GFG { public static void printArray ( int arr [ ] [ ] , int row , int col ) { HashSet < String > set = new HashSet < String > ( ) ; for ( int i = 0 ; i < row ; i ++ ) { String s = " " ; for ( int j = 0 ; j < col ; j ++ ) s += String . valueOf ( arr [ i ] [ j ] ) ; if ( ! set . contains ( s ) ) { set . add ( s ) ; System . out . println ( s ) ; } } } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 1 , 1 , 1 , 0 , 0 } } ; printArray ( arr , 4 , 5 ) ; } }

def printArray ( matrix ) : NEW_LINE INDENT rowCount = len ( matrix ) NEW_LINE if rowCount == 0 : NEW_LINE INDENT return NEW_LINE DEDENT columnCount = len ( matrix [ 0 ] ) NEW_LINE if columnCount == 0 : NEW_LINE INDENT return NEW_LINE DEDENT row_output_format = " ▁ " . join ( [ " % s " ] * columnCount ) NEW_LINE printed = { } NEW_LINE for row in matrix : NEW_LINE INDENT routput = row_output_format % tuple ( row ) NEW_LINE if routput not in printed : NEW_LINE INDENT printed [ routput ] = True NEW_LINE print ( routput ) NEW_LINE DEDENT DEDENT DEDENT mat = [ [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 0 ] , [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 1 , 1 , 0 , 0 ] ] NEW_LINE printArray ( mat ) NEW_LINE


class GFG { static int maxSum ( int [ ] a , int n ) { int ans = 0 ; int [ ] arr = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) arr [ i ] = a [ i - 1 ] ; int [ ] [ ] dp = new int [ n + 1 ] [ 3 ] ; for ( int i = 1 ; i <= n ; ++ i ) { dp [ i ] [ 0 ] = Math . max ( arr [ i ] , dp [ i - 1 ] [ 0 ] + arr [ i ] ) ; dp [ i ] [ 1 ] = Math . max ( 0 , dp [ i - 1 ] [ 0 ] ) - arr [ i ] ; if ( i >= 2 ) dp [ i ] [ 1 ] = Math . max ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + arr [ i ] ) ; if ( i >= 2 ) dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] - arr [ i ] ; if ( i >= 3 ) dp [ i ] [ 2 ] = Math . max ( dp [ i ] [ 2 ] , dp [ i - 1 ] [ 2 ] + arr [ i ] ) ; ans = Math . max ( ans , dp [ i ] [ 0 ] ) ; ans = Math . max ( ans , dp [ i ] [ 1 ] ) ; ans = Math . max ( ans , dp [ i ] [ 2 ] ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { - 5 , 3 , 2 , 7 , - 8 , 3 , 7 , - 9 , 10 , 12 , - 6 } ; int n = arr . length ; System . out . println ( maxSum ( arr , n ) ) ; } }

def maxSum ( a , n ) : NEW_LINE INDENT ans = 0 NEW_LINE arr = [ 0 ] * ( n + 1 ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT arr [ i ] = a [ i - 1 ] NEW_LINE DEDENT dp = [ [ 0 for i in range ( 3 ) ] for j in range ( n + 1 ) ] NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = max ( arr [ i ] , dp [ i - 1 ] [ 0 ] + arr [ i ] ) NEW_LINE dp [ i ] [ 1 ] = max ( 0 , dp [ i - 1 ] [ 0 ] ) - arr [ i ] NEW_LINE if i >= 2 : NEW_LINE INDENT dp [ i ] [ 1 ] = max ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 1 ] + arr [ i ] ) NEW_LINE DEDENT if i >= 2 : NEW_LINE INDENT dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] - arr [ i ] NEW_LINE DEDENT if i >= 3 : NEW_LINE INDENT dp [ i ] [ 2 ] = max ( dp [ i ] [ 2 ] , dp [ i - 1 ] [ 2 ] + arr [ i ] ) NEW_LINE DEDENT ans = max ( ans , dp [ i ] [ 0 ] ) NEW_LINE ans = max ( ans , dp [ i ] [ 1 ] ) NEW_LINE ans = max ( ans , dp [ i ] [ 2 ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ - 5 , 3 , 2 , 7 , - 8 , 3 , 7 , - 9 , 10 , 12 , - 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxSum ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static Boolean isPentagonal ( int N ) { int i = 1 , M ; do { M = ( 3 * i * i - i ) / 2 ; i += 1 ; } while ( M < N ) ; return ( M == N ) ; } public static void main ( String [ ] args ) { int N = 12 ; if ( isPentagonal ( N ) ) System . out . println ( N + " ▁ is ▁ pentagonal ▁ " ) ; else System . out . println ( N + " ▁ is ▁ not ▁ pentagonal " ) ; } }

import math NEW_LINE def isPentagonal ( N ) : NEW_LINE INDENT i = 1 NEW_LINE while True : NEW_LINE INDENT M = ( 3 * i * i - i ) / 2 NEW_LINE i += 1 NEW_LINE if ( M >= N ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return ( M == N ) NEW_LINE DEDENT N = 12 NEW_LINE if ( isPentagonal ( N ) ) : NEW_LINE INDENT print ( N , end = ' ▁ ' ) NEW_LINE print ( " is ▁ pentagonal ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( N , end = ' ▁ ' ) NEW_LINE print ( " is ▁ not ▁ pentagonal " ) NEW_LINE DEDENT


class GFG { static boolean findNature ( int a , int b , int n ) { if ( n == 0 ) return ( a & 1 ) == 1 ? true : false ; if ( n == 1 ) return ( b & 1 ) == 1 ? true : false ; if ( ( a & 1 ) == 0 ) { if ( ( b & 1 ) == 0 ) return false ; else return ( n % 3 != 0 ) ; } else { if ( ( b & 1 ) == 0 ) return ( ( n - 1 ) % 3 != 0 ) ; else return ( ( n + 1 ) % 3 != 0 ) ; } } public static void main ( String [ ] args ) { int a = 2 , b = 4 ; int n = 3 ; if ( findNature ( a , b , n ) ) System . out . println ( " Odd " ) ; else System . out . println ( " Even " ) ; } }

def findNature ( a , b , n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return ( a & 1 ) ; NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT return ( b & 1 ) ; NEW_LINE DEDENT if ( ( a & 1 ) == 0 ) : NEW_LINE INDENT if ( ( b & 1 ) == 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT else : NEW_LINE INDENT return True if ( n % 3 != 0 ) else False ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( ( b & 1 ) == 0 ) : NEW_LINE INDENT return True if ( ( n - 1 ) % 3 != 0 ) else False ; NEW_LINE DEDENT else : NEW_LINE INDENT return True if ( ( n + 1 ) % 3 != 0 ) else False ; NEW_LINE DEDENT DEDENT DEDENT a = 2 ; NEW_LINE b = 4 ; NEW_LINE n = 3 ; NEW_LINE if ( findNature ( a , b , n ) == True ) : NEW_LINE INDENT print ( " Odd " , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Even " , end = " ▁ " ) ; NEW_LINE DEDENT


import java . io . * ; class Sums { static void printXYZ ( int n ) { if ( n == 1 ) System . out . println ( - 1 ) ; else { System . out . println ( " x ▁ is ▁ " + n ) ; System . out . println ( " y ▁ is ▁ " + ( n + 1 ) ) ; System . out . println ( " z ▁ is ▁ " + ( n * ( n + 1 ) ) ) ; } } public static void main ( String [ ] args ) { int n = 7 ; printXYZ ( n ) ; } }

def printXYZ ( n ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " x ▁ is ▁ " , n ) NEW_LINE print ( " y ▁ is ▁ " , n + 1 ) NEW_LINE print ( " z ▁ is ▁ " , n * ( n + 1 ) ) NEW_LINE DEDENT DEDENT n = 7 NEW_LINE printXYZ ( n ) NEW_LINE


import java . util . * ; class GFG { static String decToBinary ( int n ) { int [ ] binaryNum = new int [ 32 ] ; int i = 0 ; while ( n > 0 ) { binaryNum [ i ] = n % 2 ; n = n / 2 ; i ++ ; } String binary = " " ; for ( int j = i - 1 ; j >= 0 ; j -- ) { binary += String . valueOf ( binaryNum [ j ] ) ; } return binary ; } static int countFreq ( String pat , String txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; int res = 0 ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) { if ( txt . charAt ( i + j ) != pat . charAt ( j ) ) { break ; } } if ( j == M ) { res ++ ; j = 0 ; } } return res ; } static void findOccurrence ( int arr [ ] , int n , String pattern ) { for ( int i = 0 ; i < n ; i ++ ) { String binary = decToBinary ( arr [ i ] ) ; System . out . print ( countFreq ( pattern , binary ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 106 , 7 , 8 } ; String pattern = "10" ; int n = arr . length ; findOccurrence ( arr , n , pattern ) ; } }

def decToBinary ( n ) : NEW_LINE INDENT binaryNum = [ 0 for i in range ( 32 ) ] NEW_LINE i = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT binaryNum [ i ] = n % 2 NEW_LINE n = n // 2 NEW_LINE i += 1 NEW_LINE DEDENT binary = " " NEW_LINE for j in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT binary += str ( binaryNum [ j ] ) NEW_LINE DEDENT return binary NEW_LINE DEDENT def countFreq ( pat , txt ) : NEW_LINE INDENT M = len ( pat ) NEW_LINE N = len ( txt ) NEW_LINE res = 0 NEW_LINE for i in range ( N - M + 1 ) : NEW_LINE INDENT j = 0 NEW_LINE while ( j < M ) : NEW_LINE INDENT if ( txt [ i + j ] != pat [ j ] ) : NEW_LINE INDENT break NEW_LINE DEDENT j += 1 NEW_LINE DEDENT if ( j == M ) : NEW_LINE INDENT res += 1 NEW_LINE j = 0 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT def findOccurrence ( arr , n , pattern ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT binary = decToBinary ( arr [ i ] ) NEW_LINE print ( countFreq ( pattern , binary ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 5 , 106 , 7 , 8 ] NEW_LINE pattern = "10" NEW_LINE n = len ( arr ) NEW_LINE findOccurrence ( arr , n , pattern ) NEW_LINE


class GFG { static void otherEndPoint ( int x1 , int y1 , int m1 , int m2 ) { float x2 = ( float ) ( 2 * m1 - x1 ) ; float y2 = ( float ) ( 2 * m2 - y1 ) ; System . out . println ( " x2 ▁ = ▁ " + x2 + " , ▁ " + " y2 ▁ = ▁ " + y2 ) ; } public static void main ( String args [ ] ) { int x1 = - 4 , y1 = - 1 , m1 = 3 , m2 = 5 ; otherEndPoint ( x1 , y1 , m1 , m2 ) ; } }

def otherEndPoint ( x1 , y1 , m1 , m2 ) : NEW_LINE INDENT x2 = ( 2 * m1 - x1 ) NEW_LINE y2 = ( 2 * m2 - y1 ) NEW_LINE print ( " x2 ▁ = ▁ { } , ▁ y2 ▁ = ▁ { } " . format ( x2 , y2 ) ) NEW_LINE DEDENT x1 = - 4 NEW_LINE y1 = - 1 NEW_LINE m1 = 3 NEW_LINE m2 = 5 NEW_LINE otherEndPoint ( x1 , y1 , m1 , m2 ) NEW_LINE


import java . util . Arrays ; class GFG { static int maxSortedAdjacentDiff ( int [ ] arr , int n ) { int maxVal = arr [ 0 ] ; int minVal = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { maxVal = Math . max ( maxVal , arr [ i ] ) ; minVal = Math . min ( minVal , arr [ i ] ) ; } int maxBucket [ ] = new int [ n - 1 ] ; int minBucket [ ] = new int [ n - 1 ] ; Arrays . fill ( maxBucket , 0 , n - 1 , Integer . MIN_VALUE ) ; Arrays . fill ( minBucket , 0 , n - 1 , Integer . MAX_VALUE ) ; float delta = ( float ) ( maxVal - minVal ) / ( float ) ( n - 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == maxVal || arr [ i ] == minVal ) { continue ; } int index = ( int ) ( Math . round ( ( arr [ i ] - minVal ) / delta ) ) ; if ( maxBucket [ index ] == Integer . MIN_VALUE ) { maxBucket [ index ] = arr [ i ] ; } else { maxBucket [ index ] = Math . max ( maxBucket [ index ] , arr [ i ] ) ; } if ( minBucket [ index ] == Integer . MAX_VALUE ) { minBucket [ index ] = arr [ i ] ; } else { minBucket [ index ] = Math . min ( minBucket [ index ] , arr [ i ] ) ; } } int prev_val = minVal ; int max_gap = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( minBucket [ i ] == Integer . MAX_VALUE ) { continue ; } max_gap = Math . max ( max_gap , minBucket [ i ] - prev_val ) ; prev_val = maxBucket [ i ] ; } max_gap = Math . max ( max_gap , maxVal - prev_val ) ; return max_gap ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 10 , 5 } ; int n = arr . length ; System . out . println ( maxSortedAdjacentDiff ( arr , n ) ) ; } }

def maxSortedAdjacentDiff ( arr , n ) : NEW_LINE INDENT maxVal , minVal = arr [ 0 ] , arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT maxVal = max ( maxVal , arr [ i ] ) NEW_LINE minVal = min ( minVal , arr [ i ] ) NEW_LINE DEDENT maxBucket = [ INT_MIN ] * ( n - 1 ) NEW_LINE minBucket = [ INT_MAX ] * ( n - 1 ) NEW_LINE delta = ( maxVal - minVal ) // ( n - 1 ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if arr [ i ] == maxVal or arr [ i ] == minVal : NEW_LINE INDENT continue NEW_LINE DEDENT index = ( arr [ i ] - minVal ) // delta NEW_LINE if maxBucket [ index ] == INT_MIN : NEW_LINE INDENT maxBucket [ index ] = arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT maxBucket [ index ] = max ( maxBucket [ index ] , arr [ i ] ) NEW_LINE DEDENT if minBucket [ index ] == INT_MAX : NEW_LINE INDENT minBucket [ index ] = arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT minBucket [ index ] = min ( minBucket [ index ] , arr [ i ] ) NEW_LINE DEDENT DEDENT prev_val , max_gap = minVal , 0 NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if minBucket [ i ] == INT_MAX : NEW_LINE INDENT continue NEW_LINE DEDENT max_gap = max ( max_gap , minBucket [ i ] - prev_val ) NEW_LINE prev_val = maxBucket [ i ] NEW_LINE DEDENT max_gap = max ( max_gap , maxVal - prev_val ) NEW_LINE return max_gap NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 10 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE INT_MIN , INT_MAX = float ( ' - inf ' ) , float ( ' inf ' ) NEW_LINE print ( maxSortedAdjacentDiff ( arr , n ) ) NEW_LINE DEDENT


import java . util . * ; class Solution { static boolean isExists ( int a [ ] , int n ) { Map < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { freq . put ( a [ i ] , freq . get ( a [ i ] ) == null ? 0 : freq . get ( a [ i ] ) + 1 ) ; sum += a [ i ] ; } if ( sum % 2 == 0 ) { if ( freq . get ( sum / 2 ) != null ) return true ; } return false ; } public static void main ( String args [ ] ) { int a [ ] = { 5 , 1 , 2 , 2 } ; int n = a . length ; if ( isExists ( a , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isExists ( a , n ) : NEW_LINE INDENT freq = { i : 0 for i in a } NEW_LINE Sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ a [ i ] ] += 1 NEW_LINE Sum += a [ i ] NEW_LINE DEDENT if Sum % 2 == 0 : NEW_LINE INDENT if freq [ Sum // 2 ] : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT a = [ 5 , 1 , 2 , 2 ] NEW_LINE n = len ( a ) NEW_LINE if isExists ( a , n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class gcdOfFibonacci { static final int MAX = 1000 ; static int [ ] f ; gcdOfFibonacci ( ) { f = new int [ MAX ] ; } private static int fib ( int n ) { if ( n == 0 ) return 0 ; if ( n == 1 || n == 2 ) return ( f [ n ] = 1 ) ; if ( f [ n ] != 0 ) return f [ n ] ; int k = ( ( n & 1 ) == 1 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( ( n & 1 ) == 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } private static int gcd ( int M , int N ) { if ( M == 0 ) return N ; return gcd ( N % M , M ) ; } static int findGCDofFibMFibN ( int M , int N ) { return fib ( gcd ( M , N ) ) ; } public static void main ( String [ ] args ) { gcdOfFibonacci obj = new gcdOfFibonacci ( ) ; int M = 3 , N = 12 ; System . out . println ( findGCDofFibMFibN ( M , N ) ) ; } }

MAX = 1000 NEW_LINE f = [ 0 for i in range ( MAX ) ] NEW_LINE def fib ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( n == 1 or n == 2 ) : NEW_LINE INDENT f [ n ] = 1 NEW_LINE DEDENT if ( f [ n ] ) : NEW_LINE INDENT return f [ n ] NEW_LINE DEDENT k = ( n + 1 ) // 2 if ( n & 1 ) else n // 2 NEW_LINE f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) if ( n & 1 ) else ( ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ) NEW_LINE return f [ n ] NEW_LINE DEDENT def gcd ( M , N ) : NEW_LINE INDENT if ( M == 0 ) : NEW_LINE INDENT return N NEW_LINE DEDENT return gcd ( N % M , M ) NEW_LINE DEDENT def findGCDofFibMFibN ( M , N ) : NEW_LINE INDENT return fib ( gcd ( M , N ) ) NEW_LINE DEDENT M = 3 NEW_LINE N = 12 NEW_LINE print ( findGCDofFibMFibN ( M , N ) ) NEW_LINE


import java . io . * ; public class GFG { static long squareRoot ( int n ) { int x = n ; int y = 1 ; while ( x > y ) { x = ( x + y ) / 2 ; y = n / x ; } return ( long ) x ; } static public void main ( String [ ] args ) { int n = 49 ; System . out . println ( " root ▁ of ▁ " + n + " ▁ is ▁ " + squareRoot ( n ) ) ; } }

def squareRoot ( n ) : NEW_LINE INDENT x = n ; NEW_LINE y = 1 ; NEW_LINE while ( x > y ) : NEW_LINE INDENT x = ( x + y ) / 2 ; NEW_LINE y = n / x ; NEW_LINE DEDENT return x ; NEW_LINE DEDENT n = 49 ; NEW_LINE print ( " root ▁ of " , n , " is " , squareRoot ( n ) ) ; NEW_LINE


public class GFG { static int eggDrop ( int n , int k ) { if ( k == 1 || k == 0 ) return k ; if ( n == 1 ) return k ; int min = Integer . MAX_VALUE ; int x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } public static void main ( String args [ ] ) { int n = 2 , k = 10 ; System . out . print ( " Minimum ▁ number ▁ of ▁ " + " trials ▁ in ▁ worst ▁ case ▁ with ▁ " + n + " ▁ eggs ▁ and ▁ " + k + " ▁ floors ▁ is ▁ " + eggDrop ( n , k ) ) ; } }

import sys NEW_LINE def eggDrop ( n , k ) : NEW_LINE INDENT if ( k == 1 or k == 0 ) : NEW_LINE INDENT return k NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT return k NEW_LINE DEDENT min = sys . maxsize NEW_LINE for x in range ( 1 , k + 1 ) : NEW_LINE INDENT res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) NEW_LINE if ( res < min ) : NEW_LINE INDENT min = res NEW_LINE DEDENT DEDENT return min + 1 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 2 NEW_LINE k = 10 NEW_LINE print ( " Minimum ▁ number ▁ of ▁ trials ▁ in ▁ worst ▁ case ▁ with " , n , " eggs ▁ and " , k , " floors ▁ is " , eggDrop ( n , k ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static boolean findParity ( int x ) { int y = x ^ ( x >> 1 ) ; y = y ^ ( y >> 2 ) ; y = y ^ ( y >> 4 ) ; y = y ^ ( y >> 8 ) ; y = y ^ ( y >> 16 ) ; if ( ( y & 1 ) > 0 ) return true ; return false ; } public static void main ( String [ ] args ) { if ( ( findParity ( 9 ) == false ) ) System . out . println ( " Even ▁ Parity " ) ; else System . out . println ( " Odd ▁ Parity " ) ; if ( findParity ( 13 ) == false ) System . out . println ( " Even ▁ Parity " ) ; else System . out . println ( " Odd ▁ Parity " ) ; } }

def findParity ( x ) : NEW_LINE INDENT y = x ^ ( x >> 1 ) ; NEW_LINE y = y ^ ( y >> 2 ) ; NEW_LINE y = y ^ ( y >> 4 ) ; NEW_LINE y = y ^ ( y >> 8 ) ; NEW_LINE y = y ^ ( y >> 16 ) ; NEW_LINE if ( y & 1 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT if ( findParity ( 9 ) == 0 ) : NEW_LINE INDENT print ( " Even ▁ Parity " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Odd ▁ Parity \n " ) ; NEW_LINE DEDENT if ( findParity ( 13 ) == 0 ) : NEW_LINE INDENT print ( " Even ▁ Parity " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Odd ▁ Parity " ) ; NEW_LINE DEDENT


import java . util . HashMap ; class GFG { public static int countOccurence ( int n , int [ ] arr , int k ) { int ans = 0 ; HashMap < Integer , Boolean > hash = new HashMap < > ( ) ; HashMap < Integer , Integer > occurence = new HashMap < > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( hash . get ( arr [ i ] ) != null && hash . get ( arr [ i ] ) == true ) continue ; if ( occurence . get ( arr [ i ] ) != null && occurence . get ( arr [ i ] ) >= k ) { ans ++ ; hash . put ( arr [ i ] , true ) ; } else { if ( occurence . get ( arr [ i ] ) == null ) occurence . put ( arr [ i ] , 1 ) ; else { int temp = occurence . get ( arr [ i ] ) ; occurence . put ( arr [ i ] , ++ temp ) ; } } } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 , 3 } ; int n = arr . length ; int k = 1 ; System . out . println ( countOccurence ( n , arr , k ) ) ; } }

def countOccurrence ( n , arr , k ) : NEW_LINE INDENT ans = 0 ; NEW_LINE hash = dict . fromkeys ( arr , 0 ) ; NEW_LINE occurrence = dict . fromkeys ( arr , 0 ) ; NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( hash [ arr [ i ] ] == True ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT if ( occurrence [ arr [ i ] ] >= k ) : NEW_LINE INDENT ans += 1 ; NEW_LINE hash [ arr [ i ] ] = True ; NEW_LINE DEDENT else : NEW_LINE INDENT occurrence [ arr [ i ] ] += 1 ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 1 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE k = 1 ; NEW_LINE print ( countOccurrence ( n , arr , k ) ) ; NEW_LINE DEDENT


class GFG { static int MAX = 10 ; static boolean isDigit ( char ch ) { if ( ch >= '0' && ch <= '9' ) return true ; return false ; } static boolean allDigits ( String str , int len ) { boolean [ ] present = new boolean [ MAX ] ; for ( int i = 0 ; i < len ; i ++ ) { if ( isDigit ( str . charAt ( i ) ) ) { int digit = str . charAt ( i ) - '0' ; present [ digit ] = true ; } } for ( int i = 0 ; i < MAX ; i ++ ) { if ( ! present [ i ] ) return false ; } return true ; } public static void main ( String [ ] args ) { String str = " Geeks12345for69708" ; int len = str . length ( ) ; if ( allDigits ( str , len ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

MAX = 10 NEW_LINE def isDigit ( ch ) : NEW_LINE INDENT ch = ord ( ch ) NEW_LINE if ( ch >= ord ( '0' ) and ch <= ord ( '9' ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def allDigits ( st , le ) : NEW_LINE INDENT present = [ False for i in range ( MAX ) ] NEW_LINE for i in range ( le ) : NEW_LINE INDENT if ( isDigit ( st [ i ] ) ) : NEW_LINE INDENT digit = ord ( st [ i ] ) - ord ( '0' ) NEW_LINE present [ digit ] = True NEW_LINE DEDENT DEDENT for i in range ( MAX ) : NEW_LINE INDENT if ( present [ i ] == False ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT st = " Geeks12345for69708" NEW_LINE le = len ( st ) NEW_LINE if ( allDigits ( st , le ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void findSubsequence ( int [ ] arr , int n , int k ) { HashMap < Integer , Integer > M = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( M . containsKey ( arr [ i ] ) ) M . put ( arr [ i ] , M . get ( arr [ i ] ) + 1 ) ; else M . put ( arr [ i ] , 1 ) ; } int [ ] numCount = new int [ k + 1 ] ; for ( int i = 0 ; i <= k ; ++ i ) numCount [ i ] = 0 ; Iterator < HashMap . Entry < Integer , Integer > > itr = M . entrySet ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { HashMap . Entry < Integer , Integer > entry = itr . next ( ) ; if ( entry . getKey ( ) <= k ) { for ( int i = 1 ; ; ++ i ) { if ( entry . getKey ( ) * i > k ) break ; numCount [ entry . getKey ( ) * i ] += entry . getValue ( ) ; } } else break ; } int lcm = 0 , length = 0 ; for ( int i = 1 ; i <= k ; ++ i ) { if ( numCount [ i ] > length ) { length = numCount [ i ] ; lcm = i ; } } if ( lcm == 0 ) System . out . println ( - 1 ) ; else { System . out . println ( " LCM ▁ = ▁ " + lcm + " ▁ Length ▁ = ▁ " + length ) ; System . out . print ( " Indexes ▁ = ▁ " ) ; for ( int i = 0 ; i < n ; ++ i ) if ( lcm % arr [ i ] == 0 ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int k = 14 ; int arr [ ] = { 2 , 3 , 4 , 5 } ; int n = arr . length ; findSubsequence ( arr , n , k ) ; } }

from collections import defaultdict NEW_LINE def findSubsequence ( arr , n , k ) : NEW_LINE INDENT M = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT M [ arr [ i ] ] += 1 NEW_LINE DEDENT numCount = [ 0 ] * ( k + 1 ) NEW_LINE for p in M : NEW_LINE INDENT if p <= k : NEW_LINE INDENT i = 1 NEW_LINE while p * i <= k : NEW_LINE INDENT numCount [ p * i ] += M [ p ] NEW_LINE i += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT lcm , length = 0 , 0 NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT if numCount [ i ] > length : NEW_LINE INDENT length = numCount [ i ] NEW_LINE lcm = i NEW_LINE DEDENT DEDENT if lcm == 0 : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " LCM ▁ = ▁ { 0 } , ▁ Length ▁ = ▁ { 1 } " . format ( lcm , length ) ) NEW_LINE print ( " Indexes ▁ = ▁ " , end = " " ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if lcm % arr [ i ] == 0 : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT k = 14 NEW_LINE arr = [ 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE findSubsequence ( arr , n , k ) NEW_LINE DEDENT


import java . lang . * ; class GFG { static final int mod = 1000000007 ; static int digitNumber ( long n ) { if ( n == 0 ) return 1 ; if ( n == 1 ) return 9 ; if ( n % 2 != 0 ) { int temp = digitNumber ( ( n - 1 ) / 2 ) % mod ; return ( 9 * ( temp * temp ) % mod ) % mod ; } else { int temp = digitNumber ( n / 2 ) % mod ; return ( temp * temp ) % mod ; } } static int countExcluding ( int n , int d ) { if ( d == 0 ) return ( 9 * digitNumber ( n - 1 ) ) % mod ; else return ( 8 * digitNumber ( n - 1 ) ) % mod ; } public static void main ( String [ ] args ) { int d = 9 ; int n = 3 ; System . out . println ( countExcluding ( n , d ) ) ; } }

mod = 1000000007 NEW_LINE def digitNumber ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT return 9 NEW_LINE DEDENT if ( n % 2 != 0 ) : NEW_LINE INDENT temp = digitNumber ( ( n - 1 ) // 2 ) % mod NEW_LINE return ( 9 * ( temp * temp ) % mod ) % mod NEW_LINE DEDENT else : NEW_LINE INDENT temp = digitNumber ( n // 2 ) % mod NEW_LINE return ( temp * temp ) % mod NEW_LINE DEDENT DEDENT def countExcluding ( n , d ) : NEW_LINE INDENT if ( d == 0 ) : NEW_LINE INDENT return ( 9 * digitNumber ( n - 1 ) ) % mod NEW_LINE DEDENT else : NEW_LINE INDENT return ( 8 * digitNumber ( n - 1 ) ) % mod NEW_LINE DEDENT DEDENT d = 9 NEW_LINE n = 3 NEW_LINE print ( countExcluding ( n , d ) ) NEW_LINE


import java . util . * ; class solution { static int minimumX ( int n , int k ) { int mini = Integer . MAX_VALUE ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { int fir = i ; int sec = n / i ; int num1 = fir * k + sec ; int res = ( num1 / k ) * ( num1 % k ) ; if ( res == n ) mini = Math . min ( num1 , mini ) ; int num2 = sec * k + fir ; res = ( num2 / k ) * ( num2 % k ) ; if ( res == n ) mini = Math . min ( num2 , mini ) ; } } return mini ; } public static void main ( String args [ ] ) { int n = 4 , k = 6 ; System . out . println ( minimumX ( n , k ) ) ; n = 5 ; k = 5 ; System . out . println ( minimumX ( n , k ) ) ; } }

import sys NEW_LINE def minimumX ( n , k ) : NEW_LINE INDENT mini = sys . maxsize NEW_LINE i = 1 NEW_LINE while i * i <= n : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT fir = i NEW_LINE sec = n // i NEW_LINE num1 = fir * k + sec NEW_LINE res = ( num1 // k ) * ( num1 % k ) NEW_LINE if ( res == n ) : NEW_LINE INDENT mini = min ( num1 , mini ) NEW_LINE DEDENT num2 = sec * k + fir NEW_LINE res = ( num2 // k ) * ( num2 % k ) NEW_LINE if ( res == n ) : NEW_LINE INDENT mini = min ( num2 , mini ) NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT return mini NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 NEW_LINE k = 6 NEW_LINE print ( minimumX ( n , k ) ) NEW_LINE n = 5 NEW_LINE k = 5 NEW_LINE print ( minimumX ( n , k ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { public static void sumSubsets ( int set [ ] , int n , int target ) { int x [ ] = new int [ set . length ] ; int j = set . length - 1 ; while ( n > 0 ) { x [ j ] = n % 2 ; n = n / 2 ; j -- ; } int sum = 0 ; for ( int i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) sum = sum + set [ i ] ; if ( sum == target ) { System . out . print ( " { " ) ; for ( int i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) System . out . print ( set [ i ] + " , ▁ " ) ; System . out . print ( " } , ▁ " ) ; } } public static void findSubsets ( int [ ] arr , int K ) { int x = ( int ) Math . pow ( 2 , arr . length ) ; for ( int i = 1 ; i < x ; i ++ ) sumSubsets ( arr , i , K ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 10 , 12 , 13 , 15 , 18 } ; int K = 30 ; findSubsets ( arr , K ) ; } }

def sumSubsets ( sets , n , target ) : NEW_LINE INDENT x = [ 0 ] * len ( sets ) ; NEW_LINE j = len ( sets ) - 1 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT x [ j ] = n % 2 ; NEW_LINE n = n // 2 ; NEW_LINE j -= 1 ; NEW_LINE DEDENT sum = 0 ; NEW_LINE for i in range ( len ( sets ) ) : NEW_LINE INDENT if ( x [ i ] == 1 ) : NEW_LINE INDENT sum += sets [ i ] ; NEW_LINE DEDENT DEDENT if ( sum == target ) : NEW_LINE INDENT print ( " { " , end = " " ) ; NEW_LINE for i in range ( len ( sets ) ) : NEW_LINE INDENT if ( x [ i ] == 1 ) : NEW_LINE INDENT print ( sets [ i ] , end = " , ▁ " ) ; NEW_LINE DEDENT DEDENT print ( " } , ▁ " , end = " " ) ; NEW_LINE DEDENT DEDENT def findSubsets ( arr , K ) : NEW_LINE INDENT x = pow ( 2 , len ( arr ) ) ; NEW_LINE for i in range ( 1 , x ) : NEW_LINE INDENT sumSubsets ( arr , i , K ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 10 , 12 , 13 , 15 , 18 ] ; NEW_LINE K = 30 ; NEW_LINE findSubsets ( arr , K ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int data ) { Node ptr1 = new Node ( ) ; Node temp = head_ref ; ptr1 . data = data ; ptr1 . next = head_ref ; if ( head_ref != null ) { while ( temp . next != head_ref ) temp = temp . next ; temp . next = ptr1 ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } static int sumOfList ( Node head ) { Node temp = head ; int sum = 0 ; if ( head != null ) { do { temp = temp . next ; sum += temp . data ; } while ( temp != head ) ; } return sum ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 12 ) ; head = push ( head , 56 ) ; head = push ( head , 2 ) ; head = push ( head , 11 ) ; System . out . println ( " Sum ▁ of ▁ Circular ▁ linked " + " ▁ list ▁ is ▁ = ▁ " + sumOfList ( head ) ) ; } }

import math NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def push ( head , data ) : NEW_LINE INDENT if not head : NEW_LINE INDENT head = Node ( data ) NEW_LINE head . next = head NEW_LINE return head NEW_LINE DEDENT lnode = head NEW_LINE while ( lnode and lnode . next is not head ) : NEW_LINE INDENT lnode = lnode . next NEW_LINE DEDENT ptr1 = Node ( data ) NEW_LINE ptr1 . next = head NEW_LINE lnode . next = ptr1 NEW_LINE head = ptr1 NEW_LINE return head NEW_LINE DEDENT def sumOfList ( head ) : NEW_LINE INDENT temp = head NEW_LINE tsum = temp . data NEW_LINE temp = temp . next NEW_LINE while ( temp is not head ) : NEW_LINE INDENT tsum += temp . data NEW_LINE temp = temp . next NEW_LINE DEDENT return tsum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 12 ) NEW_LINE head = push ( head , 56 ) NEW_LINE head = push ( head , 2 ) NEW_LINE head = push ( head , 11 ) NEW_LINE print ( " Sum ▁ of ▁ circular ▁ list ▁ is ▁ = ▁ { } " . format ( sumOfList ( head ) ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { public static double polygonArea ( double X [ ] , double Y [ ] , int n ) { double area = 0.0 ; int j = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) ; j = i ; } return Math . abs ( area / 2.0 ) ; } public static void main ( String [ ] args ) { double X [ ] = { 0 , 2 , 4 } ; double Y [ ] = { 1 , 3 , 7 } ; int n = 3 ; System . out . println ( polygonArea ( X , Y , n ) ) ; } }

def polygonArea ( X , Y , n ) : NEW_LINE INDENT area = 0.0 NEW_LINE j = n - 1 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT area += ( X [ j ] + X [ i ] ) * ( Y [ j ] - Y [ i ] ) NEW_LINE j = i NEW_LINE DEDENT return int ( abs ( area / 2.0 ) ) NEW_LINE DEDENT X = [ 0 , 2 , 4 ] NEW_LINE Y = [ 1 , 3 , 7 ] NEW_LINE n = len ( X ) NEW_LINE print ( polygonArea ( X , Y , n ) ) NEW_LINE


class GFG { static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) { int n = s1 . length ( ) ; int m = s2 . length ( ) ; int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ; if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ; if ( cnt [ i ] [ j ] >= k ) { for ( int a = k ; a <= cnt [ i ] [ j ] ; a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ; } } } return lcs [ n ] [ m ] ; } public static void main ( String [ ] args ) { int k = 4 ; String s1 = " aggasdfa " ; String s2 = " aggajasdfa " ; System . out . println ( longestSubsequenceCommonSegment ( k , s1 , s2 ) ) ; } }

def longestSubsequenceCommonSegment ( k , s1 , s2 ) : NEW_LINE INDENT n = len ( s1 ) NEW_LINE m = len ( s2 ) NEW_LINE lcs = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ] NEW_LINE cnt = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , m + 1 ) : NEW_LINE INDENT lcs [ i ] [ j ] = max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) NEW_LINE if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) : NEW_LINE INDENT cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ; NEW_LINE DEDENT if ( cnt [ i ] [ j ] >= k ) : NEW_LINE INDENT for a in range ( k , cnt [ i ] [ j ] + 1 ) : NEW_LINE INDENT lcs [ i ] [ j ] = max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) NEW_LINE DEDENT DEDENT DEDENT DEDENT return lcs [ n ] [ m ] NEW_LINE DEDENT k = 4 NEW_LINE s1 = " aggasdfa " NEW_LINE s2 = " aggajasdfa " NEW_LINE print ( longestSubsequenceCommonSegment ( k , s1 , s2 ) ) NEW_LINE


import java . io . * ; class GFG { static int pentagon_pyramidal ( int n ) { return n * n * ( n + 1 ) / 2 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( pentagon_pyramidal ( n ) ) ; } }

def pentagon_pyramidal ( n ) : NEW_LINE INDENT return n * n * ( n + 1 ) / 2 NEW_LINE DEDENT n = 4 NEW_LINE print ( int ( pentagon_pyramidal ( n ) ) ) NEW_LINE


import java . util . * ; import java . math . * ; class GFG { static int maxnumber ( int n , int k ) { for ( int j = 0 ; j < k ; j ++ ) { int ans = 0 ; int i = 1 ; while ( n / i > 0 ) { int temp = ( n / ( i * 10 ) ) * i + ( n % i ) ; i *= 10 ; ans = Math . max ( ans , temp ) ; } n = ans ; } return n ; } public static void main ( String [ ] args ) { int n = 6358 ; int k = 1 ; System . out . println ( maxnumber ( n , k ) ) ; } }

def maxnumber ( n , k ) : NEW_LINE INDENT for i in range ( 0 , k ) : NEW_LINE INDENT ans = 0 NEW_LINE i = 1 NEW_LINE while n // i > 0 : NEW_LINE INDENT temp = ( n // ( i * 10 ) ) * i + ( n % i ) NEW_LINE i *= 10 NEW_LINE if temp > ans : NEW_LINE INDENT ans = temp NEW_LINE DEDENT DEDENT n = ans NEW_LINE DEDENT return ans ; NEW_LINE DEDENT n = 6358 NEW_LINE k = 1 NEW_LINE print ( maxnumber ( n , k ) ) NEW_LINE


class GFG { public static int solve ( int n ) { int ans = ( n * n / 4 ) ; return ans ; } public static void main ( String args [ ] ) { int n = 10 ; System . out . println ( solve ( n ) ) ; } }

def solve ( n ) : NEW_LINE INDENT ans = ( n * n // 4 ) NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 NEW_LINE print ( solve ( n ) ) NEW_LINE DEDENT


import java . util . * ; public class GFG { public static void getStrings ( String str , String [ ] arr ) { for ( int i = 0 ; i < arr . length ; i ++ ) { if ( check ( arr [ i ] , str ) ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static boolean check ( String s , String str ) { char [ ] chars = s . toCharArray ( ) ; for ( char c : chars ) { if ( ! str . contains ( String . valueOf ( c ) ) ) { return false ; } } for ( int i = 0 ; i < chars . length - 1 ; i ++ ) { if ( chars [ i ] == chars [ i + 1 ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str = " ABCD " ; String [ ] arr = { " AABCDA " , " ABCDZADC " , " ABCDBCA " , " ABCDABDCA " } ; getStrings ( str , arr ) ; } }

def getStrings ( strr , arr ) : NEW_LINE INDENT for i in range ( len ( arr ) ) : NEW_LINE INDENT if ( check ( arr [ i ] , strr ) ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT def check ( s , strr ) : NEW_LINE INDENT chars = s NEW_LINE for c in chars : NEW_LINE INDENT if c not in strr : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT for i in range ( len ( chars ) - 1 ) : NEW_LINE INDENT if ( chars [ i ] == chars [ i + 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT strr = " ABCD " NEW_LINE arr = [ " AABCDA " , " ABCDZADC " , " ABCDBCA " , " ABCDABDCA " ] NEW_LINE getStrings ( strr , arr ) NEW_LINE


class GFG { static final int MOD = 1000000007 ; static int modFact ( int n , int m ) { int result = 1 ; for ( int i = 1 ; i <= m ; i ++ ) result = ( result * i ) % MOD ; return result ; } public static void main ( String [ ] args ) { int n = 3 , m = 2 ; System . out . println ( modFact ( n , m ) ) ; } }

MOD = 1000000007 NEW_LINE def modFact ( n , m ) : NEW_LINE INDENT result = 1 NEW_LINE for i in range ( 1 , m + 1 ) : NEW_LINE INDENT result = ( result * i ) % MOD NEW_LINE DEDENT return result NEW_LINE DEDENT n = 3 NEW_LINE m = 2 NEW_LINE print ( modFact ( n , m ) ) NEW_LINE


import java . util . * ; class GFG { static int fact ( int n ) { int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ( ans ) ; } static int numberOfPossiblePallindrome ( String str , int n ) { Map < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) mp . put ( str . charAt ( i ) , mp . get ( str . charAt ( i ) ) == null ? 1 : mp . get ( str . charAt ( i ) ) + 1 ) ; int k = 0 ; int num = 0 ; int den = 1 ; int fi ; for ( Map . Entry < Character , Integer > it : mp . entrySet ( ) ) { if ( it . getValue ( ) % 2 == 0 ) fi = it . getValue ( ) / 2 ; else { fi = ( it . getValue ( ) - 1 ) / 2 ; k ++ ; } num = num + fi ; den = den * fact ( fi ) ; } if ( num != 0 ) num = fact ( num ) ; int ans = num / den ; if ( k != 0 ) { ans = ans * k ; } return ( ans ) ; } public static void main ( String [ ] args ) { String str = " ababab " ; int n = str . length ( ) ; System . out . println ( numberOfPossiblePallindrome ( str , n ) ) ; } }

import math as mt NEW_LINE def fact ( n ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans = ans * i NEW_LINE DEDENT return ( ans ) NEW_LINE DEDENT def numberOfPossiblePallindrome ( string , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if string [ i ] in mp . keys ( ) : NEW_LINE INDENT mp [ string [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ string [ i ] ] = 1 NEW_LINE DEDENT DEDENT k = 0 NEW_LINE num = 0 NEW_LINE den = 1 NEW_LINE fi = 0 NEW_LINE for it in mp : NEW_LINE INDENT if ( mp [ it ] % 2 == 0 ) : NEW_LINE INDENT fi = mp [ it ] // 2 NEW_LINE DEDENT else : NEW_LINE INDENT fi = ( mp [ it ] - 1 ) // 2 NEW_LINE k += 1 NEW_LINE DEDENT num = num + fi NEW_LINE den = den * fact ( fi ) NEW_LINE DEDENT if ( num != 0 ) : NEW_LINE INDENT num = fact ( num ) NEW_LINE DEDENT ans = num // den NEW_LINE if ( k != 0 ) : NEW_LINE INDENT ans = ans * k NEW_LINE DEDENT return ( ans ) NEW_LINE DEDENT string = " ababab " NEW_LINE n = len ( string ) NEW_LINE print ( numberOfPossiblePallindrome ( string , n ) ) NEW_LINE


import java . io . * ; class GFG { static void printpascalmatrix ( int n ) { int C [ ] [ ] = new int [ 2 * n + 1 ] [ 2 * n + 1 ] ; for ( int i = 0 ; i <= 2 * n ; i ++ ) { for ( int j = 0 ; j <= Math . min ( i , 2 * n ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) System . out . print ( C [ i + j ] [ i ] + " ▁ " ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int n = 5 ; printpascalmatrix ( n ) ; } }

def printpascalmatrix ( n ) : NEW_LINE INDENT C = [ [ 0 for x in range ( 2 * n + 1 ) ] for y in range ( 2 * n + 1 ) ] NEW_LINE for i in range ( 2 * n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , 2 * n ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ; NEW_LINE DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT print ( C [ i + j ] [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT print ( ) ; NEW_LINE DEDENT DEDENT n = 5 ; NEW_LINE printpascalmatrix ( n ) ; NEW_LINE


import java . io . * ; class GFG { static int countPairs ( int n ) { int count = 0 ; for ( int x = 1 ; x < n ; x ++ ) { for ( int y = x + 1 ; y <= n ; y ++ ) { if ( ( y * x ) % ( y + x ) == 0 ) count ++ ; } } return count ; } public static void main ( String [ ] args ) { int n = 15 ; System . out . println ( countPairs ( n ) ) ; } }

def countPairs ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for x in range ( 1 , n ) : NEW_LINE INDENT for y in range ( x + 1 , n + 1 ) : NEW_LINE INDENT if ( ( y * x ) % ( y + x ) == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT n = 15 NEW_LINE print ( countPairs ( n ) ) NEW_LINE


class GFG { public static void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] ) ; } public static int compare ( int num1 , int num2 ) { String A = Integer . toString ( num1 ) ; String B = Integer . toString ( num2 ) ; return ( A + B ) . compareTo ( B + A ) ; } public static void printSmallest ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( compare ( arr [ i ] , arr [ j ] ) > 0 ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } } printArr ( arr , N ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 6 , 2 , 9 , 21 , 1 } ; int N = arr . length ; printSmallest ( N , arr ) ; } }

def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = " " ) NEW_LINE DEDENT DEDENT def compare ( num1 , num2 ) : NEW_LINE INDENT A = str ( num1 ) NEW_LINE B = str ( num2 ) NEW_LINE return int ( A + B ) <= int ( B + A ) NEW_LINE DEDENT def sort ( arr ) : NEW_LINE INDENT for i in range ( len ( arr ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( arr ) ) : NEW_LINE INDENT if compare ( arr [ i ] , arr [ j ] ) == False : NEW_LINE INDENT arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE DEDENT DEDENT DEDENT DEDENT def printSmallest ( N , arr ) : NEW_LINE INDENT sort ( arr ) NEW_LINE printArr ( arr , N ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 6 , 2 , 9 , 21 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE printSmallest ( N , arr ) NEW_LINE DEDENT


class GFG { static boolean isPerfect ( int n ) { int sum = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return true ; return false ; } public static void main ( String [ ] args ) { System . out . println ( " Below ▁ are ▁ all ▁ perfect " + " numbers ▁ till ▁ 10000" ) ; for ( int n = 2 ; n < 10000 ; n ++ ) if ( isPerfect ( n ) ) System . out . println ( n + " ▁ is ▁ a ▁ perfect ▁ number " ) ; } }

def isPerfect ( n ) : NEW_LINE INDENT sum = 1 NEW_LINE i = 2 NEW_LINE while i * i <= n : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT sum = sum + i + n / i NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return ( True if sum == n and n != 1 else False ) NEW_LINE DEDENT print ( " Below ▁ are ▁ all ▁ perfect ▁ numbers ▁ till ▁ 10000" ) NEW_LINE n = 2 NEW_LINE for n in range ( 10000 ) : NEW_LINE INDENT if isPerfect ( n ) : NEW_LINE INDENT print ( n , " ▁ is ▁ a ▁ perfect ▁ number " ) NEW_LINE DEDENT DEDENT


class GFG { static void findString ( String str , int n , int k ) { if ( k == 0 ) { System . out . println ( str ) ; ; return ; } String str2 = str ; int p = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str2 . charAt ( i ) != ' a ' ) { str2 = str2 . substring ( 0 , i ) + ' a ' + str2 . substring ( i + 1 ) ; p ++ ; if ( p == k ) break ; } } if ( p < k ) { for ( int i = n - 1 ; i >= 0 ; i -- ) if ( str . charAt ( i ) == ' a ' ) { str2 = str2 . substring ( 0 , i ) + ' b ' + str2 . substring ( i + 1 ) ; p ++ ; if ( p == k ) break ; } } System . out . println ( str2 ) ; } public static void main ( String [ ] args ) { String str = " pqrs " ; int n = str . length ( ) ; int k = 2 ; findString ( str , n , k ) ; } }

def findString ( str , n , k ) : NEW_LINE INDENT if ( k == 0 ) : NEW_LINE INDENT print ( str ) NEW_LINE return NEW_LINE DEDENT str2 = str NEW_LINE p = 0 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( str2 [ i ] != ' a ' ) : NEW_LINE INDENT str2 = str2 . replace ( str2 [ i ] , ' a ' ) NEW_LINE p += 1 NEW_LINE if ( p == k ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT if ( p < k ) : NEW_LINE INDENT i = n - 1 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT if ( str [ i ] == ' a ' ) : NEW_LINE INDENT str2 = str2 . replace ( str2 [ i ] , ' b ' ) NEW_LINE p += 1 NEW_LINE DEDENT if ( p == k ) : NEW_LINE INDENT break NEW_LINE DEDENT i -= 1 NEW_LINE DEDENT DEDENT print ( str2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " pqrs " NEW_LINE n = len ( str ) NEW_LINE k = 2 NEW_LINE findString ( str , n , k ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void check ( int arr [ ] , int N ) { int even = 0 ; int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == N || odd == N ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 3 } ; int N = arr . length ; check ( arr , N ) ; } }

def check ( arr , N ) : NEW_LINE INDENT even = 0 ; NEW_LINE odd = 0 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 1 ) : NEW_LINE INDENT odd += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT even += 1 ; NEW_LINE DEDENT DEDENT if ( even == N or odd == N ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 3 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE check ( arr , N ) ; NEW_LINE DEDENT


class GfG { static int getCount ( int a , int b , int c ) { int count = 0 ; for ( int i = 1 ; i <= 81 ; i ++ ) { int cr = b * ( int ) Math . pow ( i , a ) + c ; int tmp = cr ; int sm = 0 ; while ( tmp != 0 ) { sm += tmp % 10 ; tmp /= 10 ; } if ( sm == i && cr < 1e9 ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int a = 3 , b = 2 , c = 8 ; System . out . println ( getCount ( a , b , c ) ) ; } }

def getCount ( a , b , c ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , 82 ) : NEW_LINE INDENT cr = b * pow ( i , a ) + c NEW_LINE tmp = cr NEW_LINE sm = 0 NEW_LINE while ( tmp ) : NEW_LINE INDENT sm += tmp % 10 NEW_LINE tmp //= 10 NEW_LINE DEDENT if ( sm == i and cr < 10 ** 9 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT a , b , c = 3 , 2 , 8 NEW_LINE print ( getCount ( a , b , c ) ) NEW_LINE


import java . io . * ; class GFG { static int computeLastDigit ( long A , long B ) { int variable = 1 ; if ( A == B ) return 1 ; else if ( ( B - A ) >= 5 ) return 0 ; else { for ( long i = A + 1 ; i <= B ; i ++ ) variable = ( int ) ( variable * ( i % 10 ) ) % 10 ; return variable % 10 ; } } public static void main ( String [ ] args ) { System . out . println ( computeLastDigit ( 2632 , 2634 ) ) ; } }

def computeLastDigit ( A , B ) : NEW_LINE INDENT variable = 1 NEW_LINE if ( A == B ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif ( ( B - A ) >= 5 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( A + 1 , B + 1 ) : NEW_LINE INDENT variable = ( variable * ( i % 10 ) ) % 10 NEW_LINE DEDENT return variable % 10 NEW_LINE DEDENT DEDENT print ( computeLastDigit ( 2632 , 2634 ) ) NEW_LINE