class GFG { static int maxTeams ( int N1 , int N2 ) { int count = 0 ; while ( N1 > 0 && N2 > 0 && N1 + N2 >= 3 ) { if ( N1 > N2 ) { N1 -= 2 ; N2 -= 1 ; } else { N1 -= 1 ; N2 -= 2 ; } count ++ ; } return count ; } public static void main ( String [ ] args ) { int N1 = 4 , N2 = 5 ; System . out . println ( maxTeams ( N1 , N2 ) ) ; } }

def maxTeams ( N1 , N2 ) : NEW_LINE INDENT count = 0 NEW_LINE while ( N1 > 0 and N2 > 0 and N1 + N2 >= 3 ) : NEW_LINE INDENT if ( N1 > N2 ) : NEW_LINE INDENT N1 -= 2 NEW_LINE N2 -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT N1 -= 1 NEW_LINE N2 -= 2 NEW_LINE DEDENT count = count + 1 NEW_LINE DEDENT return count NEW_LINE DEDENT N1 = 4 NEW_LINE N2 = 5 NEW_LINE print ( maxTeams ( N1 , N2 ) ) NEW_LINE


import java . util . * ; class solution { static void printExpansion ( String str ) { String suff = " " ; for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) { suff = suff + str . charAt ( i ) ; System . out . print ( suff ) ; } } public static void main ( String args [ ] ) { String str = " geeks " ; printExpansion ( str ) ; } }

def printExpansion ( str ) : NEW_LINE INDENT suff = " " NEW_LINE for i in range ( len ( str ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT suff = suff + str [ i ] NEW_LINE print ( suff , end = " " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " geeks " NEW_LINE printExpansion ( str ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; class GFG { static void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } static void generateArr ( int arr [ ] , int n ) { boolean flip = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) { if ( flip ^= true ) System . out . print ( ( int ) ( Math . ceil ( arr [ i ] / 2.0 ) ) + " ▁ " ) ; else System . out . print ( ( int ) ( Math . floor ( arr [ i ] / 2.0 ) ) + " ▁ " ) ; } else { System . out . print ( arr [ i ] / 2 + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 3 , - 5 , - 7 , 9 , 2 , - 2 } ; int n = arr . length ; generateArr ( arr , n ) ; } }

from math import ceil , floor NEW_LINE def printArr ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def generateArr ( arr , n ) : NEW_LINE INDENT flip = True NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] & 1 ) : NEW_LINE INDENT flip ^= True NEW_LINE if ( flip ) : NEW_LINE INDENT print ( int ( ceil ( ( arr [ i ] ) / 2 ) ) , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( int ( floor ( ( arr [ i ] ) / 2 ) ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( int ( arr [ i ] / 2 ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 3 , - 5 , - 7 , 9 , 2 , - 2 ] NEW_LINE n = len ( arr ) NEW_LINE generateArr ( arr , n ) NEW_LINE


import java . util . * ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } static int minimumMoves ( int A [ ] , int N ) { int one = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( A [ i ] == 1 ) one ++ ; if ( one != 0 ) return N - one ; int minimum = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int g = A [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { g = __gcd ( A [ j ] , g ) ; if ( g == 1 ) { minimum = Math . min ( minimum , j - i ) ; break ; } } } if ( minimum == Integer . MAX_VALUE ) return - 1 ; else return N + minimum - 1 ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 4 , 3 , 9 } ; int N = A . length ; System . out . print ( minimumMoves ( A , N ) ) ; } }

def __gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return __gcd ( b % a , a ) NEW_LINE DEDENT def minimumMoves ( A , N ) : NEW_LINE INDENT one = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( A [ i ] == 1 ) : NEW_LINE INDENT one += 1 NEW_LINE DEDENT DEDENT if ( one != 0 ) : NEW_LINE INDENT return N - one NEW_LINE DEDENT minimum = + 2147483647 NEW_LINE for i in range ( N ) : NEW_LINE INDENT g = A [ i ] NEW_LINE for j in range ( i + 1 , N ) : NEW_LINE INDENT g = __gcd ( A [ j ] , g ) NEW_LINE if ( g == 1 ) : NEW_LINE INDENT minimum = min ( minimum , j - i ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT if ( minimum == + 2147483647 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return N + minimum - 1 ; NEW_LINE DEDENT DEDENT A = [ 2 , 4 , 3 , 9 ] NEW_LINE N = len ( A ) NEW_LINE print ( minimumMoves ( A , N ) ) NEW_LINE


class GFG { static int check_digits ( int n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 != 0 ) return 0 ; n /= 10 ; } return 1 ; } static int smallest_number ( int n ) { for ( int i = n ; ; i ++ ) if ( check_digits ( i ) != 0 ) return i ; } public static void main ( String [ ] args ) { int N = 2397 ; System . out . println ( smallest_number ( N ) ) ; } }

def check_digits ( n ) : NEW_LINE INDENT while ( n ) : NEW_LINE INDENT if ( ( n % 10 ) % 2 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT n = int ( n / 10 ) NEW_LINE DEDENT return 1 NEW_LINE DEDENT def smallest_number ( n ) : NEW_LINE INDENT for i in range ( n , 2401 ) : NEW_LINE INDENT if ( check_digits ( i ) == 1 ) : NEW_LINE INDENT return ( i ) NEW_LINE DEDENT DEDENT DEDENT N = 2397 NEW_LINE print ( str ( smallest_number ( N ) ) ) NEW_LINE


class GFG { static double mulmod ( long a , long b , long mod ) { long res = 0 ; a = a % mod ; while ( b > 0 ) { if ( b % 2 == 1 ) res = ( res + a ) % mod ; a = ( a * 2 ) % mod ; b /= 2 ; } return res % mod ; } static long findProduct ( long N ) { long product = 1 , fact = 1 ; long MOD = ( long ) ( 1e9 + 7 ) ; for ( int i = 1 ; i <= N ; i ++ ) { fact = ( long ) mulmod ( fact , i , MOD ) ; product = ( long ) mulmod ( product , fact , MOD ) ; if ( product == 0 ) return 0 ; } return product ; } public static void main ( String [ ] args ) { long N = 3 ; System . out . println ( findProduct ( N ) ) ; N = 5 ; System . out . println ( findProduct ( N ) ) ; } }

def mulmod ( a , b , mod ) : NEW_LINE INDENT res = 0 NEW_LINE a = a % mod NEW_LINE while ( b > 0 ) : NEW_LINE INDENT if ( b % 2 == 1 ) : NEW_LINE INDENT res = ( res + a ) % mod NEW_LINE DEDENT a = ( a * 2 ) % mod NEW_LINE b //= 2 NEW_LINE DEDENT return res % mod NEW_LINE DEDENT def findProduct ( N ) : NEW_LINE INDENT product = 1 ; fact = 1 NEW_LINE MOD = 1e9 + 7 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT fact = mulmod ( fact , i , MOD ) NEW_LINE product = mulmod ( product , fact , MOD ) NEW_LINE if not product : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT return int ( product ) NEW_LINE DEDENT N = 3 NEW_LINE print ( findProduct ( N ) ) NEW_LINE N = 5 NEW_LINE print ( findProduct ( N ) ) NEW_LINE


class GFG { static long binomialCoeff ( long n , long k ) { if ( k == 0 || k == n ) return 1 ; return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ; } static long fact ( long n ) { if ( n >= 1 ) return n * fact ( n - 1 ) ; else return 1 ; } static boolean isVowel ( char ch ) { if ( ch == ' a ' || ch == ' e ' || ch == ' i ' || ch == ' o ' || ch == ' u ' ) { return true ; } return false ; } static long countWords ( String s , int p , int q ) { long countc = 0 , countv = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( isVowel ( s . charAt ( i ) ) ) countv ++ ; else countc ++ ; } long a = binomialCoeff ( countc , p ) ; long b = binomialCoeff ( countv , q ) ; long c = fact ( p + q ) ; long ans = ( a * b ) * c ; return ans ; } public static void main ( String [ ] args ) { String s = " crackathon " ; int p = 4 , q = 3 ; System . out . println ( countWords ( s , p , q ) ) ; } }

def binomialCoeff ( n , k ) : NEW_LINE INDENT if ( k == 0 or k == n ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return binomialCoeff ( n - 1 , k - 1 ) +   \ NEW_LINE INDENT binomialCoeff ( n - 1 , k ) NEW_LINE DEDENT DEDENT def fact ( n ) : NEW_LINE INDENT if ( n >= 1 ) : NEW_LINE INDENT return n * fact ( n - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT return 1 NEW_LINE DEDENT DEDENT def isVowel ( ch ) : NEW_LINE INDENT if ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def countWords ( s , p , q ) : NEW_LINE INDENT countc = 0 NEW_LINE countv = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( isVowel ( s [ i ] ) ) : NEW_LINE INDENT countv += 1 NEW_LINE DEDENT else : NEW_LINE INDENT countc += 1 NEW_LINE DEDENT DEDENT a = binomialCoeff ( countc , p ) NEW_LINE b = binomialCoeff ( countv , q ) NEW_LINE c = fact ( p + q ) NEW_LINE ans = ( a * b ) * c NEW_LINE return ans NEW_LINE DEDENT s = " crackathon " NEW_LINE p = 4 NEW_LINE q = 3 NEW_LINE print ( countWords ( s , p , q ) ) NEW_LINE


import java . util . Arrays ; class GFG { static int minNumber ( int a [ ] , int n , int x ) { Arrays . sort ( a ) ; int k ; for ( k = 0 ; a [ ( n ) / 2 ] != x ; k ++ ) { a [ n ++ ] = x ; Arrays . sort ( a ) ; } return k ; } public static void main ( String [ ] args ) { int x = 10 ; int a [ ] = { 10 , 20 , 30 } ; int n = 3 ; System . out . println ( minNumber ( a , n - 1 , x ) ) ; } }

def minNumber ( a , n , x ) : NEW_LINE INDENT a . sort ( reverse = False ) NEW_LINE k = 0 NEW_LINE while ( a [ int ( ( n - 1 ) / 2 ) ] != x ) : NEW_LINE INDENT a [ n - 1 ] = x NEW_LINE n += 1 NEW_LINE a . sort ( reverse = False ) NEW_LINE k += 1 NEW_LINE DEDENT return k NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 10 NEW_LINE a = [ 10 , 20 , 30 ] NEW_LINE n = 3 NEW_LINE print ( minNumber ( a , n , x ) ) NEW_LINE DEDENT


class GFG { static int reverse ( int num ) { int rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num = num / 10 ; } return rev ; } static boolean isPalindrome ( int num ) { if ( num == reverse ( num ) ) return true ; return false ; } static void printPalindromes ( int d ) { if ( d <= 0 ) return ; int smallest = ( int ) Math . pow ( 10 , d - 1 ) ; int largest = ( int ) Math . pow ( 10 , d ) - 1 ; for ( int i = smallest ; i <= largest ; i ++ ) { if ( isPalindrome ( i ) ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int d = 2 ; printPalindromes ( d ) ; } }

def reverse ( num ) : NEW_LINE INDENT rev = 0 ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT rev = rev * 10 + num % 10 ; NEW_LINE num = num // 10 ; NEW_LINE DEDENT return rev ; NEW_LINE DEDENT def isPalindrome ( num ) : NEW_LINE INDENT if ( num == reverse ( num ) ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT def printPalindromes ( d ) : NEW_LINE INDENT if ( d <= 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT smallest = pow ( 10 , d - 1 ) ; NEW_LINE largest = pow ( 10 , d ) - 1 ; NEW_LINE for i in range ( smallest , largest + 1 ) : NEW_LINE INDENT if ( isPalindrome ( i ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT d = 2 ; NEW_LINE printPalindromes ( d ) ; NEW_LINE


import java . util . * ; class solution { static void Alphabet_N_Pattern ( int N ) { int index , side_index , size ; int Right = 1 , Left = 1 , Diagonal = 2 ; for ( index = 0 ; index < N ; index ++ ) { System . out . print ( Left ++ ) ; for ( side_index = 0 ; side_index < 2 * ( index ) ; side_index ++ ) System . out . print ( " ▁ " ) ; if ( index != 0 && index != N - 1 ) System . out . print ( Diagonal ++ ) ; else System . out . print ( " ▁ " ) ; for ( side_index = 0 ; side_index < 2 * ( N - index - 1 ) ; side_index ++ ) System . out . print ( " ▁ " ) ; System . out . print ( Right ++ ) ; System . out . println ( ) ; } } public static void main ( String args [ ] ) { int Size = 6 ; Alphabet_N_Pattern ( Size ) ; } }

def Alphabet_N_Pattern ( N ) : NEW_LINE INDENT Right = 1 NEW_LINE Left = 1 NEW_LINE Diagonal = 2 NEW_LINE for index in range ( N ) : NEW_LINE INDENT print ( Left , end = " " ) NEW_LINE Left += 1 NEW_LINE for side_index in range ( 0 , 2 * ( index ) , 1 ) : NEW_LINE INDENT print ( " ▁ " , end = " " ) NEW_LINE DEDENT if ( index != 0 and index != N - 1 ) : NEW_LINE INDENT print ( Diagonal , end = " " ) NEW_LINE Diagonal += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ▁ " , end = " " ) NEW_LINE DEDENT for side_index in range ( 0 , 2 * ( N - index - 1 ) , 1 ) : NEW_LINE INDENT print ( " ▁ " , end = " " ) NEW_LINE DEDENT print ( Right , end = " " ) NEW_LINE Right += 1 NEW_LINE print ( " \n " , end = " " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT Size = 6 NEW_LINE Alphabet_N_Pattern ( Size ) NEW_LINE DEDENT


import java . io . * ; import java . math . * ; class GFG { static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static int largestDigitSumdivisior ( int n ) { int res = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { res = Math . max ( res , getSum ( i ) ) ; res = Math . max ( res , getSum ( n / i ) ) ; } } return res ; } public static void main ( String args [ ] ) { int n = 14 ; System . out . println ( largestDigitSumdivisior ( n ) ) ; } }

import math NEW_LINE def getSum ( n ) : NEW_LINE INDENT sm = 0 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT sm = sm + n % 10 NEW_LINE n = n // 10 NEW_LINE DEDENT return sm NEW_LINE DEDENT def largestDigitSumdivisior ( n ) : NEW_LINE INDENT res = 0 NEW_LINE for i in range ( 1 , ( int ) ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT res = max ( res , getSum ( i ) ) NEW_LINE res = max ( res , getSum ( n // i ) ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT n = 14 NEW_LINE print ( largestDigitSumdivisior ( n ) ) NEW_LINE


class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int countNumbers ( int X , int Y , int N ) { int divisibleByX = N / X ; int divisibleByY = N / Y ; int LCM = ( X * Y ) / gcd ( X , Y ) ; int divisibleByLCM = N / LCM ; int divisibleByXorY = divisibleByX + divisibleByY - divisibleByLCM ; int divisibleByXnotY = divisibleByXorY - divisibleByY ; return divisibleByXnotY ; } public static void main ( String [ ] args ) { int X = 2 , Y = 3 , N = 10 ; System . out . println ( countNumbers ( X , Y , N ) ) ; } }

from math import gcd NEW_LINE def countNumbers ( X , Y , N ) : NEW_LINE INDENT divisibleByX = int ( N / X ) NEW_LINE divisibleByY = int ( N / Y ) NEW_LINE LCM = int ( ( X * Y ) / gcd ( X , Y ) ) NEW_LINE divisibleByLCM = int ( N / LCM ) NEW_LINE divisibleByXorY = ( divisibleByX + divisibleByY - divisibleByLCM ) NEW_LINE divisibleByXnotY = ( divisibleByXorY - divisibleByY ) NEW_LINE return divisibleByXnotY NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = 2 NEW_LINE Y = 3 NEW_LINE N = 10 NEW_LINE print ( countNumbers ( X , Y , N ) ) NEW_LINE DEDENT


import java . lang . * ; class GFG { public static boolean ispalindrome ( int x ) { int ans = 0 ; int temp = x ; while ( temp > 0 ) { ans = 10 * ans + temp % 10 ; temp = temp / 10 ; } return ans == x ; } public static int SuperPalindromes ( int L , int R ) { int LIMIT = 100000 ; int ans = 0 ; for ( int i = 0 ; i < LIMIT ; i ++ ) { String s = Integer . toString ( i ) ; StringBuilder rs = new StringBuilder ( ) ; rs . append ( s . substring ( 0 , Math . max ( 1 , s . length ( ) - 1 ) ) ) ; String srs = rs . reverse ( ) . toString ( ) ; String p = s + srs ; int p_sq = ( int ) ( Math . pow ( Integer . parseInt ( p ) , 2 ) ) ; if ( p_sq > R ) { break ; } if ( p_sq >= L && ispalindrome ( p_sq ) ) { ans = ans + 1 ; } } for ( int i = 0 ; i < LIMIT ; i ++ ) { String s = Integer . toString ( i ) ; StringBuilder rs = new StringBuilder ( ) ; rs . append ( s ) ; rs = rs . reverse ( ) ; String p = s + rs ; int p_sq = ( int ) ( Math . pow ( Integer . parseInt ( p ) , 2 ) ) ; if ( p_sq > R ) { break ; } if ( p_sq >= L && ispalindrome ( p_sq ) ) { ans = ans + 1 ; } } return ans ; } public static void main ( String [ ] args ) { String L = "4" ; String R = "1000" ; System . out . println ( SuperPalindromes ( Integer . parseInt ( L ) , Integer . parseInt ( R ) ) ) ; } }

def ispalindrome ( x ) : NEW_LINE INDENT ans , temp = 0 , x NEW_LINE while temp > 0 : NEW_LINE INDENT ans = 10 * ans + temp % 10 NEW_LINE temp = temp // 10 NEW_LINE DEDENT return ans == x NEW_LINE DEDENT def SuperPalindromes ( L , R ) : NEW_LINE INDENT L , R = int ( L ) , int ( R ) NEW_LINE LIMIT = 100000 NEW_LINE ans = 0 NEW_LINE for i in range ( LIMIT ) : NEW_LINE INDENT s = str ( i ) NEW_LINE p = s + s [ - 2 : : - 1 ] NEW_LINE p_sq = int ( p ) ** 2 NEW_LINE if p_sq > R : NEW_LINE INDENT break NEW_LINE DEDENT if p_sq >= L and ispalindrome ( p_sq ) : NEW_LINE INDENT ans = ans + 1 NEW_LINE DEDENT DEDENT for i in range ( LIMIT ) : NEW_LINE INDENT s = str ( i ) NEW_LINE p = s + s [ : : - 1 ] NEW_LINE p_sq = int ( p ) ** 2 NEW_LINE if p_sq > R : NEW_LINE INDENT break NEW_LINE DEDENT if p_sq >= L and ispalindrome ( p_sq ) : NEW_LINE INDENT ans = ans + 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT L = "4" NEW_LINE R = "1000" NEW_LINE print ( SuperPalindromes ( L , R ) ) NEW_LINE


import java . util . Arrays ; import java . util . Collections ; import java . util . List ; class GFG { static int getMax ( int [ ] A ) { int max = Integer . MIN_VALUE ; for ( int i : A ) { max = Math . max ( max , i ) ; } return max ; } static int calculateAND ( int arr [ ] , int n ) { int max_val = getMax ( arr ) ; boolean prime [ ] = new boolean [ max_val + 1 ] ; int i ; for ( i = 0 ; i < max_val + 1 ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int S1 = 0 , S2 = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { S1 += arr [ i ] ; } else if ( arr [ i ] != 1 ) { S2 += arr [ i ] ; } } return ( S1 & S2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 6 , 7 } ; int n = arr . length ; System . out . println ( calculateAND ( arr , n ) ) ; } }

def calculateAND ( arr , n ) : NEW_LINE INDENT max_val = max ( arr ) NEW_LINE prime = [ True for i in range ( max_val + 1 ) ] NEW_LINE prime [ 0 ] = False NEW_LINE prime [ 1 ] = False 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 ] ) : NEW_LINE INDENT for i in range ( 2 * p , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT S1 = 0 NEW_LINE S2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( prime [ arr [ i ] ] ) : NEW_LINE INDENT S1 += arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] != 1 ) : NEW_LINE INDENT S2 += arr [ i ] NEW_LINE DEDENT DEDENT return ( S1 & S2 ) NEW_LINE DEDENT arr = [ 3 , 4 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( calculateAND ( arr , n ) ) NEW_LINE


import java . io . * ; class GFG { static int circle ( int x1 , int y1 , int x2 , int y2 , int r1 , int r2 ) { int distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; int radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ; if ( distSq == radSumSq ) return 1 ; else if ( distSq > radSumSq ) return - 1 ; else return 0 ; } public static void main ( String [ ] args ) { int x1 = - 10 , y1 = 8 ; int x2 = 14 , y2 = - 24 ; int r1 = 30 , r2 = 10 ; int t = circle ( x1 , y1 , x2 , y2 , r1 , r2 ) ; if ( t == 1 ) System . out . println ( " Circle ▁ touch ▁ to " + " ▁ each ▁ other . " ) ; else if ( t < 0 ) System . out . println ( " Circle ▁ not ▁ touch " + " ▁ to ▁ each ▁ other . " ) ; else System . out . println ( " Circle ▁ intersect " + " ▁ to ▁ each ▁ other . " ) ; } }

def circle ( x1 , y1 , x2 , y2 , r1 , r2 ) : NEW_LINE INDENT distSq = ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ; NEW_LINE radSumSq = ( r1 + r2 ) * ( r1 + r2 ) ; NEW_LINE if ( distSq == radSumSq ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif ( distSq > radSumSq ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT x1 = - 10 NEW_LINE y1 = 8 NEW_LINE x2 = 14 NEW_LINE y2 = - 24 NEW_LINE r1 = 30 NEW_LINE r2 = 10 NEW_LINE t = circle ( x1 , y1 , x2 , y2 , r1 , r2 ) NEW_LINE if ( t == 1 ) : NEW_LINE INDENT print ( " Circle ▁ touch ▁ to ▁ each ▁ other . " ) NEW_LINE DEDENT elif ( t < 0 ) : NEW_LINE INDENT print ( " Circle ▁ not ▁ touch ▁ to ▁ each ▁ other . " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Circle ▁ intersect ▁ to ▁ each ▁ other . " ) NEW_LINE DEDENT


class GFG { static int findLength ( int [ ] arr , int n ) { int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) x = Math . max ( x , arr [ i ] ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != x ) continue ; int j = i ; while ( arr [ j ] == x ) { j ++ ; if ( j >= n ) break ; } ans = Math . max ( ans , j - i ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 } ; int n = arr . length ; System . out . println ( findLength ( arr , n ) ) ; } }

def findLength ( arr , n ) : NEW_LINE INDENT x = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = max ( x , arr [ i ] ) ; NEW_LINE DEDENT ans = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] != x ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT j = i ; NEW_LINE while ( arr [ j ] == x ) : NEW_LINE INDENT j += 1 ; NEW_LINE if j >= n : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT ans = max ( ans , j - i ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 2 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( findLength ( arr , n ) ) ; NEW_LINE DEDENT


class GFG { static int max ( int x , int y ) { return ( x > y ) ? x : y ; } static int lps ( char seq [ ] , int i , int j ) { if ( i == j ) { return 1 ; } if ( seq [ i ] == seq [ j ] && i + 1 == j ) { return 2 ; } if ( seq [ i ] == seq [ j ] ) { return lps ( seq , i + 1 , j - 1 ) + 2 ; } return max ( lps ( seq , i , j - 1 ) , lps ( seq , i + 1 , j ) ) ; } public static void main ( String [ ] args ) { String seq = " GEEKSFORGEEKS " ; int n = seq . length ( ) ; System . out . printf ( " The ▁ length ▁ of ▁ the ▁ LPS ▁ is ▁ % d " , lps ( seq . toCharArray ( ) , 0 , n - 1 ) ) ; } }

def max ( x , y ) : NEW_LINE INDENT if ( x > y ) : NEW_LINE INDENT return x NEW_LINE DEDENT return y NEW_LINE DEDENT def lps ( seq , i , j ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( seq [ i ] == seq [ j ] and i + 1 == j ) : NEW_LINE INDENT return 2 NEW_LINE DEDENT if ( seq [ i ] == seq [ j ] ) : NEW_LINE INDENT return lps ( seq , i + 1 , j - 1 ) + 2 NEW_LINE DEDENT return max ( lps ( seq , i , j - 1 ) , lps ( seq , i + 1 , j ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT seq = " GEEKSFORGEEKS " NEW_LINE n = len ( seq ) NEW_LINE print ( " The ▁ length ▁ of ▁ the ▁ LPS ▁ is " , lps ( seq , 0 , n - 1 ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static long doublefactorial ( long n ) { if ( n == 0 || n == 1 ) return 1 ; return n * doublefactorial ( n - 2 ) ; } static public void main ( String [ ] args ) { System . out . println ( " Double ▁ factorial " + " ▁ is ▁ " + doublefactorial ( 5 ) ) ; } }

def doublefactorial ( n ) : NEW_LINE INDENT if ( n == 0 or n == 1 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return n * doublefactorial ( n - 2 ) ; NEW_LINE DEDENT print ( " Double ▁ factorial ▁ is " , doublefactorial ( 5 ) ) ; NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static final int MAX = 10000 ; static int prefix [ ] = new int [ MAX + 1 ] ; static void buildPrefix ( ) { boolean prime [ ] = new boolean [ MAX + 1 ] ; for ( int i = 0 ; i < MAX + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( int p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] == true ) prefix [ p ] += p ; } } static int sumPrimeRange ( int L , int R ) { buildPrefix ( ) ; return prefix [ R ] - prefix [ L - 1 ] ; } public static void main ( String args [ ] ) { int L = 10 , R = 20 ; System . out . println ( sumPrimeRange ( L , R ) ) ; } }

from math import sqrt NEW_LINE MAX = 10000 NEW_LINE prefix = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE def buildPrefix ( ) : NEW_LINE INDENT prime = [ True for i in range ( MAX + 1 ) ] NEW_LINE for p in range ( 2 , int ( sqrt ( MAX ) ) + 1 , 1 ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , MAX + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT prefix [ 0 ] = 0 NEW_LINE prefix [ 1 ] = 0 NEW_LINE for p in range ( 2 , MAX + 1 , 1 ) : NEW_LINE INDENT prefix [ p ] = prefix [ p - 1 ] NEW_LINE if ( prime [ p ] ) : NEW_LINE INDENT prefix [ p ] += p NEW_LINE DEDENT DEDENT DEDENT def sumPrimeRange ( L , R ) : NEW_LINE INDENT buildPrefix ( ) NEW_LINE return prefix [ R ] - prefix [ L - 1 ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L = 10 NEW_LINE R = 20 NEW_LINE print ( sumPrimeRange ( L , R ) ) NEW_LINE DEDENT


public class GFG { static int nthTerm ( int n ) { return 3 * ( int ) Math . pow ( n , 2 ) - 4 * n + 2 ; } public static void main ( String args [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }

def nthTerm ( n ) : NEW_LINE INDENT return 3 * pow ( n , 2 ) - 4 * n + 2 NEW_LINE DEDENT N = 4 NEW_LINE print ( nthTerm ( N ) ) NEW_LINE


import java . util . * ; class GFG { static long subarrayXor ( int arr [ ] , int n , int m ) { long ans = 0 ; int [ ] xorArr = new int [ n ] ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; xorArr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) xorArr [ i ] = xorArr [ i - 1 ] ^ arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { int tmp = m ^ xorArr [ i ] ; ans = ans + ( mp . containsKey ( tmp ) == false ? 0 : ( ( long ) mp . get ( tmp ) ) ) ; if ( xorArr [ i ] == m ) ans ++ ; if ( mp . containsKey ( xorArr [ i ] ) ) mp . put ( xorArr [ i ] , mp . get ( xorArr [ i ] ) + 1 ) ; else mp . put ( xorArr [ i ] , 1 ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 2 , 6 , 4 } ; int n = arr . length ; int m = 6 ; System . out . print ( " Number ▁ of ▁ subarrays ▁ having ▁ given ▁ XOR ▁ is ▁ " + subarrayXor ( arr , n , m ) ) ; } }

def subarrayXor ( arr , n , m ) : NEW_LINE INDENT ans = 0 NEW_LINE xorArr = [ 0 for _ in range ( n ) ] NEW_LINE mp = dict ( ) NEW_LINE xorArr [ 0 ] = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT xorArr [ i ] = xorArr [ i - 1 ] ^ arr [ i ] NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT tmp = m ^ xorArr [ i ] NEW_LINE if tmp in mp . keys ( ) : NEW_LINE INDENT ans = ans + ( mp [ tmp ] ) NEW_LINE DEDENT if ( xorArr [ i ] == m ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT mp [ xorArr [ i ] ] = mp . get ( xorArr [ i ] , 0 ) + 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 4 , 2 , 2 , 6 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE m = 6 NEW_LINE print ( " Number ▁ of ▁ subarrays ▁ having ▁ given ▁ XOR ▁ is " , subarrayXor ( arr , n , m ) ) NEW_LINE


import java . io . * ; class GFG { static int minToggle ( int arr [ ] , int n ) { int zero [ ] = new int [ n + 1 ] ; zero [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { if ( arr [ i - 1 ] == 0 ) zero [ i ] = zero [ i - 1 ] + 1 ; else zero [ i ] = zero [ i - 1 ] ; } int ans = n ; for ( int i = 1 ; i <= n ; ++ i ) ans = Math . min ( ans , i - zero [ i ] + zero [ n ] - zero [ i ] ) ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 1 , 1 , 0 } ; int n = arr . length ; System . out . println ( minToggle ( arr , n ) ) ; } }

def minToggle ( arr , n ) : NEW_LINE INDENT zero = [ 0 for i in range ( n + 1 + 1 ) ] NEW_LINE zero [ 0 ] = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( arr [ i - 1 ] == 0 ) : NEW_LINE INDENT zero [ i ] = zero [ i - 1 ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT zero [ i ] = zero [ i - 1 ] NEW_LINE DEDENT DEDENT ans = n NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT ans = min ( ans , i - zero [ i ] + zero [ n ] - zero [ i ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT arr = [ 1 , 0 , 1 , 1 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minToggle ( arr , n ) ) NEW_LINE


class GFG { static float sqroot ( float s ) { int pSq = 0 ; int N = 0 ; for ( int i = ( int ) ( s ) ; i > 0 ; i -- ) { for ( int j = 1 ; j < i ; j ++ ) { if ( j * j == i ) { pSq = i ; N = j ; break ; } } if ( pSq > 0 ) break ; } float d = s - pSq ; float P = d / ( 2.0f * N ) ; float A = N + P ; float sqrt_of_s = A - ( ( P * P ) / ( 2.0f * A ) ) ; return sqrt_of_s ; } public static void main ( String [ ] args ) { float num = 9.2345f ; float sqroot_of_num = sqroot ( num ) ; System . out . print ( " Square ▁ root ▁ of ▁ " + num + " ▁ = ▁ " + Math . round ( sqroot_of_num * 100000.0 ) / 100000.0 ) ; } }

def sqroot ( s ) : NEW_LINE INDENT pSq = 0 ; NEW_LINE N = 0 ; NEW_LINE for i in range ( int ( s ) , 0 , - 1 ) : NEW_LINE INDENT for j in range ( 1 , i ) : NEW_LINE INDENT if ( j * j == i ) : NEW_LINE INDENT pSq = i ; NEW_LINE N = j ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( pSq > 0 ) : NEW_LINE INDENT break ; NEW_LINE DEDENT DEDENT d = s - pSq ; NEW_LINE P = d / ( 2.0 * N ) ; NEW_LINE A = N + P ; NEW_LINE sqrt_of_s = A - ( ( P * P ) / ( 2.0 * A ) ) ; NEW_LINE return sqrt_of_s ; NEW_LINE DEDENT num = 9.2345 ; NEW_LINE sqroot_of_num = sqroot ( num ) ; NEW_LINE print ( " Square ▁ root ▁ of ▁ " , num , " = " , round ( ( sqroot_of_num * 100000.0 ) / 100000.0 , 5 ) ) ; NEW_LINE


import java . util . * ; class GFG { static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = 0 ; r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } static boolean isPalindrome ( String r ) { String p = r ; p = reverse ( p ) ; return ( r . equals ( p ) ) ; } static boolean CheckStr ( String s ) { int l = s . length ( ) ; int i ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substring ( 0 , i ) ) ) { break ; } } if ( i == ( l + 1 ) ) { return false ; } i = 2 ; for ( i = 2 ; i <= l ; i ++ ) { if ( isPalindrome ( s . substring ( l - i , l ) ) ) { return true ; } } return false ; } public static void main ( String args [ ] ) { String s = " abccbarfgdbd " ; if ( CheckStr ( s ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

def isPalindrome ( r ) : NEW_LINE INDENT p = r [ : : - 1 ] NEW_LINE return r == p NEW_LINE DEDENT def CheckStr ( s ) : NEW_LINE INDENT l = len ( s ) NEW_LINE i = 0 NEW_LINE for i in range ( 2 , l + 1 ) : NEW_LINE INDENT if isPalindrome ( s [ 0 : i ] ) == True : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if i == ( l + 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , l + 1 ) : NEW_LINE INDENT if isPalindrome ( s [ l - i : l ] ) == True : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " abccbarfgdbd " NEW_LINE if CheckStr ( s ) == True : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


class GFG { static long cal_minimum_time ( long X ) { long t = 0 ; long sum = 0 ; while ( sum < X ) { t ++ ; sum = sum + t ; } return t ; } public static void main ( String [ ] args ) { long n = 6 ; long ans = cal_minimum_time ( n ) ; System . out . println ( " The ▁ minimum ▁ time ▁ required ▁ is ▁ : ▁ " + ans ) ; } }

def cal_minimum_time ( X ) : NEW_LINE INDENT t = 0 NEW_LINE sum = 0 NEW_LINE while ( sum < X ) : NEW_LINE INDENT t = t + 1 NEW_LINE sum = sum + t ; NEW_LINE DEDENT return t ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE ans = cal_minimum_time ( n ) NEW_LINE print ( " The ▁ minimum ▁ time ▁ required ▁ is ▁ : " , ans ) NEW_LINE DEDENT


class GFG { static int N = 1000000 ; static long phi [ ] = new long [ N + 5 ] ; static void computeTotient ( ) { for ( int i = 1 ; i <= N ; i ++ ) phi [ i ] = i ; for ( int p = 2 ; p <= N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( int i = 2 * p ; i <= N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } static long power ( 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 calculate ( long x , long k , long mod ) { long arr [ ] = new long [ N ] ; long count = 0 ; while ( mod > 1 ) { arr [ ( int ) count ++ ] = mod ; mod = phi [ ( int ) mod ] ; } long result = 1 ; long loop = count + 1 ; arr [ ( int ) count ] = 1 ; for ( int i = ( int ) Math . min ( k , loop ) - 1 ; i >= 0 ; i -- ) result = power ( x , result , arr [ i ] ) ; return result ; } public static void main ( String args [ ] ) { computeTotient ( ) ; long x = 3 , k = 2 , m = 3 ; System . out . println ( calculate ( x , k , m ) ) ; } }

N = 1000000 NEW_LINE phi = [ 0 for i in range ( N + 5 ) ] NEW_LINE def computeTotient ( ) : NEW_LINE INDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT phi [ i ] = i NEW_LINE DEDENT for p in range ( 2 , N + 1 ) : NEW_LINE INDENT if ( phi [ p ] == p ) : NEW_LINE INDENT phi [ p ] = p - 1 NEW_LINE for i in range ( 2 * p , N + 1 , p ) : NEW_LINE INDENT phi [ i ] = ( phi [ i ] // p ) * ( p - 1 ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def power ( 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 calculate ( x , k , mod ) : NEW_LINE INDENT arr = [ 0 for i in range ( N ) ] NEW_LINE count = 0 NEW_LINE while ( mod > 1 ) : NEW_LINE INDENT arr [ count ] = mod NEW_LINE count += 1 NEW_LINE mod = phi [ mod ] NEW_LINE DEDENT result = 1 NEW_LINE loop = count + 1 NEW_LINE arr [ count ] = 1 NEW_LINE for i in range ( min ( k , loop ) , - 1 , - 1 ) : NEW_LINE INDENT result = power ( x , result , arr [ i ] ) NEW_LINE DEDENT return result NEW_LINE DEDENT computeTotient ( ) NEW_LINE x = 3 NEW_LINE k = 2 NEW_LINE m = 3 NEW_LINE print ( calculate ( x , k , m ) ) NEW_LINE


class GFG { static int nthOdd ( int n ) { return ( 2 * n - 1 ) ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( nthOdd ( n ) ) ; } }

def nthOdd ( n ) : NEW_LINE INDENT return ( 2 * n - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 NEW_LINE print ( nthOdd ( n ) ) NEW_LINE DEDENT


class GFG { static class Node { int data ; Node next ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . next = null ; return temp ; } static void printList ( Node node ) { while ( node != null ) { System . out . print ( node . data + " ▁ " ) ; node = node . next ; } } static void replaceNodes ( Node head ) { Node p = head ; Node x = null ; int count = 0 ; int i ; while ( p != null ) { count = 0 ; i = 0 ; x = p ; while ( x != null ) { if ( x . data > p . data ) count ++ ; x = x . next ; } p . data = count ; p = p . next ; } } public static void main ( String [ ] args ) { Node head = newNode ( 10 ) ; head . next = newNode ( 12 ) ; head . next . next = newNode ( 5 ) ; head . next . next . next = newNode ( 40 ) ; head . next . next . next . next = newNode ( 21 ) ; head . next . next . next . next . next = newNode ( 70 ) ; head . next . next . next . next . next . next = newNode ( 1 ) ; head . next . next . next . next . next . next . next = newNode ( 49 ) ; head . next . next . next . next . next . next . next . next = newNode ( 37 ) ; replaceNodes ( head ) ; printList ( head ) ; } }

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 printList ( node ) : NEW_LINE INDENT while node != None : NEW_LINE INDENT print ( node . data , end = " ▁ " ) NEW_LINE node = node . next NEW_LINE DEDENT DEDENT def replaceNodes ( head ) : NEW_LINE INDENT p = head NEW_LINE x = None NEW_LINE count = 0 NEW_LINE while p != None : NEW_LINE INDENT count = 0 NEW_LINE x = p NEW_LINE while x != None : NEW_LINE INDENT if x . data > p . data : NEW_LINE INDENT count += 1 NEW_LINE DEDENT x = x . next NEW_LINE DEDENT p . data = count NEW_LINE p = p . next NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT head = Node ( 10 ) NEW_LINE head . next = Node ( 12 ) NEW_LINE head . next . next = Node ( 5 ) NEW_LINE head . next . next . next = Node ( 40 ) NEW_LINE head . next . next . next . next = Node ( 21 ) NEW_LINE head . next . next . next . next . next = Node ( 70 ) NEW_LINE head . next . next . next . next . next . next = Node ( 1 ) NEW_LINE head . next . next . next . next . next . next . next = Node ( 49 ) NEW_LINE head . next . next . next . next . next . next . next . next = Node ( 37 ) NEW_LINE replaceNodes ( head ) NEW_LINE printList ( head ) NEW_LINE DEDENT


import java . util . * ; class GFG { static String longestRepeatedSubSeq ( String str ) { int n = str . length ( ) ; int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; String res = " " ; int i = n , j = n ; while ( i > 0 && j > 0 ) { if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) { res = res + str . charAt ( i - 1 ) ; i -- ; j -- ; } else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ; else j -- ; } String reverse = " " ; for ( int k = res . length ( ) - 1 ; k >= 0 ; k -- ) { reverse = reverse + res . charAt ( k ) ; } return reverse ; } public static void main ( String args [ ] ) { String str = " AABEBCDD " ; System . out . println ( longestRepeatedSubSeq ( str ) ) ; } }

def longestRepeatedSubSeq ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( str [ i - 1 ] == str [ j - 1 ] and i != j ) : NEW_LINE INDENT dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] = max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT res = ' ' NEW_LINE i = n NEW_LINE j = n NEW_LINE while ( i > 0 and j > 0 ) : NEW_LINE INDENT if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) : NEW_LINE INDENT res += str [ i - 1 ] NEW_LINE i -= 1 NEW_LINE j -= 1 NEW_LINE DEDENT elif ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT DEDENT res = ' ' . join ( reversed ( res ) ) NEW_LINE return res NEW_LINE DEDENT str = ' AABEBCDD ' NEW_LINE print ( longestRepeatedSubSeq ( str ) ) NEW_LINE


import java . util . * ; class GFG { static float y ( float x ) { float num = 1 ; float denom = ( float ) 1.0 + x * x ; return num / denom ; } static float WeedleRule ( float a , float b ) { float h = ( b - a ) / 6 ; float sum = 0 ; sum = sum + ( ( ( 3 * h ) / 10 ) * ( y ( a ) + y ( a + 2 * h ) + 5 * y ( a + h ) + 6 * y ( a + 3 * h ) + y ( a + 4 * h ) + 5 * y ( a + 5 * h ) + y ( a + 6 * h ) ) ) ; return sum ; } public static void main ( String args [ ] ) { float a = 0 , b = 6 ; float num = WeedleRule ( a , b ) ; System . out . format ( " f ( x ) ▁ = ▁ " + " % .6f " , num ) ; } }

def y ( x ) : NEW_LINE INDENT num = 1 ; NEW_LINE denom = float ( 1.0 + x * x ) ; NEW_LINE return num / denom ; NEW_LINE DEDENT def WeedleRule ( a , b ) : NEW_LINE INDENT h = ( b - a ) / 6 ; NEW_LINE sum = 0 ; NEW_LINE sum = sum + ( ( ( 3 * h ) / 10 ) * ( y ( a ) + y ( a + 2 * h ) + 5 * y ( a + h ) + 6 * y ( a + 3 * h ) + y ( a + 4 * h ) + 5 * y ( a + 5 * h ) + y ( a + 6 * h ) ) ) ; NEW_LINE return sum ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 0 ; NEW_LINE b = 6 ; NEW_LINE num = WeedleRule ( a , b ) ; NEW_LINE print ( " f ( x ) ▁ = ▁ { 0 : . 6f } " . format ( num ) ) ; NEW_LINE DEDENT


import java . util . * ; class solution { static int findSum ( int N ) { return ( 2 * N * ( N + 1 ) * ( 4 * N + 17 ) + 54 * N ) / 6 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( findSum ( N ) ) ; } }

def findSum ( N ) : NEW_LINE INDENT return ( 2 * N * ( N + 1 ) * ( 4 * N + 17 ) + 54 * N ) / 6 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 NEW_LINE print ( findSum ( N ) ) NEW_LINE DEDENT


class GFG { static int maxN = 20 ; static int maxM = 64 ; static int [ ] [ ] dp = new int [ maxN ] [ maxM ] ; static boolean [ ] [ ] v = new boolean [ maxN ] [ maxM ] ; static int findLen ( int [ ] arr , int i , int curr , int n , int m ) { if ( i == n ) { if ( curr == m ) return 0 ; else return - 1 ; } if ( v [ i ] [ curr ] ) return dp [ i ] [ curr ] ; v [ i ] [ curr ] = true ; int l = findLen ( arr , i + 1 , curr , n , m ) ; int r = findLen ( arr , i + 1 , curr | arr [ i ] , n , m ) ; dp [ i ] [ curr ] = l ; if ( r != - 1 ) dp [ i ] [ curr ] = Math . max ( dp [ i ] [ curr ] , r + 1 ) ; return dp [ i ] [ curr ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 7 , 2 , 3 } ; int n = arr . length ; int m = 3 ; int ans = findLen ( arr , 0 , 0 , n , m ) ; if ( ans == - 1 ) System . out . println ( 0 ) ; else System . out . println ( ans ) ; } }

import numpy as np NEW_LINE maxN = 20 NEW_LINE maxM = 64 NEW_LINE dp = np . zeros ( ( maxN , maxM ) ) ; NEW_LINE v = np . zeros ( ( maxN , maxM ) ) ; NEW_LINE def findLen ( arr , i , curr , n , m ) : NEW_LINE INDENT if ( i == n ) : NEW_LINE INDENT if ( curr == m ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT DEDENT if ( v [ i ] [ curr ] ) : NEW_LINE INDENT return dp [ i ] [ curr ] ; NEW_LINE DEDENT v [ i ] [ curr ] = 1 ; NEW_LINE l = findLen ( arr , i + 1 , curr , n , m ) ; NEW_LINE r = findLen ( arr , i + 1 , curr | arr [ i ] , n , m ) ; NEW_LINE dp [ i ] [ curr ] = l ; NEW_LINE if ( r != - 1 ) : NEW_LINE INDENT dp [ i ] [ curr ] = max ( dp [ i ] [ curr ] , r + 1 ) ; NEW_LINE DEDENT return dp [ i ] [ curr ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 3 , 7 , 2 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE m = 3 ; NEW_LINE ans = findLen ( arr , 0 , 0 , n , m ) ; NEW_LINE if ( ans == - 1 ) : NEW_LINE INDENT print ( 0 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( ans ) ; NEW_LINE DEDENT DEDENT


import java . util . Arrays ; public class GFG { static final int MAX_CHARS = 256 ; static String findSubString ( String str ) { int n = str . length ( ) ; int dist_count = 0 ; boolean [ ] visited = new boolean [ MAX_CHARS ] ; Arrays . fill ( visited , false ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( visited [ str . charAt ( i ) ] == false ) { visited [ str . charAt ( i ) ] = true ; dist_count ++ ; } } int start = 0 , start_index = - 1 ; int min_len = Integer . MAX_VALUE ; int count = 0 ; int [ ] curr_count = new int [ MAX_CHARS ] ; for ( int j = 0 ; j < n ; j ++ ) { curr_count [ str . charAt ( j ) ] ++ ; if ( curr_count [ str . charAt ( j ) ] == 1 ) count ++ ; if ( count == dist_count ) { while ( curr_count [ str . charAt ( start ) ] > 1 ) { if ( curr_count [ str . charAt ( start ) ] > 1 ) curr_count [ str . charAt ( start ) ] -- ; start ++ ; } int len_window = j - start + 1 ; if ( min_len > len_window ) { min_len = len_window ; start_index = start ; } } } return str . substring ( start_index , start_index + min_len ) ; } public static void main ( String args [ ] ) { String str = " aabcbcdbca " ; System . out . println ( " Smallest ▁ window ▁ containing ▁ all ▁ distinct " + " ▁ characters ▁ is : ▁ " + findSubString ( str ) ) ; } }

from collections import defaultdict NEW_LINE MAX_CHARS = 256 NEW_LINE def findSubString ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE dist_count = len ( set ( [ x for x in str ] ) ) NEW_LINE curr_count = defaultdict ( lambda : 0 ) NEW_LINE for j in range ( n ) : NEW_LINE INDENT curr_count [ str [ j ] ] += 1 NEW_LINE if curr_count [ str [ j ] ] == 1 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT if count == dist_count : NEW_LINE INDENT while curr_count [ str [ start ] ] > 1 : NEW_LINE INDENT if curr_count [ str [ start ] ] > 1 : NEW_LINE INDENT curr_count [ str [ start ] ] -= 1 NEW_LINE DEDENT start += 1 NEW_LINE DEDENT len_window = j - start + 1 NEW_LINE if min_len > len_window : NEW_LINE INDENT min_len = len_window NEW_LINE start_index = start NEW_LINE DEDENT DEDENT DEDENT return str [ start_index : start_index + min_len ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( " Smallest ▁ window ▁ containing ▁ all ▁ distinct ▁ characters ▁ is : ▁ { } " . format ( findSubString ( " aabcbcdbca " ) ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int findNumber ( int n ) { n -- ; int i = 1 ; while ( n >= 0 ) { n -= i ; ++ i ; } return ( n + i ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( findNumber ( n ) ) ; } }

def findNumber ( n ) : NEW_LINE INDENT n -= 1 NEW_LINE i = 1 NEW_LINE while n >= 0 : NEW_LINE INDENT n -= i NEW_LINE i += 1 NEW_LINE DEDENT return ( n + i ) NEW_LINE DEDENT n = 3 NEW_LINE print ( findNumber ( n ) ) NEW_LINE


class GFG { static int FindSubarray ( int arr [ ] , int n , int k ) { int [ ] count_one = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { count_one [ i ] = Integer . bitCount ( arr [ i ] ) ; } int sum = count_one [ 0 ] ; if ( n == 1 ) { if ( count_one [ 0 ] >= k ) return 1 ; else return - 1 ; } int ans = Integer . MAX_VALUE ; int i = 1 ; int j = 0 ; while ( i < n ) { if ( k == count_one [ j ] ) { ans = 1 ; break ; } else if ( k == count_one [ i ] ) { ans = 1 ; break ; } else if ( sum + count_one [ i ] < k ) { sum += count_one [ i ] ; i ++ ; } else if ( sum + count_one [ i ] > k ) { ans = Math . min ( ans , ( i - j ) + 1 ) ; sum -= count_one [ j ] ; j ++ ; } else if ( sum + count_one [ i ] == k ) { ans = Math . min ( ans , ( i - j ) + 1 ) ; sum += count_one [ i ] ; i ++ ; } } if ( ans != Integer . MAX_VALUE ) return ans ; else return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 8 } ; int n = arr . length ; int k = 2 ; System . out . println ( FindSubarray ( arr , n , k ) ) ; } }

import sys ; NEW_LINE def FindSubarray ( arr , n , k ) : NEW_LINE INDENT count_one = [ 0 ] * n ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT count_one [ i ] = bin ( arr [ i ] ) . count ( '1' ) ; NEW_LINE DEDENT sum = count_one [ 0 ] ; NEW_LINE if ( n == 1 ) : NEW_LINE INDENT if ( count_one [ 0 ] >= k ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT DEDENT ans = sys . maxsize ; NEW_LINE i = 1 ; NEW_LINE j = 0 ; NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( k == count_one [ j ] ) : NEW_LINE INDENT ans = 1 ; NEW_LINE break ; NEW_LINE DEDENT elif ( k == count_one [ i ] ) : NEW_LINE INDENT ans = 1 ; NEW_LINE break ; NEW_LINE DEDENT elif ( sum + count_one [ i ] < k ) : NEW_LINE INDENT sum += count_one [ i ] ; NEW_LINE i += 1 ; NEW_LINE DEDENT elif ( sum + count_one [ i ] > k ) : NEW_LINE INDENT ans = min ( ans , ( i - j ) + 1 ) ; NEW_LINE sum -= count_one [ j ] ; NEW_LINE j += 1 ; NEW_LINE DEDENT elif ( sum + count_one [ i ] == k ) : NEW_LINE INDENT ans = min ( ans , ( i - j ) + 1 ) ; NEW_LINE sum += count_one [ i ] ; NEW_LINE i += 1 ; NEW_LINE DEDENT DEDENT if ( ans != sys . maxsize ) : NEW_LINE INDENT return ans ; NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 4 , 8 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE k = 2 ; NEW_LINE print ( FindSubarray ( arr , n , k ) ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int divSum ( int n ) { int result = 0 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + 1 ) ; } static boolean areAmicable ( int x , int y ) { if ( divSum ( x ) != y ) return false ; return ( divSum ( y ) == x ) ; } public static void main ( String [ ] args ) { int x = 220 , y = 284 ; if ( areAmicable ( x , y ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

import math NEW_LINE def divSum ( n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( i == int ( n / i ) ) : NEW_LINE INDENT result = result + i NEW_LINE DEDENT else : NEW_LINE INDENT result = result + NEW_LINE INDENT ( i + int ( n / i ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT return ( result + 1 ) NEW_LINE DEDENT def areAmicable ( x , y ) : NEW_LINE INDENT if ( divSum ( x ) != y ) : NEW_LINE INDENT return False NEW_LINE DEDENT return ( divSum ( y ) == x ) NEW_LINE DEDENT x = 220 NEW_LINE y = 284 NEW_LINE if ( areAmicable ( x , y ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class GFG { static int minimumDeletions ( int a [ ] , int n ) { if ( n <= 2 ) return 0 ; int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( ( a [ i ] < a [ i + 1 ] && a [ i + 1 ] < a [ i + 2 ] ) || ( a [ i ] > a [ i + 1 ] && a [ i + 1 ] > a [ i + 2 ] ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 2 , 3 , 6 , 1 } ; int n = a . length ; System . out . println ( minimumDeletions ( a , n ) ) ; } }

def minimumDeletions ( a , n ) : NEW_LINE INDENT if ( n <= 2 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( n - 2 ) : NEW_LINE INDENT if ( ( a [ i ] < a [ i + 1 ] and a [ i + 1 ] < a [ i + 2 ] ) or ( a [ i ] > a [ i + 1 ] and a [ i + 1 ] > a [ i + 2 ] ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT a = [ 5 , 2 , 3 , 6 , 1 ] NEW_LINE n = len ( a ) NEW_LINE print ( minimumDeletions ( a , n ) ) NEW_LINE


import java . util . Arrays ; public class GFG { static final int MAX_CHAR = 256 ; static void printDistinct ( String str ) { int n = str . length ( ) ; int [ ] count = new int [ MAX_CHAR ] ; int [ ] index = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { count [ i ] = 0 ; index [ i ] = n ; } for ( int i = 0 ; i < n ; i ++ ) { char x = str . charAt ( i ) ; ++ count [ x ] ; if ( count [ x ] == 1 && x != ' ▁ ' ) index [ x ] = i ; if ( count [ x ] == 2 ) index [ x ] = n ; } Arrays . sort ( index ) ; for ( int i = 0 ; i < MAX_CHAR && index [ i ] != n ; i ++ ) System . out . print ( str . charAt ( index [ i ] ) ) ; } public static void main ( String args [ ] ) { String str = " GeeksforGeeks " ; printDistinct ( str ) ; } }

MAX_CHAR = 256 NEW_LINE def printDistinct ( Str ) : NEW_LINE INDENT n = len ( Str ) NEW_LINE count = [ 0 for i in range ( MAX_CHAR ) ] NEW_LINE index = [ n for i in range ( MAX_CHAR ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = ord ( Str [ i ] ) NEW_LINE count [ x ] += 1 NEW_LINE if ( count [ x ] == 1 and x != ' ▁ ' ) : NEW_LINE INDENT index [ x ] = i NEW_LINE DEDENT if ( count [ x ] == 2 ) : NEW_LINE INDENT index [ x ] = n NEW_LINE DEDENT DEDENT index = sorted ( index ) NEW_LINE for i in range ( MAX_CHAR ) : NEW_LINE INDENT if index [ i ] == n : NEW_LINE INDENT break NEW_LINE DEDENT print ( Str [ index [ i ] ] , end = " " ) NEW_LINE DEDENT DEDENT Str = " GeeksforGeeks " NEW_LINE printDistinct ( Str ) NEW_LINE


import java . util . * ; class Count { public static int count4Divisibiles ( int arr [ ] , int n ) { int freq [ ] = { 0 , 0 , 0 , 0 } ; int i = 0 ; int ans ; for ( i = 0 ; i < n ; i ++ ) ++ freq [ arr [ i ] % 4 ] ; ans = freq [ 0 ] * ( freq [ 0 ] - 1 ) / 2 ; ans += freq [ 2 ] * ( freq [ 2 ] - 1 ) / 2 ; ans += freq [ 1 ] * freq [ 3 ] ; return ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 7 , 5 } ; int n = 5 ; System . out . print ( count4Divisibiles ( arr , n ) ) ; } }

def count4Divisibiles ( arr , n ) : NEW_LINE INDENT freq = [ 0 , 0 , 0 , 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ arr [ i ] % 4 ] += 1 NEW_LINE DEDENT ans = freq [ 0 ] * ( freq [ 0 ] - 1 ) / 2 NEW_LINE ans += freq [ 2 ] * ( freq [ 2 ] - 1 ) / 2 NEW_LINE ans += freq [ 1 ] * freq [ 3 ] NEW_LINE return int ( ans ) NEW_LINE DEDENT arr = [ 2 , 2 , 1 , 7 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( count4Divisibiles ( arr , n ) ) NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static int cola = 2 , rowa = 3 , colb = 3 , rowb = 2 ; static void Kroneckerproduct ( int A [ ] [ ] , int B [ ] [ ] ) { int [ ] [ ] C = new int [ rowa * rowb ] [ cola * colb ] ; for ( int i = 0 ; i < rowa ; i ++ ) { for ( int k = 0 ; k < rowb ; k ++ ) { for ( int j = 0 ; j < cola ; j ++ ) { for ( int l = 0 ; l < colb ; l ++ ) { C [ i + l + 1 ] [ j + k + 1 ] = A [ i ] [ j ] * B [ k ] [ l ] ; System . out . print ( C [ i + l + 1 ] [ j + k + 1 ] + " ▁ " ) ; } } System . out . println ( ) ; } } } public static void main ( String [ ] args ) { int A [ ] [ ] = { { 1 , 2 } , { 3 , 4 } , { 1 , 0 } } ; int B [ ] [ ] = { { 0 , 5 , 2 } , { 6 , 7 , 3 } } ; Kroneckerproduct ( A , B ) ; } }

cola = 2 NEW_LINE rowa = 3 NEW_LINE colb = 3 NEW_LINE rowb = 2 NEW_LINE def Kroneckerproduct ( A , B ) : NEW_LINE INDENT C = [ [ 0 for j in range ( cola * colb ) ] for i in range ( rowa * rowb ) ] NEW_LINE for i in range ( 0 , rowa ) : NEW_LINE INDENT for k in range ( 0 , rowb ) : NEW_LINE INDENT for j in range ( 0 , cola ) : NEW_LINE INDENT for l in range ( 0 , colb ) : NEW_LINE INDENT C [ i + l + 1 ] [ j + k + 1 ] = A [ i ] [ j ] * B [ k ] [ l ] NEW_LINE print ( C [ i + l + 1 ] [ j + k + 1 ] , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT print ( " \n " ) NEW_LINE DEDENT DEDENT DEDENT A = [ [ 0 for j in range ( 2 ) ] for i in range ( 3 ) ] NEW_LINE B = [ [ 0 for j in range ( 3 ) ] for i in range ( 2 ) ] NEW_LINE A [ 0 ] [ 0 ] = 1 NEW_LINE A [ 0 ] [ 1 ] = 2 NEW_LINE A [ 1 ] [ 0 ] = 3 NEW_LINE A [ 1 ] [ 1 ] = 4 NEW_LINE A [ 2 ] [ 0 ] = 1 NEW_LINE A [ 2 ] [ 1 ] = 0 NEW_LINE B [ 0 ] [ 0 ] = 0 NEW_LINE B [ 0 ] [ 1 ] = 5 NEW_LINE B [ 0 ] [ 2 ] = 2 NEW_LINE B [ 1 ] [ 0 ] = 6 NEW_LINE B [ 1 ] [ 1 ] = 7 NEW_LINE B [ 1 ] [ 2 ] = 3 NEW_LINE Kroneckerproduct ( A , B ) NEW_LINE


import java . util . Arrays ; public class GFG { static int maxPrimefactorNum ( int N ) { int arr [ ] = new int [ N + 5 ] ; Arrays . fill ( arr , 0 ) ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( arr [ i ] == 0 ) { for ( int j = 2 * i ; j <= N ; j += i ) { arr [ j ] ++ ; } } arr [ i ] = 1 ; } int maxval = 0 , maxint = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( arr [ i ] > maxval ) { maxval = arr [ i ] ; maxint = i ; } } return maxint ; } public static void main ( String [ ] args ) { int N = 40 ; System . out . println ( maxPrimefactorNum ( N ) ) ; } }

from math import sqrt NEW_LINE def maxPrimefactorNum ( N ) : NEW_LINE INDENT arr = [ 0 for i in range ( N + 5 ) ] NEW_LINE for i in range ( 2 , int ( sqrt ( N ) ) + 1 , 1 ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT for j in range ( 2 * i , N + 1 , i ) : NEW_LINE INDENT arr [ j ] += 1 NEW_LINE DEDENT DEDENT arr [ i ] = 1 NEW_LINE DEDENT maxval = 0 NEW_LINE maxint = 1 NEW_LINE for i in range ( 1 , N + 1 , 1 ) : NEW_LINE INDENT if ( arr [ i ] > maxval ) : NEW_LINE INDENT maxval = arr [ i ] NEW_LINE maxint = i NEW_LINE DEDENT DEDENT return maxint NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 40 NEW_LINE print ( maxPrimefactorNum ( N ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int maxSquareSubsetSum ( int [ ] A , int N ) { int sub1 = 0 , sub2 = 0 ; Arrays . sort ( A ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( i < ( N / 2 ) - 1 ) sub1 += A [ i ] ; else sub2 += A [ i ] ; } return sub1 * sub1 + sub2 * sub2 ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 2 , 13 , 4 , 25 , 8 } ; int N = arr . length ; System . out . println ( maxSquareSubsetSum ( arr , N ) ) ; } }

def maxSquareSubsetSum ( A , N ) : NEW_LINE INDENT sub1 = 0 ; sub2 = 0 ; NEW_LINE A . sort ( ) ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( i < ( N // 2 ) - 1 ) : NEW_LINE INDENT sub1 += A [ i ] ; NEW_LINE DEDENT else : NEW_LINE INDENT sub2 += A [ i ] ; NEW_LINE DEDENT DEDENT return sub1 * sub1 + sub2 * sub2 ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 7 , 2 , 13 , 4 , 25 , 8 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE print ( maxSquareSubsetSum ( arr , N ) ) ; NEW_LINE DEDENT


class GFG { static int findMinimumK ( int a [ ] , int n , int s ) { int maximum = a [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) { maximum = Math . max ( maximum , a [ i ] ) ; } int low = 1 , high = maximum + 1 ; int ans = high ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += ( int ) ( a [ i ] / mid ) ; } if ( sum > s ) low = mid + 1 ; else { ans = Math . min ( ans , mid ) ; high = mid - 1 ; } } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { 10 , 7 , 8 , 10 , 12 , 19 } ; int n = a . length ; int s = 27 ; System . out . println ( findMinimumK ( a , n , s ) ) ; } }

def findMinimumK ( a , n , s ) : NEW_LINE INDENT maximum = a [ 0 ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT maximum = max ( maximum , a [ i ] ) NEW_LINE DEDENT low = 1 NEW_LINE high = maximum + 1 NEW_LINE ans = high NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += ( a [ i ] // mid ) NEW_LINE DEDENT if ( sum > s ) : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans = min ( ans , mid ) NEW_LINE high = mid - 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT a = [ 10 , 7 , 8 , 10 , 12 , 19 ] NEW_LINE n = len ( a ) NEW_LINE s = 27 NEW_LINE print ( findMinimumK ( a , n , s ) ) NEW_LINE


public class GFG { static int countX ( int n ) { int count = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { if ( n - i == ( n ^ i ) ) count ++ ; } return count ; } public static void main ( String args [ ] ) { int n = 5 ; int answer = countX ( n ) ; System . out . println ( answer ) ; } }

import math as mt NEW_LINE def countX ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT if n - i == ( n ^ i ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE answer = countX ( n ) NEW_LINE print ( answer ) NEW_LINE DEDENT


class GFG { static String largestSubStr ( String s ) { while ( s . length ( ) != 0 && s . charAt ( s . length ( ) - 1 ) == '1' ) s = s . substring ( 0 , s . length ( ) - 1 ) ; if ( s . length ( ) == 0 ) return " - 1" ; else return s ; } public static void main ( String [ ] args ) { String s = "11001" ; System . out . println ( largestSubStr ( s ) ) ; } }

def largestSubStr ( s ) : NEW_LINE INDENT while ( len ( s ) and s [ len ( s ) - 1 ] == '1' ) : NEW_LINE INDENT s = s [ : len ( s ) - 1 ] ; NEW_LINE DEDENT if ( len ( s ) == 0 ) : NEW_LINE INDENT return " - 1" ; NEW_LINE DEDENT else : NEW_LINE INDENT return s ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "11001" ; NEW_LINE print ( largestSubStr ( s ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static class primeFactorization { int countOfPf , primeFactor ; public primeFactorization ( int countOfPf , int primeFactor ) { this . countOfPf = countOfPf ; this . primeFactor = primeFactor ; } } static void generateDivisors ( int curIndex , int curDivisor , Vector < primeFactorization > arr ) { if ( curIndex == arr . size ( ) ) { System . out . print ( curDivisor + " ▁ " ) ; return ; } for ( int i = 0 ; i <= arr . get ( curIndex ) . countOfPf ; ++ i ) { generateDivisors ( curIndex + 1 , curDivisor , arr ) ; curDivisor *= arr . get ( curIndex ) . primeFactor ; } } static void findDivisors ( int n ) { Vector < primeFactorization > arr = new Vector < > ( ) ; for ( int i = 2 ; i * i <= n ; ++ i ) { if ( n % i == 0 ) { int count = 0 ; while ( n % i == 0 ) { n /= i ; count += 1 ; } arr . add ( new primeFactorization ( count , i ) ) ; } } if ( n > 1 ) { arr . add ( new primeFactorization ( 1 , n ) ) ; } int curIndex = 0 , curDivisor = 1 ; generateDivisors ( curIndex , curDivisor , arr ) ; } public static void main ( String [ ] args ) { int n = 6 ; findDivisors ( n ) ; } }

def generateDivisors ( curIndex , curDivisor , arr ) : NEW_LINE INDENT if ( curIndex == len ( arr ) ) : NEW_LINE INDENT print ( curDivisor , end = ' ▁ ' ) NEW_LINE return NEW_LINE DEDENT for i in range ( arr [ curIndex ] [ 0 ] + 1 ) : NEW_LINE INDENT generateDivisors ( curIndex + 1 , curDivisor , arr ) NEW_LINE curDivisor *= arr [ curIndex ] [ 1 ] NEW_LINE DEDENT DEDENT def findDivisors ( n ) : NEW_LINE INDENT arr = [ ] NEW_LINE i = 2 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n % i == 0 ) : NEW_LINE INDENT n //= i NEW_LINE count += 1 NEW_LINE DEDENT arr . append ( [ count , i ] ) NEW_LINE DEDENT DEDENT if ( n > 1 ) : NEW_LINE INDENT arr . append ( [ 1 , n ] ) NEW_LINE DEDENT curIndex = 0 NEW_LINE curDivisor = 1 NEW_LINE generateDivisors ( curIndex , curDivisor , arr ) NEW_LINE DEDENT n = 6 NEW_LINE findDivisors ( n ) NEW_LINE


import java . util . * ; class GFG { static double countdigits ( int n , int k ) { if ( n == 0 ) return 0 ; int digit = n % 10 ; if ( digit == k ) return 1 + countdigits ( n / 10 , k ) ; return countdigits ( n / 10 , k ) ; } public static void main ( String [ ] args ) { int n = 1000 ; int k = 0 ; System . out . println ( countdigits ( n , k ) ) ; } }

def countdigits ( n , k ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT digit = n % 10 NEW_LINE if digit == k : NEW_LINE INDENT return 1 + countdigits ( n / 10 , k ) NEW_LINE DEDENT return countdigits ( n / 10 , k ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1000 ; NEW_LINE k = 0 ; NEW_LINE print ( countdigits ( n , k ) ) NEW_LINE DEDENT


class GfG { static void printPalindrome ( int n ) { if ( n == 1 ) { System . out . println ( " Smallest ▁ Palindrome : ▁ 0" ) ; System . out . println ( " Largest ▁ Palindrome : ▁ 9" ) ; } else { System . out . println ( " Smallest ▁ Palindrome : ▁ " + ( int ) ( Math . pow ( 10 , n - 1 ) ) + 1 ) ; System . out . println ( " Largest ▁ Palindrome : ▁ " + ( ( int ) ( Math . pow ( 10 , n ) ) - 1 ) ) ; } } public static void main ( String [ ] args ) { int n = 4 ; printPalindrome ( n ) ; } }

from math import pow NEW_LINE def printPalindrome ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT print ( " Smallest ▁ Palindrome : ▁ 0" ) NEW_LINE print ( " Largest ▁ Palindrome : ▁ 9" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Smallest ▁ Palindrome : " , int ( pow ( 10 , n - 1 ) ) + 1 ) NEW_LINE print ( " Largest ▁ Palindrome : " , int ( pow ( 10 , n ) ) - 1 ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE printPalindrome ( n ) NEW_LINE DEDENT


import java . util . * ; class Geeks_For_Geeks { public static char [ ] sortArrays ( char [ ] arr ) { int length = arr . length ; for ( int j = 0 ; j < arr . length - 1 ; j ++ ) { int d1 = arr [ j ] ; int d2 = arr [ j + 1 ] ; if ( d1 > d2 ) { char temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = - 1 ; } } return arr ; } public static void main ( String args [ ] ) { String geeks = " GEEKSFORGEEKS " ; char arr [ ] = geeks . toCharArray ( ) ; System . out . println ( " Original ▁ array : ▁ " + Arrays . toString ( arr ) ) ; arr = sortArrays ( arr ) ; System . out . println ( " Sorted ▁ array : ▁ " + Arrays . toString ( arr ) ) ; } }

def sortArrays ( arr , length ) : NEW_LINE INDENT j = 0 NEW_LINE while ( j < length - 1 ) : NEW_LINE INDENT d1 = arr [ j ] NEW_LINE d2 = arr [ j + 1 ] NEW_LINE if ( d1 > d2 ) : NEW_LINE INDENT temp = arr [ j ] NEW_LINE arr [ j ] = arr [ j + 1 ] NEW_LINE arr [ j + 1 ] = temp NEW_LINE j = - 1 NEW_LINE DEDENT j += 1 NEW_LINE DEDENT return arr NEW_LINE DEDENT geeks = " GEEKSFORGEEKS " NEW_LINE n = len ( geeks ) NEW_LINE arr = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ i ] = geeks [ i ] NEW_LINE DEDENT print ( " Original ▁ array : ▁ [ " , end = " " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " " ) NEW_LINE if ( i + 1 != n ) : NEW_LINE INDENT print ( " , ▁ " , end = " " ) NEW_LINE DEDENT DEDENT print ( " ] " ) NEW_LINE ansarr = sortArrays ( arr , n ) NEW_LINE print ( " Sorted ▁ array : ▁ [ " , end = " " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( ansarr [ i ] , end = " " ) NEW_LINE if ( i + 1 != n ) : NEW_LINE INDENT print ( " , ▁ " , end = " " ) NEW_LINE DEDENT DEDENT print ( " ] " ) NEW_LINE


public class gfg { int find ( String s ) { int max = 0 , i , j = 0 , countk = 0 , countr = 0 ; int table [ ] [ ] = new int [ s . length ( ) ] [ 2 ] ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == ' R ' ) countr ++ ; else table [ j ++ ] [ 0 ] = countr ; } j -- ; for ( i = s . length ( ) - 1 ; i >= 0 ; i -- ) { if ( s . charAt ( i ) == ' K ' ) { countk ++ ; table [ j -- ] [ 1 ] = countk ; } if ( Math . min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] ) > max ) max = Math . min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] ) ; } return max ; } public static void main ( String srgs [ ] ) { String s = " RKRRRKKRRKKKKRR " ; gfg ob = new gfg ( ) ; int n = ob . find ( s ) ; System . out . println ( n ) ; } }

def find ( s ) : NEW_LINE INDENT Max = j = countk = countr = 0 NEW_LINE table = [ [ 0 , 0 ] for i in range ( len ( s ) ) ] NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT if s [ i ] == ' R ' : NEW_LINE INDENT countr += 1 NEW_LINE DEDENT else : NEW_LINE INDENT table [ j ] [ 0 ] = countr NEW_LINE j += 1 NEW_LINE DEDENT DEDENT j -= 1 NEW_LINE for i in range ( len ( s ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if s [ i ] == ' K ' : NEW_LINE INDENT countk += 1 NEW_LINE table [ j ] [ 1 ] = countk NEW_LINE j -= 1 NEW_LINE DEDENT if min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] ) > Max : NEW_LINE INDENT Max = min ( table [ j + 1 ] [ 0 ] , table [ j + 1 ] [ 1 ] ) NEW_LINE DEDENT DEDENT return Max NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " RKRRRKKRRKKKKRR " NEW_LINE print ( find ( s ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static double Square ( double n , double i , double j ) { double mid = ( i + j ) / 2 ; double mul = mid * mid ; if ( ( mul == n ) || ( Math . abs ( mul - n ) < 0.00001 ) ) return mid ; else if ( mul < n ) return Square ( n , mid , j ) ; else return Square ( n , i , mid ) ; } static void findSqrt ( double n ) { double i = 1 ; boolean found = false ; while ( ! found ) { if ( i * i == n ) { System . out . println ( i ) ; found = true ; } else if ( i * i > n ) { double res = Square ( n , i - 1 , i ) ; System . out . printf ( " % .5f " , res ) ; found = true ; } i ++ ; } } public static void main ( String [ ] args ) { double n = 3 ; findSqrt ( n ) ; } }

import math NEW_LINE def Square ( n , i , j ) : NEW_LINE INDENT mid = ( i + j ) / 2 ; NEW_LINE mul = mid * mid ; NEW_LINE if ( ( mul == n ) or ( abs ( mul - n ) < 0.00001 ) ) : NEW_LINE INDENT return mid ; NEW_LINE DEDENT elif ( mul < n ) : NEW_LINE INDENT return Square ( n , mid , j ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return Square ( n , i , mid ) ; NEW_LINE DEDENT DEDENT def findSqrt ( n ) : NEW_LINE INDENT i = 1 ; NEW_LINE found = False ; NEW_LINE while ( found == False ) : NEW_LINE INDENT if ( i * i == n ) : NEW_LINE INDENT print ( i ) ; NEW_LINE found = True ; NEW_LINE DEDENT elif ( i * i > n ) : NEW_LINE INDENT res = Square ( n , i - 1 , i ) ; NEW_LINE print ( " { 0 : . 5f } " . format ( res ) ) NEW_LINE found = True NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 ; NEW_LINE findSqrt ( n ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int averageOdd ( int n ) { if ( n % 2 == 0 ) { System . out . println ( " Invalid ▁ Input " ) ; return - 1 ; } int sum = 0 , count = 0 ; while ( n >= 1 ) { count ++ ; sum += n ; n = n - 2 ; } return sum / count ; } public static void main ( String args [ ] ) { int n = 15 ; System . out . println ( averageOdd ( n ) ) ; } }

def averageOdd ( n ) : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT print ( " Invalid ▁ Input " ) NEW_LINE return - 1 NEW_LINE DEDENT sm = 0 NEW_LINE count = 0 NEW_LINE while ( n >= 1 ) : NEW_LINE INDENT count = count + 1 NEW_LINE sm = sm + n NEW_LINE n = n - 2 NEW_LINE DEDENT return sm // count NEW_LINE DEDENT n = 15 NEW_LINE print ( averageOdd ( n ) ) NEW_LINE


import java . util . * ; class solution { static boolean SumDivisible ( int n , int k ) { int sum = 0 , position = 1 ; while ( n > 0 ) { if ( position % 2 == 1 ) sum += n % 10 ; n = n / 10 ; position ++ ; } if ( sum % k == 0 ) return true ; return false ; } public static void main ( String arr [ ] ) { int n = 592452 ; int k = 3 ; if ( SumDivisible ( n , k ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

def SumDivisible ( n , k ) : NEW_LINE INDENT sum = 0 NEW_LINE position = 1 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( position % 2 == 1 ) : NEW_LINE INDENT sum += n % 10 NEW_LINE DEDENT n = n // 10 NEW_LINE position += 1 NEW_LINE DEDENT if ( sum % k == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 592452 NEW_LINE k = 3 NEW_LINE if ( SumDivisible ( n , k ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


class GFG { static void farthest_min ( int [ ] a , int n ) { int [ ] suffix_min = new int [ n ] ; suffix_min [ n - 1 ] = a [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffix_min [ i ] = Math . min ( suffix_min [ i + 1 ] , a [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { int low = i + 1 , high = n - 1 , ans = - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( suffix_min [ mid ] < a [ i ] ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } System . out . print ( ans + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] a = { 3 , 1 , 5 , 2 , 4 } ; int n = a . length ; farthest_min ( a , n ) ; } }

def farthest_min ( a , n ) : NEW_LINE INDENT suffix_min = [ 0 for i in range ( n ) ] NEW_LINE suffix_min [ n - 1 ] = a [ n - 1 ] NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT suffix_min [ i ] = min ( suffix_min [ i + 1 ] , a [ i ] ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT low = i + 1 NEW_LINE high = n - 1 NEW_LINE ans = - 1 NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = ( low + high ) // 2 NEW_LINE if ( suffix_min [ mid ] < a [ i ] ) : NEW_LINE INDENT ans = mid NEW_LINE low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT print ( ans , end = " ▁ " ) NEW_LINE DEDENT DEDENT a = [ 3 , 1 , 5 , 2 , 4 ] NEW_LINE n = len ( a ) NEW_LINE farthest_min ( a , n ) NEW_LINE


class GFG { static void printSeriesSum ( int N ) { long sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += Math . pow ( i , i - 1 ) ; } System . out . print ( sum + " \n " ) ; } public static void main ( String [ ] args ) { int N = 5 ; printSeriesSum ( N ) ; } }

def printSeriessumm ( N ) : NEW_LINE INDENT summ = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT summ += pow ( i , i - 1 ) NEW_LINE DEDENT print ( summ ) NEW_LINE DEDENT N = 5 NEW_LINE printSeriessumm ( N ) NEW_LINE


class GFG { static double EPS = 1E-15 ; static double findMinValue ( double arr [ ] , double n ) { double sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( double ) Math . log10 ( arr [ i ] ) + EPS ; double xl = ( double ) ( sum / n + EPS ) ; double res = Math . pow ( ( double ) 10.0 , ( double ) xl ) + EPS ; return ( double ) Math . ceil ( res + EPS ) ; } public static void main ( String [ ] args ) { double arr [ ] = { 4 , 2 , 1 , 10 , 6 } ; double n = arr . length ; System . out . println ( findMinValue ( arr , n ) ) ; } }

import math NEW_LINE EPS = 1E-15 ; NEW_LINE def findMinValue ( arr , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += math . log10 ( arr [ i ] ) + EPS ; NEW_LINE DEDENT xl = ( sum / n + EPS ) ; NEW_LINE res = math . pow ( 10.0 , xl ) + EPS ; NEW_LINE return math . ceil ( res + EPS ) ; NEW_LINE DEDENT arr = [ 4 , 2 , 1 , 10 , 6 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( findMinValue ( arr , n ) ) ; NEW_LINE


import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int phi ( int n ) { int result = 1 ; for ( int i = 2 ; i < n ; i ++ ) if ( gcd ( i , n ) == 1 ) result ++ ; return result ; } public static void main ( String [ ] args ) { int n ; for ( n = 1 ; n <= 10 ; n ++ ) System . out . println ( " phi ( " + n + " ) ▁ = ▁ " + phi ( n ) ) ; } }

def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def phi ( n ) : NEW_LINE INDENT result = 1 NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( gcd ( i , n ) == 1 ) : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT for n in range ( 1 , 11 ) : NEW_LINE INDENT print ( " phi ( " , n , " ) ▁ = ▁ " , phi ( n ) , sep = " " ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int binarysearch ( Vector < Integer > v , int x ) { int low = 0 , high = v . size ( ) - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( v . get ( mid ) <= x ) low = mid + 1 ; else if ( v . get ( mid ) > x && v . get ( mid ) <= x ) return mid ; else if ( v . get ( mid ) > x && mid == 0 ) return mid ; else high = mid - 1 ; } return - 1 ; } static int CountContiguousParts ( int arr [ ] , int n ) { int count = 0 ; int [ ] prefix = new int [ n ] ; prefix [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix [ i ] = prefix [ i - 1 ] + arr [ i ] ; int total_sum = prefix [ n - 1 ] ; if ( total_sum % 3 != 0 ) return 0 ; int [ ] suffix = new int [ n ] ; suffix [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix [ i ] = suffix [ i + 1 ] + arr [ i ] ; Vector < Integer > v = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( suffix [ i ] == total_sum / 3 ) v . add ( i ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( prefix [ i ] == total_sum / 3 ) { int res = binarysearch ( v , i + 1 ) ; if ( res != - 1 ) count += v . size ( ) - res ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 0 , 3 } ; int n = arr . length ; System . out . println ( CountContiguousParts ( arr , n ) ) ; } }

def binarysearch ( v , x ) : NEW_LINE INDENT low = 0 NEW_LINE high = len ( v ) - 1 NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = int ( ( low + high ) / 2 ) NEW_LINE if ( v [ mid ] <= x ) : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT elif ( v [ mid ] > x and v [ mid - 1 ] <= x ) : NEW_LINE INDENT return mid NEW_LINE DEDENT elif ( v [ mid ] > x and mid == 0 ) : NEW_LINE INDENT return mid NEW_LINE DEDENT else : NEW_LINE INDENT high = mid - 1 NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT def CountContiguousParts ( arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE prefix = [ 0 for i in range ( n ) ] NEW_LINE prefix [ 0 ] = arr [ 0 ] NEW_LINE for i in range ( 1 , n , 1 ) : NEW_LINE INDENT prefix [ i ] = prefix [ i - 1 ] + arr [ i ] NEW_LINE DEDENT total_sum = prefix [ n - 1 ] NEW_LINE if ( total_sum % 3 != 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT suffix = [ 0 for i in range ( n ) ] NEW_LINE suffix [ n - 1 ] = arr [ n - 1 ] NEW_LINE i = n - 2 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT suffix [ i ] = suffix [ i + 1 ] + arr [ i ] NEW_LINE i -= 1 NEW_LINE DEDENT v = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( suffix [ i ] == int ( total_sum / 3 ) ) : NEW_LINE INDENT v . append ( i ) NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( prefix [ i ] == int ( total_sum / 3 ) ) : NEW_LINE INDENT res = binarysearch ( v , i + 1 ) NEW_LINE if ( res != - 1 ) : NEW_LINE INDENT count += len ( v ) - res NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 0 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( CountContiguousParts ( arr , n ) ) NEW_LINE DEDENT


class GFG { static boolean checkEqualNo ( int m , int n , int a , int b ) { if ( m <= n ) { if ( ( n - m ) % ( a + b ) == 0 ) { return true ; } else { return false ; } } else { return false ; } } public static void main ( String [ ] args ) { int M = 2 , N = 8 ; int A = 3 , B = 3 ; if ( checkEqualNo ( M , N , A , B ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def checkEqualNo ( m , n , a , b ) : NEW_LINE INDENT if ( m <= n ) : NEW_LINE INDENT if ( ( n - m ) % ( a + b ) == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT M = 2 ; N = 8 ; NEW_LINE A = 3 ; B = 3 ; NEW_LINE if ( checkEqualNo ( M , N , A , B ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static boolean isDivisibleBy10 ( char bin [ ] , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; int sum = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( bin [ i ] == '1' ) { int posFromRight = n - i - 1 ; if ( posFromRight % 4 == 1 ) sum = sum + 2 ; else if ( posFromRight % 4 == 2 ) sum = sum + 4 ; else if ( posFromRight % 4 == 3 ) sum = sum + 8 ; else if ( posFromRight % 4 == 0 ) sum = sum + 6 ; } } if ( sum % 10 == 0 ) return true ; return false ; } static boolean isDivisibleBy20 ( char bin [ ] , int n ) { if ( bin [ n - 1 ] == '1' ) return false ; return isDivisibleBy10 ( bin , n - 1 ) ; } public static void main ( String args [ ] ) { char bin [ ] = "101000" . toCharArray ( ) ; int n = bin . length ; if ( isDivisibleBy20 ( bin , n - 1 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isDivisibleBy10 ( bin , n ) : NEW_LINE INDENT if ( bin [ n - 1 ] == '1' ) : NEW_LINE INDENT return False NEW_LINE DEDENT sum = 0 NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( bin [ i ] == '1' ) : NEW_LINE INDENT posFromRight = n - i - 1 NEW_LINE if ( posFromRight % 4 == 1 ) : NEW_LINE INDENT sum = sum + 2 NEW_LINE DEDENT elif ( posFromRight % 4 == 2 ) : NEW_LINE INDENT sum = sum + 4 NEW_LINE DEDENT elif ( posFromRight % 4 == 3 ) : NEW_LINE INDENT sum = sum + 8 NEW_LINE DEDENT elif ( posFromRight % 4 == 0 ) : NEW_LINE INDENT sum = sum + 6 NEW_LINE DEDENT DEDENT DEDENT if ( sum % 10 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def isDivisibleBy20 ( bin , n ) : NEW_LINE INDENT if ( bin [ n - 1 ] == '1' ) : NEW_LINE INDENT return false NEW_LINE DEDENT return isDivisibleBy10 ( bin , n - 1 ) NEW_LINE DEDENT bin = [ '1' , '0' , '1' , '0' , '0' , '0' ] NEW_LINE n = len ( bin ) NEW_LINE if ( isDivisibleBy20 ( bin , n - 1 ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class GFG { static void powerSet ( String str , int index , String curr ) { int n = str . length ( ) ; if ( index == n ) { System . out . println ( curr ) ; return ; } powerSet ( str , index + 1 , curr + str . charAt ( index ) ) ; powerSet ( str , index + 1 , curr ) ; } public static void main ( String [ ] args ) { String str = " abc " ; int index = 0 ; String curr = " " ; powerSet ( str , index , curr ) ; } }

def powerSet ( string , index , curr ) : NEW_LINE INDENT if index == len ( string ) : NEW_LINE INDENT print ( curr ) NEW_LINE return NEW_LINE DEDENT powerSet ( string , index + 1 , curr + string [ index ] ) NEW_LINE powerSet ( string , index + 1 , curr ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s1 = " abc " NEW_LINE index = 0 NEW_LINE curr = " " NEW_LINE powerSet ( s1 , index , curr ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; public class detheap { static boolean isMinHeap ( int [ ] level ) { int n = level . length - 1 ; for ( int i = ( n / 2 - 1 ) ; i >= 0 ; i -- ) { if ( level [ i ] > level [ 2 * i + 1 ] ) return false ; if ( 2 * i + 2 < n ) { if ( level [ i ] > level [ 2 * i + 2 ] ) return false ; } } return true ; } public static void main ( String [ ] args ) throws IOException { int [ ] level = new int [ ] { 10 , 15 , 14 , 25 , 30 } ; if ( isMinHeap ( level ) ) System . out . println ( " True " ) ; else System . out . println ( " False " ) ; } }

def isMinHeap ( level , n ) : NEW_LINE INDENT for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if level [ i ] > level [ 2 * i + 1 ] : NEW_LINE INDENT return False NEW_LINE DEDENT if 2 * i + 2 < n : NEW_LINE INDENT if level [ i ] > level [ 2 * i + 2 ] : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT level = [ 10 , 15 , 14 , 25 , 30 ] NEW_LINE n = len ( level ) NEW_LINE if isMinHeap ( level , n ) : NEW_LINE INDENT print ( " True " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " False " ) NEW_LINE DEDENT DEDENT


import java . util . Arrays ; class GFG { final static int MAX_CHARS = 26 ; static boolean isValid ( int count [ ] , int k ) { int val = 0 ; for ( int i = 0 ; i < MAX_CHARS ; i ++ ) { if ( count [ i ] > 0 ) { val ++ ; } } return ( k >= val ) ; } static void kUniques ( String s , int k ) { int u = 0 ; int n = s . length ( ) ; int count [ ] = new int [ MAX_CHARS ] ; Arrays . fill ( count , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ s . charAt ( i ) - ' a ' ] == 0 ) { u ++ ; } count [ s . charAt ( i ) - ' a ' ] ++ ; } if ( u < k ) { System . out . print ( " Not ▁ enough ▁ unique ▁ characters " ) ; return ; } int curr_start = 0 , curr_end = 0 ; int max_window_size = 1 , max_window_start = 0 ; Arrays . fill ( count , 0 ) ; count [ s . charAt ( 0 ) - ' a ' ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { count [ s . charAt ( i ) - ' a ' ] ++ ; curr_end ++ ; while ( ! isValid ( count , k ) ) { count [ s . charAt ( curr_start ) - ' a ' ] -- ; curr_start ++ ; } if ( curr_end - curr_start + 1 > max_window_size ) { max_window_size = curr_end - curr_start + 1 ; max_window_start = curr_start ; } } System . out . println ( " Max ▁ sustring ▁ is ▁ : ▁ " + s . substring ( max_window_start , max_window_size ) + " ▁ with ▁ length ▁ " + max_window_size ) ; } static public void main ( String [ ] args ) { String s = " aabacbebebe " ; int k = 3 ; kUniques ( s , k ) ; } }

MAX_CHARS = 26 NEW_LINE def isValid ( count , k ) : NEW_LINE INDENT val = 0 NEW_LINE for i in range ( MAX_CHARS ) : NEW_LINE INDENT if count [ i ] > 0 : NEW_LINE INDENT val += 1 NEW_LINE DEDENT DEDENT return ( k >= val ) NEW_LINE DEDENT def kUniques ( s , k ) : NEW_LINE INDENT u = 0 NEW_LINE n = len ( s ) NEW_LINE count = [ 0 ] * MAX_CHARS NEW_LINE for i in range ( n ) : NEW_LINE INDENT if count [ ord ( s [ i ] ) - ord ( ' a ' ) ] == 0 : NEW_LINE INDENT u += 1 NEW_LINE DEDENT count [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT if u < k : NEW_LINE INDENT print ( " Not ▁ enough ▁ unique ▁ characters " ) NEW_LINE return NEW_LINE DEDENT curr_start = 0 NEW_LINE curr_end = 0 NEW_LINE max_window_size = 1 NEW_LINE max_window_start = 0 NEW_LINE count = [ 0 ] * len ( count ) NEW_LINE count [ ord ( s [ 0 ] ) - ord ( ' a ' ) ] += 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT count [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE curr_end += 1 NEW_LINE while not isValid ( count , k ) : NEW_LINE INDENT count [ ord ( s [ curr_start ] ) - ord ( ' a ' ) ] -= 1 NEW_LINE curr_start += 1 NEW_LINE DEDENT if curr_end - curr_start + 1 > max_window_size : NEW_LINE INDENT max_window_size = curr_end - curr_start + 1 NEW_LINE max_window_start = curr_start NEW_LINE DEDENT DEDENT print ( " Max ▁ substring ▁ is ▁ : ▁ " + s [ max_window_start : max_window_start + max_window_size ] + " ▁ with ▁ length ▁ " + str ( max_window_size ) ) NEW_LINE DEDENT s = " aabacbebebe " NEW_LINE k = 3 NEW_LINE kUniques ( s , k ) NEW_LINE


class GFG { static int printPermutation ( int n ) { if ( n % 2 != 0 ) { System . out . println ( " - 1" ) ; } else for ( int i = 1 ; i <= n / 2 ; i ++ ) { System . out . print ( 2 * i + " ▁ " + ( ( 2 * i ) - 1 ) + " ▁ " ) ; } return n ; } public static void main ( String [ ] args ) { int n = 4 ; printPermutation ( n ) ; } }

def printPermutation ( n ) : NEW_LINE INDENT if ( n % 2 != 0 ) : NEW_LINE INDENT print ( - 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( 1 , ( n // 2 ) + 1 ) : NEW_LINE INDENT print ( ( 2 * i ) , ( 2 * i - 1 ) , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT n = 4 ; NEW_LINE printPermutation ( n ) ; NEW_LINE


import java . io . * ; class GFG { static float mean ( float mid [ ] , int freq [ ] , int n ) { float sum = 0 , freqSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum = sum + mid [ i ] * freq [ i ] ; freqSum = freqSum + freq [ i ] ; } return sum / freqSum ; } static float groupedSD ( float lower_limit [ ] , float upper_limit [ ] , int freq [ ] , int n ) { float mid [ ] = new float [ n ] ; float sum = 0 , freqSum = 0 , sd ; for ( int i = 0 ; i < n ; i ++ ) { mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2 ; sum = sum + freq [ i ] * mid [ i ] * mid [ i ] ; freqSum = freqSum + freq [ i ] ; } sd = ( float ) Math . sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) ) ; return sd ; } public static void main ( String [ ] args ) { float lower_limit [ ] = { 50 , 61 , 71 , 86 , 96 } ; float upper_limit [ ] = { 60 , 70 , 85 , 95 , 100 } ; int freq [ ] = { 9 , 7 , 9 , 12 , 8 } ; int n = lower_limit . length ; System . out . println ( groupedSD ( lower_limit , upper_limit , freq , n ) ) ; } }

import math NEW_LINE def mean ( mid , freq , n ) : NEW_LINE INDENT sum = 0 NEW_LINE freqSum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sum = sum + mid [ i ] * freq [ i ] NEW_LINE freqSum = freqSum + freq [ i ] NEW_LINE DEDENT return sum / freqSum NEW_LINE DEDENT def groupedSD ( lower_limit , upper_limit , freq , n ) : NEW_LINE INDENT mid = [ [ 0 ] for i in range ( 0 , n ) ] NEW_LINE sum = 0 NEW_LINE freqSum = 0 NEW_LINE sd = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT mid [ i ] = ( lower_limit [ i ] + upper_limit [ i ] ) / 2 NEW_LINE sum = sum + freq [ i ] * mid [ i ] * mid [ i ] NEW_LINE freqSum = freqSum + freq [ i ] NEW_LINE DEDENT sd = math . sqrt ( ( sum - freqSum * mean ( mid , freq , n ) * mean ( mid , freq , n ) ) / ( freqSum - 1 ) ) NEW_LINE return sd NEW_LINE DEDENT lower_limit = [ 50 , 61 , 71 , 86 , 96 ] NEW_LINE upper_limit = [ 60 , 70 , 85 , 95 , 100 ] NEW_LINE freq = [ 9 , 7 , 9 , 12 , 8 ] NEW_LINE n = len ( lower_limit ) NEW_LINE print ( groupedSD ( lower_limit , upper_limit , freq , n ) ) NEW_LINE


import java . util . * ; class GFG { public static int calculate ( int ar [ ] , int size ) { int count = 0 ; for ( int i = 0 ; i < size ; i ++ ) if ( ar [ i ] % 2 == 0 && ar [ i ] != 0 && ar [ i ] != 2 ) count ++ ; return count ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 4 , 6 } ; int size = a . length ; System . out . print ( calculate ( a , size ) ) ; } }

def calculate ( array , size ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( size ) : NEW_LINE INDENT if ( array [ i ] % 2 == 0 and array [ i ] != 0 and array [ i ] != 2 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 1 , 3 , 4 , 6 ] NEW_LINE size = len ( a ) NEW_LINE print ( calculate ( a , size ) ) NEW_LINE DEDENT


class GFG { static long getMinNum ( int N ) { int lcm = 1 ; for ( int i = 2 ; i <= N ; i ++ ) lcm = ( ( i * lcm ) / ( __gcd ( i , lcm ) ) ) ; return ( lcm + 1 ) ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void main ( String args [ ] ) { int N = 5 ; System . out . println ( getMinNum ( N ) ) ; } }

from math import gcd NEW_LINE def getMinNum ( N ) : NEW_LINE INDENT lcm = 1 ; NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT lcm = ( ( i * lcm ) // ( gcd ( i , lcm ) ) ) ; NEW_LINE DEDENT return ( lcm + 1 ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 ; NEW_LINE print ( getMinNum ( N ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static void product_subarrays ( int arr [ ] , int n ) { int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { product *= arr [ j ] ; } } System . out . println ( product + " \n " ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 10 , 3 , 7 } ; int n = arr . length ; product_subarrays ( arr , n ) ; } }

def product_subarrays ( arr , n ) : NEW_LINE INDENT product = 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT product *= arr [ j ] ; NEW_LINE DEDENT DEDENT print ( product ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 10 , 3 , 7 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE product_subarrays ( arr , n ) ; NEW_LINE DEDENT


class GFG { private static int minJumps ( int [ ] arr , int n ) { int jumps [ ] = new int [ n ] ; int i , j ; if ( n == 0 || arr [ 0 ] == 0 ) return Integer . MAX_VALUE ; jumps [ 0 ] = 0 ; for ( i = 1 ; i < n ; i ++ ) { jumps [ i ] = Integer . MAX_VALUE ; for ( j = 0 ; j < i ; j ++ ) { if ( i <= j + arr [ j ] && jumps [ j ] != Integer . MAX_VALUE ) { jumps [ i ] = Math . min ( jumps [ i ] , jumps [ j ] + 1 ) ; break ; } } } return jumps [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 6 , 1 , 0 , 9 } ; System . out . println ( " Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach ▁ end ▁ is ▁ : ▁ " + minJumps ( arr , arr . length ) ) ; } }

def minJumps ( arr , n ) : NEW_LINE INDENT jumps = [ 0 for i in range ( n ) ] NEW_LINE if ( n == 0 ) or ( arr [ 0 ] == 0 ) : NEW_LINE INDENT return float ( ' inf ' ) NEW_LINE DEDENT jumps [ 0 ] = 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT jumps [ i ] = float ( ' inf ' ) NEW_LINE for j in range ( i ) : NEW_LINE INDENT if ( i <= j + arr [ j ] ) and ( jumps [ j ] != float ( ' inf ' ) ) : NEW_LINE INDENT jumps [ i ] = min ( jumps [ i ] , jumps [ j ] + 1 ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return jumps [ n - 1 ] NEW_LINE DEDENT arr = [ 1 , 3 , 6 , 1 , 0 , 9 ] NEW_LINE size = len ( arr ) NEW_LINE print ( ' Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach ' , ' end ▁ is ' , minJumps ( arr , size ) ) NEW_LINE


class GFG { static void decBinary ( int arr [ ] , int n ) { int k = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n /= 2 ; } } static int binaryDec ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } static int concat ( int m , int n ) { int k = ( int ) ( Math . log ( m ) / Math . log ( 2 ) ) + 1 ; int l = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) + 1 ; int a [ ] = new int [ k ] ; int b [ ] = new int [ l ] ; int c [ ] = new int [ k + l ] ; decBinary ( a , m ) ; decBinary ( b , n ) ; int in = 0 ; for ( int i = 0 ; i < k ; i ++ ) c [ in ++ ] = a [ i ] ; for ( int i = 0 ; i < l ; i ++ ) c [ in ++ ] = b [ i ] ; return ( binaryDec ( c , k + l ) ) ; } public static void main ( String [ ] args ) { int m = 4 , n = 5 ; System . out . println ( concat ( m , n ) ) ; } }

import math NEW_LINE def decBinary ( arr , n ) : NEW_LINE INDENT k = int ( math . log2 ( n ) ) NEW_LINE while ( n > 0 ) : NEW_LINE INDENT arr [ k ] = n % 2 NEW_LINE k = k - 1 NEW_LINE n = n // 2 NEW_LINE DEDENT DEDENT def binaryDec ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT ans = ans + ( arr [ i ] << ( n - i - 1 ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT def concat ( m , n ) : NEW_LINE INDENT k = int ( math . log2 ( m ) ) + 1 NEW_LINE l = int ( math . log2 ( n ) ) + 1 NEW_LINE a = [ 0 for i in range ( 0 , k ) ] NEW_LINE b = [ 0 for i in range ( 0 , l ) ] NEW_LINE c = [ 0 for i in range ( 0 , k + l ) ] NEW_LINE decBinary ( a , m ) ; NEW_LINE decBinary ( b , n ) ; NEW_LINE iin = 0 NEW_LINE for i in range ( 0 , k ) : NEW_LINE INDENT c [ iin ] = a [ i ] NEW_LINE iin = iin + 1 NEW_LINE DEDENT for i in range ( 0 , l ) : NEW_LINE INDENT c [ iin ] = b [ i ] NEW_LINE iin = iin + 1 NEW_LINE DEDENT return ( binaryDec ( c , k + l ) ) NEW_LINE DEDENT m = 4 NEW_LINE n = 5 NEW_LINE print ( concat ( m , n ) ) NEW_LINE


class GFG { static int N = 100005 ; static int LIS ( int a [ ] , int n ) { int dp [ ] = new int [ N ] , d [ ] = new int [ N ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { dp [ a [ i ] ] = 1 ; for ( int j = 2 ; j * j <= a [ i ] ; j ++ ) { if ( a [ i ] % j == 0 ) { dp [ a [ i ] ] = Math . max ( dp [ a [ i ] ] , dp [ d [ j ] ] + 1 ) ; dp [ a [ i ] ] = Math . max ( dp [ a [ i ] ] , dp [ d [ a [ i ] / j ] ] + 1 ) ; d [ j ] = a [ i ] ; d [ a [ i ] / j ] = a [ i ] ; } } ans = Math . max ( ans , dp [ a [ i ] ] ) ; d [ a [ i ] ] = a [ i ] ; } return ans ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = a . length ; System . out . print ( LIS ( a , n ) ) ; } }

N = 100005 NEW_LINE def LIS ( a , n ) : NEW_LINE INDENT dp = [ 0 for i in range ( N ) ] NEW_LINE d = [ 0 for i in range ( N ) ] NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT dp [ a [ i ] ] = 1 NEW_LINE for j in range ( 2 , a [ i ] ) : NEW_LINE INDENT if j * j > a [ i ] : NEW_LINE INDENT break NEW_LINE DEDENT if ( a [ i ] % j == 0 ) : NEW_LINE INDENT dp [ a [ i ] ] = max ( dp [ a [ i ] ] , dp [ d [ j ] ] + 1 ) NEW_LINE dp [ a [ i ] ] = max ( dp [ a [ i ] ] , dp [ d [ a [ i ] // j ] ] + 1 ) NEW_LINE d [ j ] = a [ i ] NEW_LINE d [ a [ i ] // j ] = a [ i ] NEW_LINE DEDENT DEDENT ans = max ( ans , dp [ a [ i ] ] ) NEW_LINE d [ a [ i ] ] = a [ i ] NEW_LINE DEDENT return ans NEW_LINE DEDENT a = [ 1 , 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( a ) NEW_LINE print ( LIS ( a , n ) ) NEW_LINE


import java . io . * ; class GFG { static long fifthPowerSum ( int n ) { return ( ( 2 * n * n * n * n * n * n ) + ( 6 * n * n * n * n * n ) + ( 5 * n * n * n * n ) - ( n * n ) ) / 12 ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( fifthPowerSum ( n ) ) ; } }

def fifthPowerSum ( n ) : NEW_LINE INDENT return ( ( 2 * n * n * n * n * n * n ) + ( 6 * n * n * n * n * n ) + ( 5 * n * n * n * n ) - ( n * n ) ) // 12 NEW_LINE DEDENT n = 5 NEW_LINE print ( fifthPowerSum ( n ) ) NEW_LINE


import java . util . * ; class GFG { static boolean check ( String s ) { int n = s . length ( ) ; for ( int i = 2 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' && s . charAt ( i - 1 ) == '1' && s . charAt ( i - 2 ) == '1' ) return true ; } return false ; } static int countStr ( int i , String s ) { if ( i < 0 ) { if ( check ( s ) ) return 1 ; return 0 ; } char [ ] myNameChars = s . toCharArray ( ) ; myNameChars [ i ] = '0' ; s = String . valueOf ( myNameChars ) ; int ans = countStr ( i - 1 , s ) ; char [ ] myChar = s . toCharArray ( ) ; myChar [ i ] = '1' ; s = String . valueOf ( myChar ) ; ans += countStr ( i - 1 , s ) ; char [ ] myChar1 = s . toCharArray ( ) ; myChar1 [ i ] = '0' ; s = String . valueOf ( myChar1 ) ; return ans ; } public static void main ( String args [ ] ) { int N = 4 ; String s = "0000" ; System . out . println ( countStr ( N - 1 , s ) ) ; } }

def check ( s ) : NEW_LINE INDENT n = len ( s ) ; NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( s [ i ] == '1' and s [ i - 1 ] == '1' and s [ i - 2 ] == '1' ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT DEDENT DEDENT def countStr ( i , s ) : NEW_LINE INDENT if ( i < 0 ) : NEW_LINE INDENT if ( check ( s ) ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT s [ i ] = '0' ; NEW_LINE ans = countStr ( i - 1 , s ) ; NEW_LINE s [ i ] = '1' ; NEW_LINE ans += countStr ( i - 1 , s ) ; NEW_LINE s [ i ] = '0' ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 ; NEW_LINE s = list ( '0' * N ) ; NEW_LINE print ( countStr ( N - 1 , s ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static int longLenSub ( int [ ] arr , int n ) { HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ; int longLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int len = 0 ; if ( um . containsKey ( arr [ i ] - 1 ) && len < um . get ( arr [ i ] - 1 ) ) len = um . get ( arr [ i ] - 1 ) ; if ( um . containsKey ( arr [ i ] + 1 ) && len < um . get ( arr [ i ] + 1 ) ) len = um . get ( arr [ i ] + 1 ) ; um . put ( arr [ i ] , len + 1 ) ; if ( longLen < um . get ( arr [ i ] ) ) longLen = um . get ( arr [ i ] ) ; } return longLen ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 3 , 2 } ; int n = arr . length ; System . out . println ( " Longest ▁ length ▁ subsequence ▁ = ▁ " + longLenSub ( arr , n ) ) ; } }

from collections import defaultdict NEW_LINE def longLenSub ( arr , n ) : NEW_LINE INDENT um = defaultdict ( lambda : 0 ) NEW_LINE longLen = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT len1 = 0 NEW_LINE if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) : NEW_LINE INDENT len1 = um [ arr [ i ] - 1 ] NEW_LINE DEDENT if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) : NEW_LINE INDENT len1 = um [ arr [ i ] + 1 ] NEW_LINE DEDENT um [ arr [ i ] ] = len1 + 1 NEW_LINE if longLen < um [ arr [ i ] ] : NEW_LINE INDENT longLen = um [ arr [ i ] ] NEW_LINE DEDENT DEDENT return longLen NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 3 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Longest ▁ length ▁ subsequence ▁ = " , longLenSub ( arr , n ) ) NEW_LINE


import java . util . * ; class GFG { public static String nextWord ( String str ) { if ( str == " " ) return " a " ; int i = str . length ( ) - 1 ; while ( str . charAt ( i ) == ' z ' && i >= 0 ) i -- ; if ( i == - 1 ) str = str + ' a ' ; else str = str . substring ( 0 , i ) + ( char ) ( ( int ) ( str . charAt ( i ) ) + 1 ) + str . substring ( i + 1 ) ; return str ; } public static void main ( String [ ] args ) { String str = " samez " ; System . out . print ( nextWord ( str ) ) ; } }

def nextWord ( s ) : NEW_LINE INDENT if ( s == " ▁ " ) : NEW_LINE INDENT return " a " NEW_LINE DEDENT i = len ( s ) - 1 NEW_LINE while ( s [ i ] == ' z ' and i >= 0 ) : NEW_LINE INDENT i -= 1 NEW_LINE DEDENT if ( i == - 1 ) : NEW_LINE INDENT s = s + ' a ' NEW_LINE DEDENT else : NEW_LINE INDENT s = s . replace ( s [ i ] , chr ( ord ( s [ i ] ) + 1 ) , 1 ) NEW_LINE DEDENT return s NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " samez " NEW_LINE print ( nextWord ( str ) ) NEW_LINE DEDENT


class GFG { static void mul_table ( int N , int i ) { if ( i > 10 ) return ; System . out . println ( N + " ▁ * ▁ " + i + " ▁ = ▁ " + N * i ) ; mul_table ( N , i + 1 ) ; } public static void main ( String [ ] args ) { int N = 8 ; mul_table ( N , 1 ) ; } }

def mul_table ( N , i ) : NEW_LINE INDENT if ( i > 10 ) : NEW_LINE INDENT return NEW_LINE DEDENT print ( N , " * " , i , " = " , N * i ) NEW_LINE return mul_table ( N , i + 1 ) NEW_LINE DEDENT N = 8 NEW_LINE mul_table ( N , 1 ) NEW_LINE