import java . util . * ; import java . lang . * ; class GFG { public static int gcdExtended ( int a , int b , int x , int y ) { if ( a == 0 ) { x = 0 ; y = 1 ; return b ; } int x1 = 1 , y1 = 1 ; int gcd = gcdExtended ( b % a , a , x1 , y1 ) ; x = y1 - ( b / a ) * x1 ; y = x1 ; return gcd ; } public static void main ( String [ ] args ) { int x = 1 , y = 1 ; int a = 35 , b = 15 ; int g = gcdExtended ( a , b , x , y ) ; System . out . print ( " gcd ( " + a + " ▁ , ▁ " + b + " ) ▁ = ▁ " + g ) ; } }

def gcdExtended ( a , b ) : NEW_LINE INDENT if a == 0 : NEW_LINE INDENT return b , 0 , 1 NEW_LINE DEDENT gcd , x1 , y1 = gcdExtended ( b % a , a ) NEW_LINE x = y1 - ( b // a ) * x1 NEW_LINE y = x1 NEW_LINE return gcd , x , y NEW_LINE DEDENT a , b = 35 , 15 NEW_LINE g , x , y = gcdExtended ( a , b ) NEW_LINE print ( " gcd ( " , a , " , " , b , " ) ▁ = ▁ " , g ) NEW_LINE


import java . lang . * ; class GFG { static int countNumbers ( int n ) { int k = 0 ; int count = 0 ; while ( n > 0 ) { if ( ( n & 1 ) == 0 ) count += ( int ) ( Math . pow ( 2 , k ) ) ; k += 1 ; n >>= 1 ; } return count ; } public static void main ( String [ ] args ) { int n = 11 ; System . out . println ( countNumbers ( n ) ) ; } }

def countNumbers ( n ) : NEW_LINE INDENT k = 0 NEW_LINE count = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( ( n & 1 ) == 0 ) : NEW_LINE INDENT count += pow ( 2 , k ) NEW_LINE DEDENT k += 1 NEW_LINE n >>= 1 NEW_LINE DEDENT return count NEW_LINE DEDENT n = 11 NEW_LINE print ( countNumbers ( n ) ) NEW_LINE


class GFG { static int digit_count ( int x ) { int sum = 0 ; while ( x > 0 ) { sum ++ ; x = x / 10 ; } return sum ; } static int find_count ( int [ ] arr , int k ) { int ans = 0 ; for ( int i : arr ) { int x = digit_count ( i ) ; if ( x % k == 0 ) ans += 1 ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 12 , 345 , 2 , 68 , 7896 } ; int K = 2 ; System . out . print ( find_count ( arr , K ) ) ; } }

def digit_count ( x ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( x ) : NEW_LINE INDENT sum += 1 NEW_LINE x = x // 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def find_count ( arr , k ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in arr : NEW_LINE INDENT x = digit_count ( i ) NEW_LINE if ( x % k == 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 345 , 2 , 68 , 7896 ] NEW_LINE K = 2 NEW_LINE print ( find_count ( arr , K ) ) NEW_LINE DEDENT


class GFG { static int n = 3 ; static int [ ] [ ] dp = new int [ n ] [ n ] ; static int [ ] [ ] v = new int [ n ] [ n ] ; static int minSteps ( int i , int j , int arr [ ] [ ] ) { if ( i == n - 1 && j == n - 1 ) { return 0 ; } if ( i > n - 1 || j > n - 1 ) { return 9999999 ; } if ( v [ i ] [ j ] == 1 ) { return dp [ i ] [ j ] ; } v [ i ] [ j ] = 1 ; dp [ i ] [ j ] = 9999999 ; for ( int k = Math . max ( 0 , arr [ i ] [ j ] + j - n + 1 ) ; k <= Math . min ( n - i - 1 , arr [ i ] [ j ] ) ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , minSteps ( i + k , j + arr [ i ] [ j ] - k , arr ) ) ; } dp [ i ] [ j ] ++ ; return dp [ i ] [ j ] ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 4 , 1 , 2 } , { 1 , 1 , 1 } , { 2 , 1 , 1 } } ; int ans = minSteps ( 0 , 0 , arr ) ; if ( ans >= 9999999 ) { System . out . println ( - 1 ) ; } else { System . out . println ( ans ) ; } } }

import numpy as np NEW_LINE n = 3 NEW_LINE dp = np . zeros ( ( n , n ) ) NEW_LINE v = np . zeros ( ( n , n ) ) ; NEW_LINE def minSteps ( i , j , arr ) : NEW_LINE INDENT if ( i == n - 1 and j == n - 1 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( i > n - 1 or j > n - 1 ) : NEW_LINE INDENT return 9999999 ; NEW_LINE DEDENT if ( v [ i ] [ j ] ) : NEW_LINE INDENT return dp [ i ] [ j ] ; NEW_LINE DEDENT v [ i ] [ j ] = 1 ; NEW_LINE dp [ i ] [ j ] = 9999999 ; NEW_LINE for k in range ( max ( 0 , arr [ i ] [ j ] + j - n + 1 ) , min ( n - i - 1 , arr [ i ] [ j ] ) + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] = min ( dp [ i ] [ j ] , minSteps ( i + k , j + arr [ i ] [ j ] - k , arr ) ) ; NEW_LINE DEDENT dp [ i ] [ j ] += 1 ; NEW_LINE return dp [ i ] [ j ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ [ 4 , 1 , 2 ] , [ 1 , 1 , 1 ] , [ 2 , 1 , 1 ] ] ; NEW_LINE ans = minSteps ( 0 , 0 , arr ) ; NEW_LINE if ( ans >= 9999999 ) : NEW_LINE INDENT print ( - 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( ans ) ; NEW_LINE DEDENT DEDENT


import java . util . * ; class GFG { static void printSeries ( int N ) { int ith_term = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { ith_term = i % 2 == 0 ? 2 * i * i + 1 : 2 * i * i - 1 ; System . out . print ( ith_term + " , ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 7 ; printSeries ( N ) ; } }

def printSeries ( N ) : NEW_LINE INDENT ith_term = 0 ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT ith_term = 0 ; NEW_LINE if ( i % 2 == 0 ) : NEW_LINE INDENT ith_term = 2 * i * i + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT ith_term = 2 * i * i - 1 ; NEW_LINE DEDENT print ( ith_term , end = " , ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 7 ; NEW_LINE printSeries ( N ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int findPossibleDerivables ( int arr [ ] , int n , int D , int A , int B ) { int gcdAB = gcd ( A , B ) ; int counter = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( Math . abs ( arr [ i ] - D ) % gcdAB ) == 0 ) { counter ++ ; } } return counter ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 7 , 13 } ; int n = arr . length ; int D = 5 , A = 4 , B = 2 ; System . out . println ( findPossibleDerivables ( arr , n , D , A , B ) ) ; int a [ ] = { 1 , 2 , 3 } ; n = a . length ; D = 6 ; A = 3 ; B = 2 ; System . out . println ( findPossibleDerivables ( a , n , D , A , B ) ) ; } }

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 findPossibleDerivables ( arr , n , D , A , B ) : NEW_LINE INDENT gcdAB = gcd ( A , B ) NEW_LINE counter = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ( abs ( arr [ i ] - D ) % gcdAB ) == 0 ) : NEW_LINE INDENT counter += 1 NEW_LINE DEDENT DEDENT return counter NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 7 , 13 ] NEW_LINE n = len ( arr ) NEW_LINE D , A , B = 5 , 4 , 2 NEW_LINE print ( findPossibleDerivables ( arr , n , D , A , B ) ) NEW_LINE a = [ 1 , 2 , 3 ] NEW_LINE n = len ( a ) NEW_LINE D , A , B = 6 , 3 , 2 NEW_LINE print ( findPossibleDerivables ( a , n , D , A , B ) ) NEW_LINE DEDENT


class GFG { static float power ( float x , int y ) { float temp ; if ( y == 0 ) return 1 ; temp = power ( x , y / 2 ) ; if ( y % 2 == 0 ) return temp * temp ; else { if ( y > 0 ) return x * temp * temp ; else return ( temp * temp ) / x ; } } public static void main ( String [ ] args ) { float x = 2 ; int y = - 3 ; System . out . printf ( " % f " , power ( x , y ) ) ; } }

def power ( x , y ) : NEW_LINE INDENT if ( y == 0 ) : return 1 NEW_LINE temp = power ( x , int ( y / 2 ) ) NEW_LINE if ( y % 2 == 0 ) : NEW_LINE INDENT return temp * temp NEW_LINE DEDENT else : NEW_LINE INDENT if ( y > 0 ) : return x * temp * temp NEW_LINE else : return ( temp * temp ) / x NEW_LINE DEDENT DEDENT x , y = 2 , - 3 NEW_LINE print ( ' % .6f ' % ( power ( x , y ) ) ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int maxSubStrings ( String s , int k ) { int maxSubStr = 0 , n = s . length ( ) ; for ( int c = 0 ; c < 26 ; c ++ ) { char ch = ( char ) ( ( int ) ' a ' + c ) ; int curr = 0 ; for ( int i = 0 ; i <= n - k ; i ++ ) { if ( s . charAt ( i ) != ch ) continue ; int cnt = 0 ; while ( i < n && s . charAt ( i ) == ch && cnt != k ) { i ++ ; cnt ++ ; } i -- ; if ( cnt == k ) curr ++ ; } maxSubStr = Math . max ( maxSubStr , curr ) ; } return maxSubStr ; } public static void main ( String [ ] args ) { String s = " aaacaabbaa " ; int k = 2 ; System . out . println ( maxSubStrings ( s , k ) ) ; } }

def maxSubStrings ( s , k ) : NEW_LINE INDENT maxSubStr = 0 NEW_LINE n = len ( s ) NEW_LINE for c in range ( 27 ) : NEW_LINE INDENT ch = chr ( ord ( ' a ' ) + c ) NEW_LINE curr = 0 NEW_LINE for i in range ( n - k ) : NEW_LINE INDENT if ( s [ i ] != ch ) : NEW_LINE INDENT continue NEW_LINE DEDENT cnt = 0 NEW_LINE while ( i < n and s [ i ] == ch and cnt != k ) : NEW_LINE INDENT i += 1 NEW_LINE cnt += 1 NEW_LINE DEDENT i -= 1 NEW_LINE if ( cnt == k ) : NEW_LINE INDENT curr += 1 NEW_LINE DEDENT DEDENT maxSubStr = max ( maxSubStr , curr ) NEW_LINE DEDENT return maxSubStr NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " aaacaabbaa " NEW_LINE k = 2 NEW_LINE print ( maxSubStrings ( s , k ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int distinctSubString ( String P , String Q , int K , int N ) { HashSet < String > S = new HashSet < String > ( ) ; for ( int i = 0 ; i < N ; ++ i ) { int sum = 0 ; String s = " " ; for ( int j = i ; j < N ; ++ j ) { int pos = P . charAt ( j ) - ' a ' ; sum += Q . charAt ( pos ) - '0' ; s += P . charAt ( j ) ; if ( sum <= K ) { S . add ( s ) ; } else { break ; } } } return S . size ( ) ; } public static void main ( String [ ] args ) { String P = " abcde " ; String Q = "12345678912345678912345678" ; int K = 5 ; int N = P . length ( ) ; System . out . print ( distinctSubString ( P , Q , K , N ) ) ; } }

def distinctSubstring ( P , Q , K , N ) : NEW_LINE INDENT S = set ( ) NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT sum = 0 ; NEW_LINE s = ' ' NEW_LINE for j in range ( i , N ) : NEW_LINE INDENT pos = ord ( P [ j ] ) - 97 NEW_LINE sum = sum + ord ( Q [ pos ] ) - 48 NEW_LINE s += P [ j ] NEW_LINE if ( sum <= K ) : NEW_LINE INDENT S . add ( s ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return len ( S ) NEW_LINE DEDENT P = " abcde " NEW_LINE Q = "12345678912345678912345678" NEW_LINE K = 5 NEW_LINE N = len ( P ) NEW_LINE print ( distinctSubstring ( P , Q , K , N ) ) NEW_LINE


import java . io . * ; import java . math . * ; class GFG { static long dp [ ] [ ] = new long [ 1000 ] [ 1000 ] ; static long sum ( int a [ ] , int i , int j ) { long ans = 0 ; for ( int m = i ; m <= j ; m ++ ) ans = ( ans + a [ m ] ) % 100 ; return ans ; } static long solve ( int a [ ] , int i , int j ) { if ( i == j ) return 0 ; if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; dp [ i ] [ j ] = 100000000 ; for ( int k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , ( solve ( a , i , k ) + solve ( a , k + 1 , j ) + ( sum ( a , i , k ) * sum ( a , k + 1 , j ) ) ) ) ; } return dp [ i ] [ j ] ; } static void intialize ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = - 1 ; } public static void main ( String args [ ] ) { int a [ ] = { 40 , 60 , 20 } ; int n = a . length ; intialize ( n ) ; System . out . println ( solve ( a , 0 , n - 1 ) ) ; } }

import numpy as np NEW_LINE import sys NEW_LINE dp = np . zeros ( ( 1000 , 1000 ) ) NEW_LINE def sum ( a , i , j ) : NEW_LINE INDENT ans = 0 NEW_LINE for m in range ( i , j + 1 ) : NEW_LINE INDENT ans = ( ans + a [ m ] ) % 100 NEW_LINE DEDENT return ans NEW_LINE DEDENT def solve ( a , i , j ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( dp [ i ] [ j ] != - 1 ) : NEW_LINE INDENT return dp [ i ] [ j ] NEW_LINE DEDENT dp [ i ] [ j ] = sys . maxsize NEW_LINE for k in range ( i , j ) : NEW_LINE INDENT dp [ i ] [ j ] = min ( dp [ i ] [ j ] , ( solve ( a , i , k ) + solve ( a , k + 1 , j ) + ( sum ( a , i , k ) * sum ( a , k + 1 , j ) ) ) ) NEW_LINE DEDENT return dp [ i ] [ j ] NEW_LINE DEDENT def intialize ( n ) : NEW_LINE INDENT for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] = - 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 40 , 60 , 20 ] NEW_LINE n = len ( a ) NEW_LINE intialize ( n ) NEW_LINE print ( int ( solve ( a , 0 , n - 1 ) ) ) NEW_LINE DEDENT


class Test { static void printCubes ( int a , int b ) { for ( int i = a ; i <= b ; i ++ ) { for ( int j = 1 ; j * j * j <= i ; j ++ ) { if ( j * j * j == i ) { System . out . print ( j * j * j + " ▁ ▁ " ) ; break ; } } } } public static void main ( String [ ] args ) { int a = 1 , b = 100 ; System . out . println ( " Perfect ▁ cubes ▁ in ▁ given ▁ range : " ) ; printCubes ( a , b ) ; } }

def printCubes ( a , b ) : NEW_LINE INDENT for i in range ( a , b + 1 ) : NEW_LINE INDENT j = 1 NEW_LINE for j in range ( j ** 3 , i + 1 ) : NEW_LINE INDENT if ( j ** 3 == i ) : NEW_LINE INDENT print ( j ** 3 , end = " ▁ " ) NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT DEDENT a = 1 ; b = 100 NEW_LINE print ( " Perfect ▁ cubes ▁ in ▁ given ▁ range : ▁ " ) NEW_LINE printCubes ( a , b ) NEW_LINE


class GFG { static int findNthDigit ( int p , int q , int N ) { int res = 0 ; while ( N > 0 ) { N -- ; p *= 10 ; res = p / q ; p %= q ; } return res ; } public static void main ( String args [ ] ) { int p = 1 , q = 2 , N = 1 ; System . out . println ( findNthDigit ( p , q , N ) ) ; } }

def findNthDigit ( p , q , N ) : NEW_LINE INDENT while ( N > 0 ) : NEW_LINE INDENT N -= 1 ; NEW_LINE p *= 10 ; NEW_LINE res = p // q ; NEW_LINE p %= q ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT p = 1 ; q = 2 ; N = 1 ; NEW_LINE print ( findNthDigit ( p , q , N ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static void printKMax ( int a [ ] , int n , int k ) { if ( k == 1 ) { for ( int i = 0 ; i < n ; i += 1 ) System . out . print ( a [ i ] + " ▁ " ) ; return ; } int p = 0 , q = k - 1 , t = p , max = a [ k - 1 ] ; while ( q <= n - 1 ) { if ( a [ p ] > max ) max = a [ p ] ; p += 1 ; if ( q == p && p != n ) { System . out . print ( max + " ▁ " ) ; q ++ ; p = ++ t ; if ( q < n ) max = a [ q ] ; } } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = a . length ; int K = 3 ; printKMax ( a , n , K ) ; } }

def printKMax ( a , n , k ) : NEW_LINE INDENT if ( k == 1 ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT return ; NEW_LINE DEDENT p = 0 ; NEW_LINE q = k - 1 ; NEW_LINE t = p ; NEW_LINE max = a [ k - 1 ] ; NEW_LINE while ( q <= n - 1 ) : NEW_LINE INDENT if ( a [ p ] > max ) : NEW_LINE INDENT max = a [ p ] ; NEW_LINE DEDENT p += 1 ; NEW_LINE if ( q == p and p != n ) : NEW_LINE INDENT print ( max , end = " ▁ " ) ; NEW_LINE q += 1 ; NEW_LINE p = t + 1 ; NEW_LINE if ( q < n ) : NEW_LINE INDENT max = a [ q ] ; NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; NEW_LINE n = len ( a ) ; NEW_LINE K = 3 ; NEW_LINE printKMax ( a , n , K ) ; NEW_LINE DEDENT


def multiply ( F , M ) : NEW_LINE INDENT x = F [ 0 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 0 ] NEW_LINE y = F [ 0 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 0 ] [ 1 ] * M [ 1 ] [ 1 ] NEW_LINE z = F [ 1 ] [ 0 ] * M [ 0 ] [ 0 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 0 ] NEW_LINE w = F [ 1 ] [ 0 ] * M [ 0 ] [ 1 ] + F [ 1 ] [ 1 ] * M [ 1 ] [ 1 ] NEW_LINE F [ 0 ] [ 0 ] = x NEW_LINE F [ 0 ] [ 1 ] = y NEW_LINE F [ 1 ] [ 0 ] = z NEW_LINE F [ 1 ] [ 1 ] = w NEW_LINE DEDENT def power ( F , n ) : NEW_LINE INDENT M = [ [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT multiply ( F , M ) NEW_LINE DEDENT DEDENT def fib ( n ) : NEW_LINE INDENT F = [ [ 1 , 1 ] , [ 1 , 0 ] ] NEW_LINE if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT power ( F , n - 1 ) NEW_LINE return F [ 0 ] [ 0 ] NEW_LINE DEDENT def leonardo ( n ) : NEW_LINE INDENT if ( n == 0 or n == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return ( 2 * fib ( n + 1 ) - 1 ) NEW_LINE DEDENT print ( leonardo ( 3 ) ) NEW_LINE


class GFG { static int sum ( int n ) { int sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } static int repeatedSum ( int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { n = sum ( n ) ; } return n ; } public static void main ( String [ ] args ) { int n = 2 , k = 2 ; System . out . println ( repeatedSum ( n , k ) ) ; } }

def summ ( n ) : NEW_LINE INDENT suum = ( n * ( n + 1 ) ) // 2 NEW_LINE return suum NEW_LINE DEDENT def repeatedSum ( n , k ) : NEW_LINE INDENT for i in range ( k ) : NEW_LINE INDENT n = summ ( n ) NEW_LINE DEDENT return n NEW_LINE DEDENT n = 2 NEW_LINE k = 2 NEW_LINE print ( repeatedSum ( n , k ) ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class GeeksforGeeks { static int sumOfDigits ( long x ) { int sum = 0 ; while ( x > 0 ) { sum += ( x % 10 ) ; x /= 10 ; } return sum ; } static void compute ( long n ) { long answer [ ] = new long [ 100 ] ; int pos = 0 ; for ( int i = 0 ; i <= 100 ; i ++ ) { long valueOnLeft = Math . abs ( n - i ) + sumOfDigits ( Math . abs ( n - i ) ) ; long valueOnRight = ( n + i ) + sumOfDigits ( n + i ) ; if ( valueOnRight == n ) answer [ pos ++ ] = ( n + i ) ; if ( valueOnLeft == n ) answer [ pos ++ ] = Math . abs ( n - i ) ; } if ( pos == 0 ) System . out . print ( - 1 ) ; else for ( int i = 0 ; i < pos ; i ++ ) System . out . println ( " X ▁ = ▁ " + answer [ i ] ) ; } public static void main ( String [ ] args ) { long N = 100000001 ; compute ( N ) ; } }

def sumOfDigits ( x ) : NEW_LINE INDENT sum = 0 ; NEW_LINE while ( x > 0 ) : NEW_LINE INDENT sum += ( x % 10 ) ; NEW_LINE x = int ( x / 10 ) ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT def compute ( n ) : NEW_LINE INDENT answer = [ ] ; NEW_LINE pos = 0 ; NEW_LINE for i in range ( 101 ) : NEW_LINE INDENT valueOnLeft = ( abs ( n - i ) + sumOfDigits ( abs ( n - i ) ) ) ; NEW_LINE valueOnRight = ( n + i ) + sumOfDigits ( n + i ) ; NEW_LINE if ( valueOnRight == n ) : NEW_LINE INDENT answer . append ( n + i ) ; NEW_LINE DEDENT if ( valueOnLeft == n ) : NEW_LINE INDENT answer . append ( abs ( n - i ) ) ; NEW_LINE DEDENT DEDENT if ( len ( answer ) == 0 ) : NEW_LINE INDENT print ( - 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( len ( answer ) ) : NEW_LINE INDENT print ( " X ▁ = " , answer [ i ] ) ; NEW_LINE DEDENT DEDENT DEDENT N = 100000001 ; NEW_LINE compute ( N ) ; NEW_LINE


class GFG { static int findPowerPrime ( int fact , int p ) { int res = 0 ; while ( fact > 0 ) { res += fact / p ; fact /= p ; } return res ; } static int findPowerComposite ( int fact , int n ) { int res = Integer . MAX_VALUE ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { int count = 0 ; if ( n % i == 0 ) { count ++ ; n = n / i ; } if ( count > 0 ) { int curr_pow = findPowerPrime ( fact , i ) / count ; res = Math . min ( res , curr_pow ) ; } } if ( n >= 2 ) { int curr_pow = findPowerPrime ( fact , n ) ; res = Math . min ( res , curr_pow ) ; } return res ; } public static void main ( String [ ] args ) { int fact = 146 , n = 5 ; System . out . println ( findPowerComposite ( fact , n ) ) ; } }

import math NEW_LINE def findPowerPrime ( fact , p ) : NEW_LINE INDENT res = 0 NEW_LINE while fact : NEW_LINE INDENT res += fact // p NEW_LINE fact //= p NEW_LINE DEDENT return res NEW_LINE DEDENT def findPowerComposite ( fact , n ) : NEW_LINE INDENT res = math . inf NEW_LINE for i in range ( 2 , int ( n ** 0.5 ) + 1 ) : NEW_LINE INDENT count = 0 NEW_LINE if not n % i : NEW_LINE INDENT count += 1 NEW_LINE n = n // i NEW_LINE DEDENT if count : NEW_LINE INDENT curr_pow = findPowerPrime ( fact , i ) // count NEW_LINE res = min ( res , curr_pow ) NEW_LINE DEDENT DEDENT if n >= 2 : NEW_LINE INDENT curr_pow = findPowerPrime ( fact , n ) NEW_LINE res = min ( res , curr_pow ) NEW_LINE DEDENT return res NEW_LINE DEDENT fact = 146 ; n = 5 NEW_LINE print ( findPowerComposite ( fact , n ) ) NEW_LINE


class GFG { static final int size = 10001 ; static long [ ] fib = new long [ 100010 ] ; static int [ ] freq = new int [ 100010 ] ; static boolean isPerfectSquare ( int x ) { int s = ( int ) Math . sqrt ( x ) ; return ( s * s == x ) ; } static int isFibonacci ( int n ) { if ( isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ) return 1 ; return 0 ; } static void compute ( int a , int b ) { for ( int i = 1 ; i < 100010 ; i ++ ) { fib [ i ] = isFibonacci ( i ) ; } for ( int x = 1 ; x < 100010 ; x ++ ) { for ( int y = 1 ; y < size ; y ++ ) { if ( fib [ x ] == 1 && fib [ y ] == 1 && a * x + b * y < 100010 ) { freq [ a * x + b * y ] ++ ; } } } } public static void main ( String [ ] args ) { int Q = 2 , A = 5 , B = 10 ; compute ( A , B ) ; int arr [ ] = { 50 , 150 } ; for ( int i = 0 ; i < Q ; i ++ ) { System . out . print ( freq [ arr [ i ] ] + " ▁ " ) ; } } }

import math NEW_LINE size = 101 NEW_LINE fib = [ 0 ] * 100010 NEW_LINE freq = [ 0 ] * ( 100010 ) NEW_LINE def isPerfectSquare ( x ) : NEW_LINE INDENT s = int ( math . sqrt ( x ) ) NEW_LINE return ( s * s ) == x NEW_LINE DEDENT def isFibonacci ( n ) : NEW_LINE INDENT if ( isPerfectSquare ( 5 * n * n + 4 ) or isPerfectSquare ( 5 * n * n - 4 ) ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT def compute ( a , b ) : NEW_LINE INDENT for i in range ( 1 , 100010 ) : NEW_LINE INDENT fib [ i ] = isFibonacci ( i ) NEW_LINE DEDENT for x in range ( 1 , 100010 ) : NEW_LINE INDENT for y in range ( 1 , size ) : NEW_LINE INDENT if ( fib [ x ] == 1 and fib [ y ] == 1 and a * x + b * y < 100010 ) : NEW_LINE INDENT freq [ a * x + b * y ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT Q = 2 NEW_LINE A = 5 NEW_LINE B = 10 NEW_LINE compute ( A , B ) ; NEW_LINE arr = [ 50 , 150 ] NEW_LINE for i in range ( Q ) : NEW_LINE INDENT print ( freq [ arr [ i ] ] , end = " ▁ " ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int MAX = 100 ; static int recur ( int ind , int cnt , int last , int a [ ] , int n , int k , int dp [ ] [ ] ) { if ( cnt == k ) return 0 ; if ( ind == n ) return ( int ) - 1e9 ; if ( dp [ ind ] [ cnt ] != - 1 ) return dp [ ind ] [ cnt ] ; int ans = 0 ; for ( int i = ind ; i < n ; i ++ ) { if ( cnt % 2 == 0 ) ans = Math . max ( ans , recur ( i + 1 , cnt + 1 , i , a , n , k , dp ) ) ; else ans = Math . max ( ans , __gcd ( a [ last ] , a [ i ] ) + recur ( i + 1 , cnt + 1 , 0 , a , n , k , dp ) ) ; } return dp [ ind ] [ cnt ] = ans ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int a [ ] = { 4 , 5 , 3 , 7 , 8 , 10 , 9 , 8 } ; int n = a . length ; int k = 4 ; int [ ] [ ] dp = new int [ n ] [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } System . out . println ( recur ( 0 , 0 , 0 , a , n , k , dp ) ) ; } }

from math import gcd as __gcd NEW_LINE MAX = 100 NEW_LINE def recur ( ind , cnt , last , a , n , k , dp ) : NEW_LINE INDENT if ( cnt == k ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( ind == n ) : NEW_LINE INDENT return - 10 ** 9 NEW_LINE DEDENT if ( dp [ ind ] [ cnt ] != - 1 ) : NEW_LINE INDENT return dp [ ind ] [ cnt ] NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( ind , n ) : NEW_LINE INDENT if ( cnt % 2 == 0 ) : NEW_LINE INDENT ans = max ( ans , recur ( i + 1 , cnt + 1 , i , a , n , k , dp ) ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = max ( ans , __gcd ( a [ last ] , a [ i ] ) + recur ( i + 1 , cnt + 1 , 0 , a , n , k , dp ) ) NEW_LINE DEDENT DEDENT dp [ ind ] [ cnt ] = ans NEW_LINE return ans NEW_LINE DEDENT a = [ 4 , 5 , 3 , 7 , 8 , 10 , 9 , 8 ] NEW_LINE n = len ( a ) NEW_LINE k = 4 ; NEW_LINE dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( n ) ] NEW_LINE print ( recur ( 0 , 0 , 0 , a , n , k , dp ) ) NEW_LINE


class GFG { static final int MAX = 10 ; static void binomialCoeff ( int C [ ] [ ] , int n , int k ) { for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } } static int countParallelogram ( int n , int m ) { int C [ ] [ ] = new int [ MAX ] [ MAX ] ; binomialCoeff ( C , Math . max ( n , m ) , 2 ) ; return C [ n ] [ 2 ] * C [ m ] [ 2 ] ; } public static void main ( String arg [ ] ) { int n = 5 , m = 5 ; System . out . println ( countParallelogram ( n , m ) ) ; } }

MAX = 10 ; NEW_LINE def binomialCoeff ( C , n , k ) : NEW_LINE INDENT for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( 0 , min ( i , k ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; NEW_LINE DEDENT DEDENT DEDENT DEDENT def countParallelogram ( n , m ) : NEW_LINE INDENT C = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ] NEW_LINE binomialCoeff ( C , max ( n , m ) , 2 ) ; NEW_LINE return C [ n ] [ 2 ] * C [ m ] [ 2 ] ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 ; NEW_LINE m = 5 ; NEW_LINE print ( countParallelogram ( n , m ) ) ; NEW_LINE DEDENT


class GFG { static int countSetBits ( int n ) { int count = 0 ; while ( n > 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } static int pairs ( int arr [ ] , int n , int k ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = countSetBits ( arr [ i ] ) + countSetBits ( arr [ j ] ) ; if ( sum == k ) count ++ ; } } return count ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; int k = 4 ; System . out . println ( pairs ( arr , n , k ) ) ; } }

def countSetBits ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n ) : NEW_LINE INDENT n &= ( n - 1 ) ; NEW_LINE count += 1 NEW_LINE DEDENT return count ; NEW_LINE DEDENT def pairs ( arr , n , k ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT sum = countSetBits ( arr [ i ] ) + countSetBits ( arr [ j ] ) ; NEW_LINE if ( sum == k ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE k = 4 ; NEW_LINE print ( pairs ( arr , n , k ) ) ; NEW_LINE DEDENT


import java . lang . Math ; class GFG { public static int nthTerm ( int N ) { int nth = 0 , i ; for ( i = N ; i > 0 ; i -- ) { nth += Math . pow ( i , i ) ; } return nth ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( nthTerm ( N ) ) ; } }

def nthTerm ( N ) : NEW_LINE INDENT nth = 0 NEW_LINE for i in range ( N , 0 , - 1 ) : NEW_LINE INDENT nth += pow ( i , i ) NEW_LINE DEDENT return nth NEW_LINE DEDENT N = 3 NEW_LINE print ( nthTerm ( N ) ) NEW_LINE


import java . lang . Math ; class GFG { public static int findNth ( int n ) { int nthElement = 19 + ( n - 1 ) * 9 ; int outliersCount = ( int ) Math . log10 ( nthElement ) - 1 ; nthElement += 9 * outliersCount ; return nthElement ; } public static void main ( String [ ] args ) { System . out . println ( findNth ( 5 ) ) ; } }

import math NEW_LINE def findNth ( n ) : NEW_LINE INDENT nthElement = 19 + ( n - 1 ) * 9 NEW_LINE outliersCount = int ( math . log10 ( nthElement ) ) - 1 NEW_LINE nthElement += 9 * outliersCount NEW_LINE return nthElement NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( findNth ( 5 ) ) NEW_LINE DEDENT


class GFG { static long difference ( long M , long N ) { return M + N ; } public static void main ( String [ ] args ) { long M = 999999999 ; long N = 1000000000 ; System . out . print ( difference ( M , N ) + " \n " ) ; } }

def difference ( M , N ) : NEW_LINE INDENT return M + N NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M = 999999999 NEW_LINE N = 1000000000 NEW_LINE print ( difference ( M , N ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int catalanDP ( int n ) { int [ ] catalan = new int [ n + 1 ] ; catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( int j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } static int countWays ( int n ) { if ( n < 1 ) { System . out . println ( " Invalid " ) ; return 0 ; } return catalanDP ( n / 2 ) ; } public static void main ( String [ ] args ) { System . out . println ( countWays ( 6 ) + " ▁ " ) ; } }

def catalanDP ( n ) : NEW_LINE INDENT catalan = [ 1 for i in range ( n + 1 ) ] NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT catalan [ i ] = 0 NEW_LINE for j in range ( i ) : NEW_LINE INDENT catalan [ i ] += ( catalan [ j ] * catalan [ i - j - 1 ] ) NEW_LINE DEDENT DEDENT return catalan [ n ] NEW_LINE DEDENT def countWays ( n ) : NEW_LINE INDENT if ( n & 1 ) : NEW_LINE INDENT print ( " Invalid " ) NEW_LINE return 0 NEW_LINE DEDENT return catalanDP ( n // 2 ) NEW_LINE DEDENT print ( countWays ( 6 ) ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; public class GFG { static int nthTerm ( int n ) { int d = 2 , a1 = 0 ; int An = a1 + ( n - 1 ) * d ; return ( int ) Math . pow ( An , 3 ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( nthTerm ( n ) ) ; } }

def term ( n ) : NEW_LINE INDENT d = 2 NEW_LINE a1 = 0 NEW_LINE An = a1 + ( n - 1 ) * d NEW_LINE An = An ** 3 NEW_LINE return An ; NEW_LINE DEDENT n = 5 NEW_LINE print ( term ( n ) ) NEW_LINE


class GFG { public static int findMaxGCD ( int arr [ ] , int n ) { int high = 0 ; for ( int i = 0 ; i < n ; i ++ ) high = Math . max ( high , arr [ i ] ) ; int divisors [ ] = new int [ high + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 1 ; j <= Math . sqrt ( arr [ i ] ) ; j ++ ) { if ( arr [ i ] % j == 0 ) { divisors [ j ] ++ ; if ( j != arr [ i ] / j ) divisors [ arr [ i ] / j ] ++ ; } } } for ( int i = high ; i >= 1 ; i -- ) if ( divisors [ i ] > 1 ) return i ; return 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 8 , 8 , 12 } ; int n = arr . length ; System . out . println ( findMaxGCD ( arr , n ) ) ; } }

import math NEW_LINE def findMaxGCD ( arr , n ) : NEW_LINE INDENT high = 0 NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT high = max ( high , arr [ i ] ) NEW_LINE i = i + 1 NEW_LINE DEDENT divisors = [ 0 ] * ( high + 1 ) NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT j = 1 NEW_LINE while j <= math . sqrt ( arr [ i ] ) : NEW_LINE INDENT if ( arr [ i ] % j == 0 ) : NEW_LINE INDENT divisors [ j ] = divisors [ j ] + 1 NEW_LINE if ( j != arr [ i ] / j ) : NEW_LINE INDENT divisors [ arr [ i ] / j ] = divisors [ arr [ i ] / j ] NEW_LINE INDENT + 1 NEW_LINE DEDENT DEDENT DEDENT j = j + 1 NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT i = high NEW_LINE while i >= 1 : NEW_LINE INDENT if ( divisors [ i ] > 1 ) : NEW_LINE INDENT return i NEW_LINE DEDENT i = i - 1 NEW_LINE DEDENT return 1 NEW_LINE DEDENT arr = [ 1 , 2 , 4 , 8 , 8 , 12 ] NEW_LINE n = len ( arr ) NEW_LINE print findMaxGCD ( arr , n ) NEW_LINE


import java . util . * ; import java . lang . * ; public class GFG { public static int findRepeatFirst ( String s ) { int p = - 1 , i , k ; int MAX_CHAR = 256 ; int hash [ ] = new int [ MAX_CHAR ] ; int pos [ ] = new int [ MAX_CHAR ] ; for ( i = 0 ; i < s . length ( ) ; i ++ ) { k = ( int ) s . charAt ( i ) ; if ( hash [ k ] == 0 ) { hash [ k ] ++ ; pos [ k ] = i ; } else if ( hash [ k ] == 1 ) hash [ k ] ++ ; } for ( i = 0 ; i < MAX_CHAR ; i ++ ) { if ( hash [ i ] == 2 ) { if ( p == - 1 ) p = pos [ i ] ; else if ( p > pos [ i ] ) p = pos [ i ] ; } } return p ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int pos = findRepeatFirst ( str ) ; if ( pos == - 1 ) System . out . println ( " Not ▁ found " ) ; else System . out . println ( str . charAt ( pos ) ) ; } }

MAX_CHAR = 256 NEW_LINE def findRepeatFirst ( s ) : NEW_LINE INDENT p = - 1 NEW_LINE hash = [ 0 for i in range ( MAX_CHAR ) ] NEW_LINE pos = [ 0 for i in range ( MAX_CHAR ) ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT k = ord ( s [ i ] ) NEW_LINE if ( hash [ k ] == 0 ) : NEW_LINE INDENT hash [ k ] += 1 NEW_LINE pos [ k ] = i NEW_LINE DEDENT elif ( hash [ k ] == 1 ) : NEW_LINE INDENT hash [ k ] += 1 NEW_LINE DEDENT DEDENT for i in range ( MAX_CHAR ) : NEW_LINE INDENT if ( hash [ i ] == 2 ) : NEW_LINE INDENT if ( p == - 1 ) : NEW_LINE INDENT p = pos [ i ] NEW_LINE DEDENT elif ( p > pos [ i ] ) : NEW_LINE INDENT p = pos [ i ] NEW_LINE DEDENT DEDENT DEDENT return p NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " geeksforgeeks " NEW_LINE pos = findRepeatFirst ( str ) ; NEW_LINE if ( pos == - 1 ) : NEW_LINE INDENT print ( " Not ▁ found " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( str [ pos ] ) NEW_LINE DEDENT DEDENT


import java . util . Arrays ; public class GFG { static void rearrangeArray ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int [ ] tempArr = new int [ n ] ; int ArrIndex = 0 ; for ( int i = 0 , j = n - 1 ; i <= n / 2 || j > n / 2 ; i ++ , j -- ) { if ( ArrIndex < n ) { tempArr [ ArrIndex ] = arr [ i ] ; ArrIndex ++ ; } if ( ArrIndex < n ) { tempArr [ ArrIndex ] = arr [ j ] ; ArrIndex ++ ; } } for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = tempArr [ i ] ; } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 8 , 1 , 4 , 2 , 9 , 3 , 7 , 6 } ; int n = arr . length ; rearrangeArray ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

def rearrangeArray ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE tempArr = [ 0 ] * ( n + 1 ) NEW_LINE ArrIndex = 0 NEW_LINE i = 0 NEW_LINE j = n - 1 NEW_LINE while ( i <= n // 2 or j > n // 2 ) : NEW_LINE INDENT tempArr [ ArrIndex ] = arr [ i ] NEW_LINE ArrIndex = ArrIndex + 1 NEW_LINE tempArr [ ArrIndex ] = arr [ j ] NEW_LINE ArrIndex = ArrIndex + 1 NEW_LINE i = i + 1 NEW_LINE j = j - 1 NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT arr [ i ] = tempArr [ i ] NEW_LINE DEDENT DEDENT arr = [ 5 , 8 , 1 , 4 , 2 , 9 , 3 , 7 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE rearrangeArray ( arr , n ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static int countgroup ( int a [ ] , int n ) { int xs = 0 ; for ( int i = 0 ; i < n ; i ++ ) xs = xs ^ a [ i ] ; if ( xs == 0 ) return ( 1 << ( n - 1 ) ) - 1 ; return 0 ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 2 , 3 } ; int n = a . length ; System . out . println ( countgroup ( a , n ) ) ; } }

def countgroup ( a , n ) : NEW_LINE INDENT xs = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT xs = xs ^ a [ i ] NEW_LINE DEDENT if xs == 0 : NEW_LINE INDENT return ( 1 << ( n - 1 ) ) - 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT a = [ 1 , 2 , 3 ] NEW_LINE n = len ( a ) NEW_LINE print ( countgroup ( a , n ) ) NEW_LINE


class GFG { static int reverse ( int n ) { int rev = 0 ; while ( n > 0 ) { int d = n % 10 ; rev = rev * 10 + d ; n = n / 10 ; } return rev ; } static boolean isPalin ( int n ) { return ( n == reverse ( n ) ) ; } static int countDigits ( int n ) { int c = 0 ; while ( n > 0 ) { n = n / 10 ; c ++ ; } return c ; } static int countPalinDigits ( int [ ] arr , int n ) { int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < 10 || isPalin ( arr [ i ] ) ) { s += countDigits ( arr [ i ] ) ; } } return s ; } public static void main ( String [ ] args ) { int [ ] arr = { 121 , 56 , 434 } ; int n = arr . length ; System . out . println ( countPalinDigits ( arr , n ) ) ; } }

def reverse ( n ) : NEW_LINE INDENT rev = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT d = n % 10 ; NEW_LINE rev = rev * 10 + d ; NEW_LINE n = n // 10 ; NEW_LINE DEDENT return rev ; NEW_LINE DEDENT def isPalin ( n ) : NEW_LINE INDENT return ( n == reverse ( n ) ) ; NEW_LINE DEDENT def countDigits ( n ) : NEW_LINE INDENT c = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT n = n // 10 ; NEW_LINE c += 1 ; NEW_LINE DEDENT return c ; NEW_LINE DEDENT def countPalinDigits ( arr , n ) : NEW_LINE INDENT s = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] < 10 or isPalin ( arr [ i ] ) ) : NEW_LINE INDENT s += countDigits ( arr [ i ] ) ; NEW_LINE DEDENT DEDENT return s ; NEW_LINE DEDENT arr = [ 121 , 56 , 434 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( countPalinDigits ( arr , n ) ) ; NEW_LINE


import java . util . Stack ; public class GFG { static boolean checkRedundancy ( String s ) { Stack < Character > st = new Stack < > ( ) ; char [ ] str = s . toCharArray ( ) ; for ( char ch : str ) { if ( ch == ' ) ' ) { char top = st . peek ( ) ; st . pop ( ) ; boolean flag = true ; while ( top != ' ( ' ) { if ( top == ' + ' || top == ' - ' || top == ' * ' || top == ' / ' ) { flag = false ; } top = st . peek ( ) ; st . pop ( ) ; } if ( flag == true ) { return true ; } } else { st . push ( ch ) ; } } return false ; } static void findRedundant ( String str ) { boolean ans = checkRedundancy ( str ) ; if ( ans == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { String str = " ( ( a + b ) ) " ; findRedundant ( str ) ; str = " ( a + ( b ) / c ) " ; findRedundant ( str ) ; str = " ( a + b * ( c - d ) ) " ; findRedundant ( str ) ; } }

def checkRedundancy ( Str ) : NEW_LINE INDENT st = [ ] NEW_LINE for ch in Str : NEW_LINE INDENT if ( ch == ' ) ' ) : NEW_LINE INDENT top = st [ - 1 ] NEW_LINE st . pop ( ) NEW_LINE flag = True NEW_LINE while ( top != ' ( ' ) : NEW_LINE INDENT if ( top == ' + ' or top == ' - ' or top == ' * ' or top == ' / ' ) : NEW_LINE INDENT flag = False NEW_LINE DEDENT top = st [ - 1 ] NEW_LINE st . pop ( ) NEW_LINE DEDENT if ( flag == True ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT st . append ( ch ) NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def findRedundant ( Str ) : NEW_LINE INDENT ans = checkRedundancy ( Str ) NEW_LINE if ( ans == True ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT Str = " ( ( a + b ) ) " NEW_LINE findRedundant ( Str ) NEW_LINE Str = " ( a + ( b ) / c ) " NEW_LINE findRedundant ( Str ) NEW_LINE Str = " ( a + b * ( c - d ) ) " NEW_LINE findRedundant ( Str ) NEW_LINE DEDENT


class GFG { static void find ( int a [ ] , int n ) { int count_odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 != 0 ) { count_odd += 1 ; } } int result = ( int ) ( Math . pow ( 2 , n ) - 1 ) ; result -= ( Math . pow ( 2 , count_odd ) - 1 ) ; System . out . println ( result ) ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 2 , 3 } ; int n = a . length ; find ( a , n ) ; } }

import math as ma NEW_LINE def find ( a ) : NEW_LINE INDENT count_odd = 0 NEW_LINE for i in a : NEW_LINE INDENT if ( i % 2 != 0 ) : NEW_LINE INDENT count_odd += 1 NEW_LINE DEDENT DEDENT result = pow ( 2 , len ( a ) ) - 1 NEW_LINE result = result - ( pow ( 2 , count_odd ) - 1 ) NEW_LINE print ( result ) NEW_LINE DEDENT a = [ 2 , 2 , 3 ] NEW_LINE find ( a ) NEW_LINE


class GFG { static int maxDiff ( int arr [ ] , int n ) { int diff = arr [ 1 ] - arr [ 0 ] ; int curr_sum = diff ; int max_sum = curr_sum ; for ( int i = 1 ; i < n - 1 ; i ++ ) { diff = arr [ i + 1 ] - arr [ i ] ; if ( curr_sum > 0 ) curr_sum += diff ; else curr_sum = diff ; if ( curr_sum > max_sum ) max_sum = curr_sum ; } return max_sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 80 , 2 , 6 , 3 , 100 } ; int n = arr . length ; System . out . print ( " Maximum ▁ difference ▁ is ▁ " + maxDiff ( arr , n ) ) ; } }

def maxDiff ( arr , n ) : NEW_LINE INDENT diff = arr [ 1 ] - arr [ 0 ] NEW_LINE curr_sum = diff NEW_LINE max_sum = curr_sum NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT diff = arr [ i + 1 ] - arr [ i ] NEW_LINE if ( curr_sum > 0 ) : NEW_LINE INDENT curr_sum += diff NEW_LINE DEDENT else : NEW_LINE INDENT curr_sum = diff NEW_LINE DEDENT if ( curr_sum > max_sum ) : NEW_LINE INDENT max_sum = curr_sum NEW_LINE DEDENT DEDENT return max_sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 80 , 2 , 6 , 3 , 100 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , n ) ) NEW_LINE DEDENT


class GFG { static void solve ( char [ ] a , char [ ] b ) { int l = a . length ; int min = 0 , max = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( a [ i ] == ' + ' || b [ i ] == ' + ' || a [ i ] != b [ i ] ) max ++ ; if ( a [ i ] != ' + ' && b [ i ] != ' + ' && a [ i ] != b [ i ] ) min ++ ; } System . out . print ( min + max + " \n " ) ; } public static void main ( String [ ] args ) { String s1 = " a + c " , s2 = " + + b " ; solve ( s1 . toCharArray ( ) , s2 . toCharArray ( ) ) ; } }

def solve ( a , b ) : NEW_LINE INDENT l = len ( a ) NEW_LINE min = 0 NEW_LINE max = 0 NEW_LINE for i in range ( l ) : NEW_LINE INDENT if ( a [ i ] == ' + ' or b [ i ] == ' + ' or a [ i ] != b [ i ] ) : NEW_LINE INDENT max += 1 NEW_LINE DEDENT if ( a [ i ] != ' + ' and b [ i ] != ' + ' and a [ i ] != b [ i ] ) : NEW_LINE INDENT min += 1 NEW_LINE DEDENT DEDENT print ( min + max ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s1 = " a + c " NEW_LINE s2 = " + + b " NEW_LINE solve ( s1 , s2 ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int findMinX ( int num [ ] , int rem [ ] , int k ) { int x = 1 ; while ( true ) { int j ; for ( j = 0 ; j < k ; j ++ ) if ( x % num [ j ] != rem [ j ] ) break ; if ( j == k ) return x ; x ++ ; } } public static void main ( String args [ ] ) { int num [ ] = { 3 , 4 , 5 } ; int rem [ ] = { 2 , 3 , 1 } ; int k = num . length ; System . out . println ( " x ▁ is ▁ " + findMinX ( num , rem , k ) ) ; } }

def findMinX ( num , rem , k ) : NEW_LINE INDENT x = 1 ; NEW_LINE while ( True ) : NEW_LINE INDENT j = 0 ; NEW_LINE while ( j < k ) : NEW_LINE INDENT if ( x % num [ j ] != rem [ j ] ) : NEW_LINE INDENT break ; NEW_LINE DEDENT j += 1 ; NEW_LINE DEDENT if ( j == k ) : NEW_LINE INDENT return x ; NEW_LINE DEDENT x += 1 ; NEW_LINE DEDENT DEDENT num = [ 3 , 4 , 5 ] ; NEW_LINE rem = [ 2 , 3 , 1 ] ; NEW_LINE k = len ( num ) ; NEW_LINE print ( " x ▁ is " , findMinX ( num , rem , k ) ) ; NEW_LINE


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

import math NEW_LINE def sumOfSeries ( n ) : NEW_LINE INDENT return int ( ( n * ( 2 * n - 1 ) * ( 2 * n + 1 ) ) / 3 ) NEW_LINE DEDENT n = 10 NEW_LINE print ( sumOfSeries ( n ) ) NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static int findMinEqualSums ( int [ ] a , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; } int sum1 = 0 , sum2 = 0 ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { sum1 += a [ i ] ; sum2 = sum - sum1 ; if ( Math . abs ( sum1 - sum2 ) < min ) { min = Math . abs ( sum1 - sum2 ) ; } if ( min == 0 ) { break ; } } return min ; } public static void main ( String args [ ] ) { int [ ] a = { 3 , 2 , 1 , 5 , 7 , 8 } ; int N = a . length ; System . out . println ( findMinEqualSums ( a , N ) ) ; } }

import sys NEW_LINE def findMinEqualSums ( a , N ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT sum = sum + a [ i ] NEW_LINE DEDENT sum1 = 0 NEW_LINE sum2 = 0 NEW_LINE min = sys . maxsize NEW_LINE for i in range ( 0 , N - 1 ) : NEW_LINE INDENT sum1 += a [ i ] NEW_LINE sum2 = sum - sum1 NEW_LINE if ( abs ( sum1 - sum2 ) < min ) : NEW_LINE INDENT min = abs ( sum1 - sum2 ) NEW_LINE DEDENT if ( min == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT return min NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 3 , 2 , 1 , 5 , 7 , 8 ] NEW_LINE N = len ( a ) NEW_LINE print ( findMinEqualSums ( a , N ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static int DP_s = 9 ; static int getNumStrictMonotone ( int len ) { int [ ] [ ] DP = new int [ len ] [ DP_s ] ; for ( int i = 0 ; i < DP_s ; ++ i ) DP [ 0 ] [ i ] = i + 1 ; for ( int i = 1 ; i < len ; ++ i ) for ( int j = 1 ; j < DP_s ; ++ j ) DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] ; return DP [ len - 1 ] [ DP_s - 1 ] ; } public static void main ( String [ ] args ) { int n = 2 ; System . out . println ( getNumStrictMonotone ( n ) ) ; } }

DP_s = 9 NEW_LINE def getNumStrictMonotone ( ln ) : NEW_LINE INDENT DP = [ [ 0 ] * DP_s for _ in range ( ln ) ] NEW_LINE for i in range ( DP_s ) : NEW_LINE INDENT DP [ 0 ] [ i ] = i + 1 NEW_LINE DEDENT for i in range ( 1 , ln ) : NEW_LINE INDENT for j in range ( 1 , DP_s ) : NEW_LINE INDENT DP [ i ] [ j ] = DP [ i - 1 ] [ j - 1 ] + DP [ i ] [ j - 1 ] NEW_LINE DEDENT DEDENT return DP [ ln - 1 ] [ DP_s - 1 ] NEW_LINE DEDENT print ( getNumStrictMonotone ( 2 ) ) NEW_LINE


class GFG { static int countDivisors ( int n ) { int count = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) count ++ ; else count += 2 ; } } return count ; } static int MaximumDivisors ( int X , int Y ) { int maxDivisors = 0 , result = 0 ; int [ ] arr = new int [ Y - X + 1 ] ; for ( int i = X ; i <= Y ; i ++ ) { int Div = countDivisors ( i ) ; arr [ i - X ] = Div ; maxDivisors = Math . max ( Div , maxDivisors ) ; } for ( int i = 0 ; i < ( Y - X + 1 ) ; i ++ ) if ( arr [ i ] == maxDivisors ) result ++ ; return result ; } public static void main ( String [ ] args ) { int X = 1 , Y = 10 ; System . out . println ( MaximumDivisors ( X , Y ) ) ; } }

from math import * NEW_LINE def countDivisors ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , int ( sqrt ( n ) + 1 ) ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT if n / i == i : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count += 2 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT def MaximumDivisors ( X , Y ) : NEW_LINE INDENT result = 0 NEW_LINE maxDivisors = 0 NEW_LINE arr = [ ] NEW_LINE for i in range ( Y - X + 1 ) : NEW_LINE INDENT arr . append ( 0 ) NEW_LINE DEDENT for i in range ( X , Y + 1 ) : NEW_LINE INDENT Div = countDivisors ( i ) NEW_LINE arr [ i - X ] = Div NEW_LINE maxDivisors = max ( Div , maxDivisors ) NEW_LINE DEDENT for i in range ( Y - X + 1 ) : NEW_LINE INDENT if arr [ i ] == maxDivisors : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X , Y = 1 , 10 NEW_LINE print ( MaximumDivisors ( X , Y ) ) NEW_LINE DEDENT


class GFG { static int largestPower ( int x , int P ) { int res = 0 ; while ( x != 0 ) { x /= P ; res += x ; } return res ; } static int sumOfDivisblePowers ( int L , int R , int P ) { return largestPower ( R , P ) - largestPower ( L - 1 , P ) ; } public static void main ( String [ ] args ) { int L = 1 , R = 10 , P = 2 ; System . out . println ( sumOfDivisblePowers ( L , R , P ) ) ; } }

def largestPower ( x , P ) : NEW_LINE INDENT res = 0 NEW_LINE while ( x ) : NEW_LINE INDENT x = int ( x / P ) NEW_LINE res += x NEW_LINE DEDENT return res NEW_LINE DEDENT def sumOfDivisblePowers ( L , R , P ) : NEW_LINE INDENT return largestPower ( R , P ) - largestPower ( L - 1 , P ) NEW_LINE DEDENT L = 1 NEW_LINE R = 10 NEW_LINE P = 2 NEW_LINE print ( sumOfDivisblePowers ( L , R , P ) ) NEW_LINE


class GFG { static void print ( int n ) { System . out . println ( n + n / 2 ) ; for ( int i = 2 ; i <= n ; i += 2 ) System . out . print ( i + " ▁ " ) ; for ( int i = 1 ; i <= n ; i += 2 ) System . out . print ( i + " ▁ " ) ; for ( int i = 2 ; i <= n ; i += 2 ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 3 ; print ( n ) ; } }

def bomb_required ( n ) : NEW_LINE INDENT print ( n + n // 2 ) NEW_LINE for i in range ( 2 , n + 1 , 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT for i in range ( 1 , n + 1 , 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT for i in range ( 2 , n , 2 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT bomb_required ( 3 ) NEW_LINE


class GFG { static int addOne ( int x ) { int m = 1 ; while ( ( int ) ( x & m ) >= 1 ) { x = x ^ m ; m <<= 1 ; } x = x ^ m ; return x ; } public static void main ( String [ ] args ) { System . out . println ( addOne ( 13 ) ) ; } }

def addOne ( x ) : NEW_LINE INDENT m = 1 ; NEW_LINE while ( x & m ) : NEW_LINE INDENT x = x ^ m NEW_LINE m <<= 1 NEW_LINE DEDENT x = x ^ m NEW_LINE return x NEW_LINE DEDENT n = 13 NEW_LINE print addOne ( n ) NEW_LINE


class GFG { static int largestNum ( int num ) { int max_digit = - 1 ; int max_digit_indx = - 1 ; int l_indx = - 1 ; int r_indx = 1 ; String num_in_str = String . valueOf ( num ) ; for ( int i = num_in_str . length ( ) - 1 ; i >= 0 ; i -- ) { if ( num_in_str . charAt ( r_indx ) > max_digit ) { max_digit = num_in_str . charAt ( i ) ; max_digit_indx = i ; continue ; } if ( num_in_str . charAt ( i ) < max_digit ) { l_indx = i ; r_indx = max_digit_indx ; } } if ( l_indx == - 1 ) return num ; num_in_str = swap ( num_in_str , l_indx , r_indx ) ; return Integer . parseInt ( num_in_str ) ; } static String swap ( String arr , int i , int j ) { char temp [ ] = arr . toCharArray ( ) ; char c = temp [ i ] ; temp [ i ] = temp [ j ] ; temp [ j ] = c ; return String . valueOf ( temp ) ; } public static void main ( String [ ] args ) { int num = 789 ; System . out . println ( largestNum ( num ) ) ; num = 49658 ; System . out . println ( largestNum ( num ) ) ; num = 2135 ; System . out . println ( largestNum ( num ) ) ; } }

def largestNum ( num ) : NEW_LINE INDENT max_digit = - 1 NEW_LINE max_digit_indx = - 1 NEW_LINE l_indx = - 1 NEW_LINE r_indx = 1 NEW_LINE num_in_str = list ( str ( num ) ) NEW_LINE for i in range ( len ( num_in_str ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT if int ( num_in_str [ r_indx ] ) > int ( max_digit ) : NEW_LINE INDENT max_digit = num_in_str [ i ] NEW_LINE max_digit_indx = i NEW_LINE continue NEW_LINE DEDENT if int ( num_in_str [ i ] ) < int ( max_digit ) : NEW_LINE INDENT l_indx = i NEW_LINE r_indx = max_digit_indx NEW_LINE DEDENT DEDENT if l_indx == - 1 : NEW_LINE INDENT return num NEW_LINE DEDENT num_in_str [ l_indx ] , num_in_str [ r_indx ] =   \ NEW_LINE num_in_str [ r_indx ] , num_in_str [ l_indx ] NEW_LINE return int ( ' ' . join ( num_in_str ) ) NEW_LINE DEDENT num = 789 NEW_LINE print ( largestNum ( num ) ) NEW_LINE num = 49658 NEW_LINE print ( largestNum ( num ) ) NEW_LINE num = 2135 NEW_LINE print ( largestNum ( num ) ) NEW_LINE


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

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


class GFG { static String canMake ( String s ) { int o = 0 , z = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) - '0' == 1 ) o ++ ; else z ++ ; } if ( o % 2 == 1 && z % 2 == 1 ) return " NO " ; else return " YES " ; } public static void main ( String [ ] args ) { String s = "01011" ; System . out . println ( canMake ( s ) ) ; } }

def canMake ( s ) : NEW_LINE INDENT o = 0 ; z = 0 ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( ord ( s [ i ] ) - ord ( '0' ) == 1 ) : NEW_LINE INDENT o += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT z += 1 ; NEW_LINE DEDENT DEDENT if ( o % 2 == 1 and z % 2 == 1 ) : NEW_LINE INDENT return " NO " ; NEW_LINE DEDENT else : NEW_LINE INDENT return " YES " ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "01011" ; NEW_LINE print ( canMake ( s ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static int getMin ( int arr [ ] , int n ) { int minVal = Arrays . stream ( arr ) . min ( ) . getAsInt ( ) ; return minVal ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 1 , 6 , 9 } ; int n = arr . length ; System . out . println ( getMin ( arr , n ) ) ; } }

def getMin ( arr , n ) : NEW_LINE INDENT minVal = min ( arr ) ; NEW_LINE return minVal ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 3 , 1 , 6 , 9 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( getMin ( arr , n ) ) ; NEW_LINE DEDENT


class GFG { static float [ ] XandYandZintercept ( float A , float B , float C , float D ) { float rslt [ ] = new float [ 3 ] ; float x = - D / A ; float y = - D / B ; float z = - D / C ; rslt [ 0 ] = x ; rslt [ 1 ] = y ; rslt [ 2 ] = z ; return rslt ; } public static void main ( String [ ] args ) { int A = 2 ; int B = 5 ; int C = 7 ; int D = 8 ; float rslt [ ] = XandYandZintercept ( A , B , C , D ) ; for ( int i = 0 ; i < 3 ; i ++ ) { System . out . print ( rslt [ i ] + " ▁ " ) ; } } }

def XandYandZintercept ( A , B , C , D ) : NEW_LINE INDENT x = - D / A NEW_LINE y = - D / B NEW_LINE z = - D / C NEW_LINE return [ x , y , z ] NEW_LINE DEDENT A = 2 NEW_LINE B = 5 NEW_LINE C = 7 NEW_LINE D = 8 NEW_LINE print ( XandYandZintercept ( A , B , C , D ) ) NEW_LINE


public class GFG { static int findMinDifference ( int arr [ ] , int n ) { int min , secondMin , max , secondMax ; min = secondMax = ( arr [ 0 ] < arr [ 1 ] ) ? arr [ 0 ] : arr [ 1 ] ; max = secondMin = ( arr [ 0 ] < arr [ 1 ] ) ? arr [ 1 ] : arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { secondMax = max ; max = arr [ i ] ; } else if ( arr [ i ] > secondMax ) { secondMax = arr [ i ] ; } else if ( arr [ i ] < min ) { secondMin = min ; min = arr [ i ] ; } else if ( arr [ i ] < secondMin ) { secondMin = arr [ i ] ; } } int diff = Math . min ( max - secondMin , secondMax - min ) ; return diff ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 3 , 4 } ; int n = arr . length ; System . out . println ( findMinDifference ( arr , n ) ) ; } }

def findMinDifference ( arr , n ) : NEW_LINE INDENT if ( arr [ 0 ] < arr [ 1 ] ) : NEW_LINE INDENT min__ = secondMax = arr [ 0 ] NEW_LINE DEDENT else : NEW_LINE INDENT min__ = secondMax = arr [ 1 ] NEW_LINE DEDENT if ( arr [ 0 ] < arr [ 1 ] ) : NEW_LINE INDENT max__ = secondMin = arr [ 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT max__ = secondMin = arr [ 0 ] NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if ( arr [ i ] > max__ ) : NEW_LINE INDENT secondMax = max__ NEW_LINE max__ = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] > secondMax ) : NEW_LINE INDENT secondMax = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] < min__ ) : NEW_LINE INDENT secondMin = min__ NEW_LINE min__ = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] < secondMin ) : NEW_LINE INDENT secondMin = arr [ i ] NEW_LINE DEDENT DEDENT diff = min ( max__ - secondMin , secondMax - min__ ) NEW_LINE return diff NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 4 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMinDifference ( arr , n ) ) NEW_LINE DEDENT


public class GFG { public static void largestInColumn ( int cols , int [ ] [ ] arr ) { for ( int i = 0 ; i < cols ; i ++ ) { int maxm = arr [ 0 ] [ i ] ; for ( int j = 1 ; j < arr [ i ] . length ; j ++ ) if ( arr [ j ] [ i ] > maxm ) maxm = arr [ j ] [ i ] ; System . out . println ( maxm ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] arr = new int [ ] [ ] { { 3 , 4 , 1 , 8 } , { 1 , 4 , 9 , 11 } , { 76 , 34 , 21 , 1 } , { 2 , 1 , 4 , 5 } } ; largestInColumn ( 4 , arr ) ; } }

MAX = 100 NEW_LINE def largestInColumn ( mat , rows , cols ) : NEW_LINE INDENT for i in range ( cols ) : NEW_LINE INDENT maxm = mat [ 0 ] [ i ] NEW_LINE for j in range ( rows ) : NEW_LINE INDENT if mat [ j ] [ i ] > maxm : NEW_LINE INDENT maxm = mat [ j ] [ i ] NEW_LINE DEDENT DEDENT print ( maxm ) NEW_LINE DEDENT DEDENT n , m = 4 , 4 NEW_LINE mat = [ [ 3 , 4 , 1 , 8 ] , [ 1 , 4 , 9 , 11 ] , [ 76 , 34 , 21 , 1 ] , [ 2 , 1 , 4 , 5 ] ] NEW_LINE largestInColumn ( mat , n , m ) ; NEW_LINE


import java . math . BigInteger ; class Test { static int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 } ; static void printSubsequences ( int n ) { int opsize = ( int ) Math . pow ( 2 , n ) ; for ( int counter = 1 ; counter < opsize ; counter ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( BigInteger . valueOf ( counter ) . testBit ( j ) ) System . out . print ( arr [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { System . out . println ( " All ▁ Non - empty ▁ Subsequences " ) ; printSubsequences ( arr . length ) ; } }

import math NEW_LINE def printSubsequences ( arr , n ) : NEW_LINE INDENT opsize = math . pow ( 2 , n ) NEW_LINE for counter in range ( 1 , ( int ) ( opsize ) ) : NEW_LINE INDENT for j in range ( 0 , n ) : NEW_LINE INDENT if ( counter & ( 1 << j ) ) : NEW_LINE INDENT print ( arr [ j ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " All ▁ Non - empty ▁ Subsequences " ) NEW_LINE printSubsequences ( arr , n ) NEW_LINE


class GFG { static class Node { int data ; Node next ; } ; static Node push ( Node head_ref , int data ) { Node ptr1 = new Node ( ) ; Node temp = head_ref ; ptr1 . data = data ; ptr1 . next = head_ref ; if ( head_ref != null ) { while ( temp . next != head_ref ) temp = temp . next ; temp . next = ptr1 ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } static int countNodes ( Node head ) { Node temp = head ; int result = 0 ; if ( head != null ) { do { temp = temp . next ; result ++ ; } while ( temp != head ) ; } return result ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 12 ) ; head = push ( head , 56 ) ; head = push ( head , 2 ) ; head = push ( head , 11 ) ; System . out . printf ( " % d " , countNodes ( 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 push ( head_ref , data ) : NEW_LINE INDENT ptr1 = Node ( 0 ) NEW_LINE temp = head_ref NEW_LINE ptr1 . data = data NEW_LINE ptr1 . next = head_ref NEW_LINE if ( head_ref != None ) : NEW_LINE INDENT while ( temp . next != head_ref ) : NEW_LINE INDENT temp = temp . next NEW_LINE DEDENT temp . next = ptr1 NEW_LINE DEDENT else : NEW_LINE INDENT ptr1 . next = ptr1 NEW_LINE DEDENT head_ref = ptr1 NEW_LINE return head_ref NEW_LINE DEDENT def countNodes ( head ) : NEW_LINE INDENT temp = head NEW_LINE result = 0 NEW_LINE if ( head != None ) : NEW_LINE INDENT while True : NEW_LINE INDENT temp = temp . next NEW_LINE result = result + 1 NEW_LINE if ( temp == head ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 12 ) NEW_LINE head = push ( head , 56 ) NEW_LINE head = push ( head , 2 ) NEW_LINE head = push ( head , 11 ) NEW_LINE print ( countNodes ( head ) ) NEW_LINE DEDENT


class GFG { static int countOddNumber ( int row_num ) { int count = 0 ; while ( row_num > 0 ) { count += row_num & 1 ; row_num >>= 1 ; } return ( 1 << count ) ; } static void gouldSequence ( int n ) { for ( int row_num = 0 ; row_num < n ; row_num ++ ) { System . out . print ( countOddNumber ( row_num ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 16 ; gouldSequence ( n ) ; } }

def countOddNumber ( row_num ) : NEW_LINE INDENT count = 0 NEW_LINE while row_num != 0 : NEW_LINE INDENT count += row_num & 1 NEW_LINE row_num >>= 1 NEW_LINE DEDENT return ( 1 << count ) NEW_LINE DEDENT def gouldSequence ( n ) : NEW_LINE INDENT for row_num in range ( 0 , n ) : NEW_LINE INDENT print ( countOddNumber ( row_num ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 16 NEW_LINE gouldSequence ( n ) NEW_LINE DEDENT


class GFG { static int countSubStr ( char [ ] s , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 2 😉 { if ( s [ i ] == '0' && s [ i + 1 ] == '1' && s [ i + 2 ] == '0' ) { count ++ ; i += 3 ; } else if ( s [ i ] == '1' && s [ i + 1 ] == '0' && s [ i + 2 ] == '1' ) { count ++ ; i += 3 ; } else { i ++ ; } } return count ; } public static void main ( String [ ] args ) { char [ ] s = "10101010101" . toCharArray ( ) ; int n = s . length ; System . out . println ( countSubStr ( s , n ) ) ; } }

def countSubStr ( s , n ) : NEW_LINE INDENT count = 0 ; NEW_LINE i = 0 NEW_LINE while i < ( n - 2 ) : NEW_LINE INDENT if ( s [ i ] == '0' and s [ i + 1 ] == '1' and s [ i + 2 ] == '0' ) : NEW_LINE INDENT count += 1 ; NEW_LINE i += 3 ; NEW_LINE DEDENT elif ( s [ i ] == '1' and s [ i + 1 ] == '0' and s [ i + 2 ] == '1' ) : NEW_LINE INDENT count += 1 ; NEW_LINE i += 3 ; NEW_LINE DEDENT else : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "10101010101" ; NEW_LINE n = len ( s ) ; NEW_LINE print ( countSubStr ( s , n ) ) ; NEW_LINE DEDENT


class GFG { static int getNumber ( int n , int k ) { int [ ] arr = new int [ n ] ; int i = 0 ; int odd = 1 ; while ( odd <= n ) { arr [ i ++ ] = odd ; odd += 2 ; } int even = 2 ; while ( even <= n ) { arr [ i ++ ] = even ; even += 2 ; } return arr [ k - 1 ] ; } public static void main ( String [ ] args ) { int n = 8 , k = 5 ; System . out . println ( getNumber ( n , k ) ) ; } }

def getNumber ( n , k ) : NEW_LINE INDENT arr = [ 0 ] * n ; NEW_LINE i = 0 ; NEW_LINE odd = 1 ; NEW_LINE while ( odd <= n ) : NEW_LINE INDENT arr [ i ] = odd ; NEW_LINE i += 1 ; NEW_LINE odd += 2 ; NEW_LINE DEDENT even = 2 ; NEW_LINE while ( even <= n ) : NEW_LINE INDENT arr [ i ] = even ; NEW_LINE i += 1 ; NEW_LINE even += 2 ; NEW_LINE DEDENT return arr [ k - 1 ] ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 8 ; NEW_LINE k = 5 ; NEW_LINE print ( getNumber ( n , k ) ) ; NEW_LINE DEDENT


import java . util . HashSet ; class Test { static void printUnion ( int arr1 [ ] , int arr2 [ ] ) { HashSet < Integer > hs = new HashSet < > ( ) ; for ( int i = 0 ; i < arr1 . length ; i ++ ) hs . add ( arr1 [ i ] ) ; for ( int i = 0 ; i < arr2 . length ; i ++ ) hs . add ( arr2 [ i ] ) ; System . out . println ( hs ) ; } static void printIntersection ( int arr1 [ ] , int arr2 [ ] ) { HashSet < Integer > hs = new HashSet < > ( ) ; HashSet < Integer > hs1 = new HashSet < > ( ) ; for ( int i = 0 ; i < arr1 . length ; i ++ ) hs . add ( arr1 [ i ] ) ; for ( int i = 0 ; i < arr2 . length ; i ++ ) if ( hs . contains ( arr2 [ i ] ) ) System . out . print ( arr2 [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 7 , 1 , 5 , 2 , 3 , 6 } ; int arr2 [ ] = { 3 , 8 , 6 , 20 , 7 } ; System . out . println ( " Union ▁ of ▁ two ▁ arrays ▁ is ▁ : ▁ " ) ; printUnion ( arr1 , arr2 ) ; System . out . println ( " Intersection ▁ of ▁ two ▁ arrays ▁ is ▁ : ▁ " ) ; printIntersection ( arr1 , arr2 ) ; } }

def printUnion ( arr1 , arr2 , n1 , n2 ) : NEW_LINE INDENT hs = set ( ) NEW_LINE for i in range ( 0 , n1 ) : NEW_LINE INDENT hs . add ( arr1 [ i ] ) NEW_LINE DEDENT for i in range ( 0 , n2 ) : NEW_LINE INDENT hs . add ( arr2 [ i ] ) NEW_LINE DEDENT print ( " Union : " ) NEW_LINE for i in hs : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT print ( " \n " ) NEW_LINE DEDENT def printIntersection ( arr1 , arr2 , n1 , n2 ) : NEW_LINE INDENT hs = set ( ) NEW_LINE for i in range ( 0 , n1 ) : NEW_LINE INDENT hs . add ( arr1 [ i ] ) NEW_LINE DEDENT print ( " Intersection : " ) NEW_LINE for i in range ( 0 , n2 ) : NEW_LINE INDENT if arr2 [ i ] in hs : NEW_LINE INDENT print ( arr2 [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr1 = [ 7 , 1 , 5 , 2 , 3 , 6 ] NEW_LINE arr2 = [ 3 , 8 , 6 , 20 , 7 ] NEW_LINE n1 = len ( arr1 ) NEW_LINE n2 = len ( arr2 ) NEW_LINE printUnion ( arr1 , arr2 , n1 , n2 ) NEW_LINE printIntersection ( arr1 , arr2 , n1 , n2 ) NEW_LINE


import java . util . * ; class GFG { static char encodedChar ( char [ ] str , int k ) { int i , j ; int n = str . length ; int len ; int num ; int freq ; i = 0 ; while ( i < n ) { j = i ; len = 0 ; freq = 0 ; while ( j < n && Character . isAlphabetic ( str [ j ] ) ) { j ++ ; len ++ ; } while ( j < n && Character . isDigit ( str [ j ] ) ) { freq = freq * 10 + ( str [ j ] - '0' ) ; j ++ ; } num = freq * len ; if ( k > num ) { k -= num ; i = j ; } else { k -- ; k %= len ; return str [ i + k ] ; } } return str [ k - 1 ] ; } public static void main ( String [ ] args ) { String str = " abced " ; int k = 4 ; System . out . println ( encodedChar ( str . toCharArray ( ) , k ) ) ; } }

def encodedChar ( string , k ) : NEW_LINE INDENT n = len ( string ) NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT j = i NEW_LINE length = 0 NEW_LINE freq = 0 NEW_LINE while j < n and string [ j ] . isalpha ( ) : NEW_LINE INDENT j += 1 NEW_LINE length += 1 NEW_LINE DEDENT while j < n and string [ j ] . isdigit ( ) : NEW_LINE INDENT freq = freq * 10 + int ( string [ j ] ) NEW_LINE j += 1 NEW_LINE DEDENT num = freq * length NEW_LINE if k > num : NEW_LINE INDENT k -= num NEW_LINE i = j NEW_LINE DEDENT else : NEW_LINE INDENT k -= 1 NEW_LINE k %= length NEW_LINE return string [ i + k ] NEW_LINE DEDENT DEDENT return string [ k - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " abced " NEW_LINE k = 4 NEW_LINE print ( encodedChar ( string , k ) ) NEW_LINE DEDENT


import java . util . Vector ; public class GFG { static int maxPrimefactorNum ( int N ) { boolean arr [ ] = new boolean [ N + 5 ] ; for ( int i = 3 ; i * i <= N ; i += 2 ) { if ( ! arr [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { arr [ j ] = true ; } } } Vector < Integer > prime = new Vector < > ( ) ; prime . add ( prime . size ( ) , 2 ) ; for ( int i = 3 ; i <= N ; i += 2 ) { if ( ! arr [ i ] ) { prime . add ( prime . size ( ) , i ) ; } } int i = 0 , ans = 1 ; while ( ans * prime . get ( i ) <= N && i < prime . size ( ) ) { ans *= prime . get ( i ) ; i ++ ; } return ans ; } public static void main ( String [ ] args ) { int N = 40 ; System . out . println ( maxPrimefactorNum ( N ) ) ; } }

def maxPrimefactorNum ( N ) : NEW_LINE INDENT arr = [ True ] * ( N + 5 ) ; NEW_LINE i = 3 ; NEW_LINE while ( i * i <= N ) : NEW_LINE INDENT if ( arr [ i ] ) : NEW_LINE INDENT for j in range ( i * i , N + 1 , i ) : NEW_LINE INDENT arr [ j ] = False ; NEW_LINE DEDENT DEDENT i += 2 ; NEW_LINE DEDENT prime = [ ] ; NEW_LINE prime . append ( 2 ) ; NEW_LINE for i in range ( 3 , N + 1 , 2 ) : NEW_LINE INDENT if ( arr [ i ] ) : NEW_LINE INDENT prime . append ( i ) ; NEW_LINE DEDENT DEDENT i = 0 ; NEW_LINE ans = 1 ; NEW_LINE while ( ans * prime [ i ] <= N and i < len ( prime ) ) : NEW_LINE INDENT ans *= prime [ i ] ; NEW_LINE i += 1 ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT N = 40 ; NEW_LINE print ( maxPrimefactorNum ( N ) ) ; NEW_LINE


class GFG { static int n ; static int [ ] [ ] dp = new int [ 1000 ] [ 1000 ] ; static String str = " abcb " ; static int countPS ( int i , int j ) { if ( i >= n || j < 0 ) return 0 ; if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; if ( ( i - j == 1 ) || ( i - j == - 1 ) ) { if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = 3 ; else return dp [ i ] [ j ] = 2 ; } if ( i == j ) return dp [ 1 ] [ j ] = 1 ; else if ( str . charAt ( i ) == str . charAt ( j ) ) return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ; else return dp [ i ] [ j ] = countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 1000 ; i ++ ) for ( int j = 0 ; j < 1000 ; j ++ ) dp [ i ] [ j ] = - 1 ; n = str . length ( ) ; System . out . println ( " Total ▁ palindromic ▁ subsequence " + " are ▁ : ▁ " + countPS ( 0 , n - 1 ) ) ; } }

str = " abcb " NEW_LINE def countPS ( i , j ) : NEW_LINE INDENT if ( i >= n or j < 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( dp [ i ] [ j ] != - 1 ) : NEW_LINE INDENT return dp [ i ] [ j ] NEW_LINE DEDENT if ( abs ( i - j ) == 1 ) : NEW_LINE INDENT if ( str [ i ] == str [ j ] ) : NEW_LINE INDENT dp [ i ] [ j ] = 3 NEW_LINE return dp [ i ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] = 2 NEW_LINE return dp [ i ] [ j ] NEW_LINE DEDENT DEDENT if ( i == j ) : NEW_LINE INDENT dp [ 1 ] [ j ] = 1 NEW_LINE return dp [ 1 ] [ j ] NEW_LINE DEDENT elif ( str [ i ] == str [ j ] ) : NEW_LINE INDENT dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) + 1 ) NEW_LINE return dp [ i ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT dp [ i ] [ j ] = ( countPS ( i + 1 , j ) + countPS ( i , j - 1 ) - countPS ( i + 1 , j - 1 ) ) NEW_LINE return dp [ i ] [ j ] NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT dp = [ [ - 1 for x in range ( 1000 ) ] for y in range ( 1000 ) ] NEW_LINE n = len ( str ) NEW_LINE print ( " Total ▁ palindromic ▁ subsequence ▁ are ▁ : " , countPS ( 0 , n - 1 ) ) NEW_LINE DEDENT


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

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


import java . util . * ; class GFG { static int MX = 2001 ; static int OFF = 1000 ; static class point { int x , y ; public point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int countPoints ( int n , point points [ ] ) { int [ ] minx = new int [ MX ] ; int [ ] miny = new int [ MX ] ; for ( int i = 0 ; i < n ; i ++ ) { minx [ i ] = Integer . MAX_VALUE ; miny [ i ] = Integer . MAX_VALUE ; } int [ ] maxx = new int [ MX ] ; int [ ] maxy = new int [ MX ] ; int x , y ; for ( int i = 0 ; i < n ; i ++ ) { points [ i ] . x += OFF ; points [ i ] . y += OFF ; x = points [ i ] . x ; y = points [ i ] . y ; minx [ y ] = Math . min ( minx [ y ] , x ) ; maxx [ y ] = Math . max ( maxx [ y ] , x ) ; miny [ x ] = Math . min ( miny [ x ] , y ) ; maxy [ x ] = Math . max ( maxy [ x ] , y ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { x = points [ i ] . x ; y = points [ i ] . y ; if ( x > minx [ y ] && x < maxx [ y ] ) if ( y > miny [ x ] && y < maxy [ x ] ) count ++ ; } return count ; } public static void main ( String [ ] args ) { point points [ ] = { new point ( 0 , 0 ) , new point ( 0 , 1 ) , new point ( 1 , 0 ) , new point ( 0 , - 1 ) , new point ( - 1 , 0 ) } ; int n = points . length ; System . out . println ( countPoints ( n , points ) ) ; } }

from sys import maxsize as INT_MAX NEW_LINE MX = 2001 NEW_LINE OFF = 1000 NEW_LINE class point : NEW_LINE INDENT def __init__ ( self , x , y ) : NEW_LINE INDENT self . x = x NEW_LINE self . y = y NEW_LINE DEDENT DEDENT def countPoints ( n : int , points : list ) -> int : NEW_LINE INDENT minx = [ INT_MAX ] * MX NEW_LINE miny = [ INT_MAX ] * MX NEW_LINE maxx = [ 0 ] * MX NEW_LINE maxy = [ 0 ] * MX NEW_LINE x , y = 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT points [ i ] . x += OFF NEW_LINE points [ i ] . y += OFF NEW_LINE x = points [ i ] . x NEW_LINE y = points [ i ] . y NEW_LINE minx [ y ] = min ( minx [ y ] , x ) NEW_LINE maxx [ y ] = max ( maxx [ y ] , x ) NEW_LINE miny [ x ] = min ( miny [ x ] , y ) NEW_LINE maxy [ x ] = max ( maxy [ x ] , y ) NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = points [ i ] . x NEW_LINE y = points [ i ] . y NEW_LINE if ( x > minx [ y ] and x < maxx [ y ] ) : NEW_LINE INDENT if ( y > miny [ x ] and y < maxy [ x ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT points = [ point ( 0 , 0 ) , point ( 0 , 1 ) , point ( 1 , 0 ) , point ( 0 , - 1 ) , point ( - 1 , 0 ) ] NEW_LINE n = len ( points ) NEW_LINE print ( countPoints ( n , points ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int EulerTotientFunction ( int limit ) { int copy = limit ; Vector < Integer > primes = new Vector < Integer > ( ) ; for ( int i = 2 ; i * i <= limit ; i ++ ) { if ( limit % i == 0 ) { while ( limit % i == 0 ) { limit /= i ; } primes . add ( i ) ; } } if ( limit >= 2 ) { primes . add ( limit ) ; } int ans = copy ; for ( int it : primes ) { ans = ( ans / it ) * ( it - 1 ) ; } return ans ; } static void CountGCD ( int m , int k ) { if ( m % k != 0 ) { System . out . print ( 0 + " \n " ) ; return ; } if ( m == k ) { System . out . print ( 2 + " \n " ) ; return ; } int limit = m / k ; int ans = EulerTotientFunction ( limit ) ; System . out . print ( ans + " \n " ) ; } public static void main ( String [ ] args ) { int M = 9 ; int K = 1 ; CountGCD ( M , K ) ; } }

def EulerTotientFunction ( limit ) : NEW_LINE INDENT copy = limit NEW_LINE primes = [ ] NEW_LINE for i in range ( 2 , limit + 1 ) : NEW_LINE INDENT if i * i > limit : NEW_LINE INDENT break NEW_LINE DEDENT if ( limit % i == 0 ) : NEW_LINE INDENT while ( limit % i == 0 ) : NEW_LINE INDENT limit //= i NEW_LINE DEDENT primes . append ( i ) NEW_LINE DEDENT DEDENT if ( limit >= 2 ) : NEW_LINE INDENT primes . append ( limit ) NEW_LINE DEDENT ans = copy NEW_LINE for it in primes : NEW_LINE INDENT ans = ( ans // it ) * ( it - 1 ) NEW_LINE DEDENT return ans NEW_LINE DEDENT def CountGCD ( m , k ) : NEW_LINE INDENT if ( m % k != 0 ) : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT if ( m == k ) : NEW_LINE INDENT print ( 2 ) NEW_LINE return NEW_LINE DEDENT limit = m // k NEW_LINE ans = EulerTotientFunction ( limit ) NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT M = 9 NEW_LINE K = 1 NEW_LINE CountGCD ( M , K ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { public static int stopping_station ( int p , int n ) { int num = 1 , dem = 1 , s = p ; while ( p != 1 ) { dem *= p ; p -- ; } int t = n - s + 1 ; while ( t != ( n - 2 * s + 1 ) ) { num *= t ; t -- ; } if ( ( n - s + 1 ) >= s ) System . out . print ( num / dem ) ; else System . out . print ( " not ▁ possible " ) ; return 0 ; } public static void main ( String [ ] args ) { int n , s ; stopping_station ( 4 , 12 ) ; } }

def stopping_station ( p , n ) : NEW_LINE INDENT num = 1 NEW_LINE dem = 1 NEW_LINE s = p NEW_LINE while p != 1 : NEW_LINE INDENT dem *= p NEW_LINE p -= 1 NEW_LINE DEDENT t = n - s + 1 NEW_LINE while t != ( n - 2 * s + 1 ) : NEW_LINE INDENT num *= t NEW_LINE t -= 1 NEW_LINE DEDENT if ( n - s + 1 ) >= s : NEW_LINE INDENT return int ( num / dem ) NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT num = stopping_station ( 4 , 12 ) NEW_LINE if num != - 1 : NEW_LINE INDENT print ( num ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int mod = 1000000007 ; static int countSubsets ( int a [ ] , int n ) { int answer = 0 ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int bitwiseAND = - 1 ; int bitwiseOR = 0 ; int bitwiseXOR = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) == 0 ) { if ( bitwiseAND == - 1 ) bitwiseAND = a [ j ] ; else bitwiseAND &= a [ j ] ; bitwiseOR |= a [ j ] ; bitwiseXOR ^= a [ j ] ; } } if ( bitwiseAND == bitwiseOR && bitwiseOR == bitwiseXOR ) answer = ( answer + 1 ) % mod ; } return answer ; } public static void main ( String [ ] args ) { int N = 6 ; int A [ ] = { 1 , 3 , 2 , 1 , 2 , 1 } ; System . out . print ( countSubsets ( A , N ) ) ; } }

mod = 1000000007 ; NEW_LINE def countSubsets ( a , n ) : NEW_LINE INDENT answer = 0 ; NEW_LINE for i in range ( 1 << n ) : NEW_LINE INDENT bitwiseAND = - 1 ; NEW_LINE bitwiseOR = 0 ; NEW_LINE bitwiseXOR = 0 ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( i & ( 1 << j ) ) : NEW_LINE INDENT if ( bitwiseAND == - 1 ) : NEW_LINE INDENT bitwiseAND = a [ j ] ; NEW_LINE DEDENT else : NEW_LINE INDENT bitwiseAND &= a [ j ] ; NEW_LINE DEDENT bitwiseOR |= a [ j ] ; NEW_LINE bitwiseXOR ^= a [ j ] ; NEW_LINE DEDENT DEDENT if ( bitwiseAND == bitwiseOR and bitwiseOR == bitwiseXOR ) : NEW_LINE INDENT answer = ( answer + 1 ) % mod ; NEW_LINE DEDENT DEDENT return answer ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 6 ; NEW_LINE A = [ 1 , 3 , 2 , 1 , 2 , 1 ] ; NEW_LINE print ( countSubsets ( A , N ) ) ; NEW_LINE DEDENT


import java . util . HashMap ; import java . util . Map ; class GFG { static int subset ( int arr [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) == null ? 1 : mp . get ( arr [ i ] ) + 1 ) ; int res = 0 ; for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) res = Math . max ( res , entry . getValue ( ) ) ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 6 , 9 , 3 , 4 , 3 , 4 } ; int n = arr . length ; System . out . println ( subset ( arr , n ) ) ; } }

def subset ( arr , n ) : NEW_LINE INDENT mp = { i : 0 for i in range ( 10 ) } NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT res = 0 NEW_LINE for key , value in mp . items ( ) : NEW_LINE INDENT res = max ( res , value ) NEW_LINE DEDENT return res NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 5 , 6 , 9 , 3 , 4 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( subset ( arr , n ) ) NEW_LINE DEDENT


import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; public class FindDuplicatedInArray { public static void main ( String [ ] args ) { int arr [ ] = { 12 , 11 , 40 , 12 , 5 , 6 , 5 , 12 , 11 } ; int n = arr . length ; printDuplicates ( arr , n ) ; } private static void printDuplicates ( int [ ] arr , int n ) { Map < Integer , Integer > map = new HashMap < > ( ) ; int count = 0 ; boolean dup = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( map . containsKey ( arr [ i ] ) ) { count = map . get ( arr [ i ] ) ; map . put ( arr [ i ] , count + 1 ) ; } else { map . put ( arr [ i ] , 1 ) ; } } for ( Entry < Integer , Integer > entry : map . entrySet ( ) ) { if ( entry . getValue ( ) > 1 ) { System . out . print ( entry . getKey ( ) + " ▁ " ) ; dup = true ; } } if ( ! dup ) { System . out . println ( " - 1" ) ; } } }

def printDuplicates ( arr ) : NEW_LINE INDENT dict = { } NEW_LINE for ele in arr : NEW_LINE INDENT try : NEW_LINE INDENT dict [ ele ] += 1 NEW_LINE DEDENT except : NEW_LINE INDENT dict [ ele ] = 1 NEW_LINE DEDENT DEDENT for item in dict : NEW_LINE INDENT if ( dict [ item ] > 1 ) : NEW_LINE INDENT print ( item , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( " \n " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT list = [ 12 , 11 , 40 , 12 , 5 , 6 , 5 , 12 , 11 ] NEW_LINE printDuplicates ( list ) NEW_LINE DEDENT


class GFG { static int smallestSum ( int n ) { if ( n == 1 ) return 0 ; return ( 2 * ( int ) Math . pow ( 10 , n - 1 ) ) ; } static int largestSum ( int n ) { return ( 2 * ( ( int ) Math . pow ( 10 , n ) - 1 ) ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( " Largest ▁ = ▁ " + largestSum ( n ) ) ; System . out . print ( " Smallest ▁ = ▁ " + smallestSum ( n ) ) ; } }

def smallestSum ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( 2 * pow ( 10 , n - 1 ) ) NEW_LINE DEDENT def largestSum ( n ) : NEW_LINE INDENT return ( 2 * ( pow ( 10 , n ) - 1 ) ) NEW_LINE DEDENT n = 4 NEW_LINE print ( " Largest ▁ = ▁ " , largestSum ( n ) ) NEW_LINE print ( " Smallest ▁ = ▁ " , smallestSum ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int rhombusAreaPeri ( int d1 , int d2 ) { int area , perimeter ; area = ( d1 * d2 ) / 2 ; perimeter = ( int ) ( 2 * Math . sqrt ( Math . pow ( d1 , 2 ) + Math . pow ( d2 , 2 ) ) ) ; System . out . println ( " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " + d1 + " ▁ and ▁ " + d2 + " ▁ is ▁ " + area + " . " ) ; System . out . println ( " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals ▁ " + d1 + " ▁ and ▁ " + d2 + " ▁ is ▁ " + perimeter + " . " ) ; return 0 ; } public static void main ( String [ ] args ) { int d1 = 2 , d2 = 4 ; rhombusAreaPeri ( d1 , d2 ) ; } }

from math import sqrt , pow NEW_LINE def rhombusAreaPeri ( d1 , d2 ) : NEW_LINE INDENT area = ( d1 * d2 ) / 2 NEW_LINE perimeter = 2 * sqrt ( pow ( d1 , 2 ) + pow ( d2 , 2 ) ) NEW_LINE print ( " The ▁ area ▁ of ▁ rhombus ▁ with ▁ diagonals " , d1 , " and " , d2 , " is " , area , " . " ) NEW_LINE print ( " The ▁ perimeter ▁ of ▁ rhombus ▁ with ▁ diagonals " , d1 , " and " , d2 , " is " , perimeter , " . " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT d1 = 2 NEW_LINE d2 = 4 NEW_LINE rhombusAreaPeri ( d1 , d2 ) NEW_LINE DEDENT


import java . io . * ; class GFG { static float area ( float a ) { if ( a < 0 ) return - 1 ; float area = ( float ) Math . pow ( ( a * Math . sqrt ( 3 ) ) / ( Math . sqrt ( 2 ) ) , 2 ) ; return area ; } public static void main ( String [ ] args ) { float a = 5 ; System . out . println ( area ( a ) ) ; } }

from math import pow , sqrt NEW_LINE def area ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT area = pow ( ( a * sqrt ( 3 ) ) / ( sqrt ( 2 ) ) , 2 ) NEW_LINE return area NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 5 NEW_LINE print ( " { 0 : . 3 } " . format ( area ( a ) ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ( ch == ' A ' || ch == ' E ' || ch == ' I ' || ch == ' O ' || ch == ' U ' ) ; } static String duplicateVowels ( String str ) { int t = str . length ( ) ; String res = " " ; for ( int i = 0 ; i < t ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) res += str . charAt ( i ) ; res += str . charAt ( i ) ; } return res ; } public static void main ( String [ ] args ) { String str = " helloworld " ; System . out . println ( " Original ▁ String : ▁ " + str ) ; String res = duplicateVowels ( str ) ; System . out . println ( " String ▁ with ▁ Vowels ▁ duplicated : ▁ " + res ) ; } }

def isVowel ( ch ) : NEW_LINE INDENT ch = ch . upper ( ) NEW_LINE if ( ch == ' A ' or ch == ' E ' or ch == ' I ' or ch == ' O ' or ch == ' U ' ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def duplicateVowels ( S ) : NEW_LINE INDENT t = len ( S ) NEW_LINE res = " " NEW_LINE for i in range ( t ) : NEW_LINE INDENT if ( isVowel ( S [ i ] ) ) : NEW_LINE INDENT res += S [ i ] NEW_LINE DEDENT res += S [ i ] NEW_LINE DEDENT return res NEW_LINE DEDENT S = " helloworld " NEW_LINE print ( " Original ▁ String : ▁ " , S ) NEW_LINE res = duplicateVowels ( S ) NEW_LINE print ( " String ▁ with ▁ Vowels ▁ duplicated : ▁ " , res ) NEW_LINE


class GFG { static int MAX = 100000 ; static int countPairsWithProductK ( int arr [ ] , int n , int k ) { int count = 0 ; int i ; boolean hashmap [ ] = new boolean [ MAX ] ; for ( i = 0 ; i < n ; i ++ ) hashmap [ arr [ i ] ] = true ; for ( i = 0 ; i < n ; i ++ ) { int x = arr [ i ] ; double index = 1.0 * k / arr [ i ] ; if ( index >= 0 && ( ( index - ( int ) ( index ) ) == 0 ) && hashmap [ k / x ] ) count ++ ; hashmap [ x ] = false ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int N = arr . length ; int K = 3 ; System . out . print ( countPairsWithProductK ( arr , N , K ) ) ; } }

MAX = 100000 ; NEW_LINE def countPairsWithProductK ( arr , n , k ) : NEW_LINE INDENT count = 0 ; NEW_LINE hashmap = [ False ] * MAX ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT hashmap [ arr [ i ] ] = True ; NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT x = arr [ i ] ; NEW_LINE index = 1.0 * k / arr [ i ] ; NEW_LINE if ( index >= 0 and ( ( index - int ( index ) ) == 0 ) and hashmap [ k // x ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT hashmap [ x ] = False ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 5 , 3 , 4 , 2 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE K = 3 ; NEW_LINE print ( countPairsWithProductK ( arr , N , K ) ) ; NEW_LINE DEDENT


class GFG { static int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here += a [ i ] ; if ( max_so_far < max_ending_here ) { max_so_far = max_ending_here ; start = s ; end = i ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; s = i + 1 ; } } return ( end - start + 1 ) ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = a . length ; System . out . println ( maxSubArraySum ( a , n ) ) ; } }

from sys import maxsize NEW_LINE def maxSubArraySum ( a , size ) : NEW_LINE INDENT max_so_far = - maxsize - 1 NEW_LINE max_ending_here = 0 NEW_LINE start = 0 NEW_LINE end = 0 NEW_LINE s = 0 NEW_LINE for i in range ( 0 , size ) : NEW_LINE INDENT max_ending_here += a [ i ] NEW_LINE if max_so_far < max_ending_here : NEW_LINE INDENT max_so_far = max_ending_here NEW_LINE start = s NEW_LINE end = i NEW_LINE DEDENT if max_ending_here < 0 : NEW_LINE INDENT max_ending_here = 0 NEW_LINE s = i + 1 NEW_LINE DEDENT DEDENT return ( end - start + 1 ) NEW_LINE DEDENT a = [ - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 ] NEW_LINE print ( maxSubArraySum ( a , len ( a ) ) ) NEW_LINE


import java . util . * ; class GFG { public static int [ ] computeLPSArray ( String str ) { int n = str . length ( ) ; int lps [ ] = new int [ n ] ; int i = 1 , len = 0 ; lps [ 0 ] = 0 ; while ( i < n ) { if ( str . charAt ( i ) == str . charAt ( len ) ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } return lps ; } static int getMinCharToAddedToMakeStringPalin ( String str ) { StringBuilder s = new StringBuilder ( ) ; s . append ( str ) ; String rev = s . reverse ( ) . toString ( ) ; s . reverse ( ) . append ( " $ " ) . append ( rev ) ; int lps [ ] = computeLPSArray ( s . toString ( ) ) ; return str . length ( ) - lps [ s . length ( ) - 1 ] ; } public static void main ( String args [ ] ) { String str = " AACECAAAA " ; System . out . println ( getMinCharToAddedToMakeStringPalin ( str ) ) ; } }

def computeLPSArray ( string ) : NEW_LINE INDENT M = len ( string ) NEW_LINE lps = [ None ] * M NEW_LINE length = 0 NEW_LINE lps [ 0 ] = 0 NEW_LINE i = 1 NEW_LINE while i < M : NEW_LINE INDENT if string [ i ] == string [ length ] : NEW_LINE INDENT length += 1 NEW_LINE lps [ i ] = length NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT if length != 0 : NEW_LINE INDENT length = lps [ length - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT lps [ i ] = 0 NEW_LINE i += 1 NEW_LINE DEDENT DEDENT DEDENT return lps NEW_LINE DEDENT def getMinCharToAddedToMakeStringPalin ( string ) : NEW_LINE INDENT revStr = string [ : : - 1 ] NEW_LINE concat = string + " $ " + revStr NEW_LINE lps = computeLPSArray ( concat ) NEW_LINE return len ( string ) - lps [ - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " AACECAAAA " NEW_LINE print ( getMinCharToAddedToMakeStringPalin ( string ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { public static boolean isPrime ( int x ) { if ( x == 0 || x == 1 ) return false ; for ( int i = 2 ; i * i <= x ; ++ i ) if ( x % i == 0 ) return false ; return true ; } public static void findPrimes ( int n ) { if ( isPrime ( n ) ) System . out . print ( n ) ; else if ( isPrime ( n - 2 ) ) System . out . print ( 2 + " ▁ " + ( n - 2 ) ) ; else { System . out . print ( 3 + " ▁ " ) ; n = n - 3 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime ( i ) && isPrime ( n - i ) ) { System . out . print ( i + " ▁ " + ( n - i ) ) ; break ; } } } } public static void main ( String [ ] args ) { int n = 27 ; findPrimes ( n ) ; } }

def isPrime ( x ) : NEW_LINE INDENT if ( x == 0 or x == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT i = 2 NEW_LINE while i * i <= x : NEW_LINE INDENT if ( x % i == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT return 1 NEW_LINE DEDENT def findPrimes ( n ) : NEW_LINE INDENT if ( isPrime ( n ) ) : NEW_LINE INDENT print ( n , end = " ▁ " ) NEW_LINE DEDENT elif ( isPrime ( n - 2 ) ) : NEW_LINE INDENT print ( "2" , end = " ▁ " ) NEW_LINE print ( n - 2 , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "3" , end = " ▁ " ) NEW_LINE n = n - 3 NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT if ( isPrime ( i ) and isPrime ( n - i ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE print ( ( n - i ) , end = " ▁ " ) NEW_LINE break NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT DEDENT DEDENT n = 27 ; NEW_LINE findPrimes ( n ) ; NEW_LINE


import java . io . * ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } public static void main ( String args [ ] ) { int x = 2 ; int y = 5 ; int p = 13 ; System . out . println ( " Power ▁ is ▁ " + power ( x , y , p ) ) ; } }

def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE if ( x == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT while ( y > 0 ) : NEW_LINE INDENT if ( ( y & 1 ) == 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 x = 2 ; y = 5 ; p = 13 NEW_LINE print ( " Power ▁ is ▁ " , power ( x , y , p ) ) NEW_LINE


import java . lang . Math . * ; class GFG { static final double PI = 3.142 ; static double cosXSertiesSum ( double x , int n ) { x = x * ( PI / 180.0 ) ; double res = 1 ; double sign = 1 , fact = 1 , pow = 1 ; for ( int i = 1 ; i < 5 ; i ++ ) { sign = sign * - 1 ; fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ; pow = pow * x * x ; res = res + sign * pow / fact ; } return res ; } public static void main ( String [ ] args ) { float x = 50 ; int n = 5 ; System . out . println ( ( float ) ( cosXSertiesSum ( x , 5 ) * 1000000 ) / 1000000.00 ) ; } }

PI = 3.142 ; NEW_LINE def cosXSertiesSum ( x , n ) : NEW_LINE INDENT x = x * ( PI / 180.0 ) ; NEW_LINE res = 1 ; NEW_LINE sign = 1 ; NEW_LINE fact = 1 ; NEW_LINE pow = 1 ; NEW_LINE for i in range ( 1 , 5 ) : NEW_LINE INDENT sign = sign * - 1 ; NEW_LINE fact = fact * ( 2 * i - 1 ) * ( 2 * i ) ; NEW_LINE pow = pow * x * x ; NEW_LINE res = res + sign * pow / fact ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT x = 50 ; NEW_LINE n = 5 ; NEW_LINE print ( round ( cosXSertiesSum ( x , 5 ) , 6 ) ) ; NEW_LINE


class GFG { static int digSum ( int n ) { int sum = 0 , rem = 0 ; while ( n > 0 ) { rem = n % 10 ; sum += rem ; n /= 10 ; } return sum ; } static int findX ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) if ( i + digSum ( i ) == n ) return i ; return - 1 ; } public static void main ( String [ ] args ) { int n = 43 ; System . out . println ( " x ▁ = ▁ " + findX ( n ) ) ; } }

def digSum ( n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE rem = 0 ; NEW_LINE while ( n ) : NEW_LINE INDENT rem = n % 10 ; NEW_LINE sum = sum + rem ; NEW_LINE n = int ( n / 10 ) ; NEW_LINE DEDENT return sum ; NEW_LINE DEDENT def findX ( n ) : NEW_LINE INDENT for i in range ( n + 1 ) : NEW_LINE INDENT if ( i + digSum ( i ) == n ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT return - 1 ; NEW_LINE DEDENT n = 43 ; NEW_LINE print ( " x ▁ = ▁ " , findX ( n ) ) ; NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static void reverseWords ( String str ) { Stack < Character > st = new Stack < Character > ( ) ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { if ( str . charAt ( i ) != ' ▁ ' ) st . push ( str . charAt ( i ) ) ; else { while ( st . empty ( ) == false ) { System . out . print ( st . pop ( ) ) ; } System . out . print ( " ▁ " ) ; } } while ( st . empty ( ) == false ) { System . out . print ( st . pop ( ) ) ; } } public static void main ( String [ ] args ) { String str = " Geeks ▁ for ▁ Geeks " ; reverseWords ( str ) ; } }

def reverserWords ( string ) : NEW_LINE INDENT st = list ( ) NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if string [ i ] != " ▁ " : NEW_LINE INDENT st . append ( string [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT while len ( st ) > 0 : NEW_LINE INDENT print ( st [ - 1 ] , end = " " ) NEW_LINE st . pop ( ) NEW_LINE DEDENT print ( end = " ▁ " ) NEW_LINE DEDENT DEDENT while len ( st ) > 0 : NEW_LINE INDENT print ( st [ - 1 ] , end = " " ) NEW_LINE st . pop ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " Geeks ▁ for ▁ Geeks " NEW_LINE reverserWords ( string ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean check ( int arr [ ] , int n ) { int k = Integer . MIN_VALUE ; int r = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { k = Math . max ( k , arr [ i ] ) ; r = Math . min ( r , arr [ i ] ) ; } k += 1 ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = k - arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( arr [ i ] ) - 1 < n && arr [ Math . abs ( arr [ i ] ) - 1 ] > 0 ) { arr [ Math . abs ( arr [ i ] ) - 1 ] = - arr [ Math . abs ( arr [ i ] ) - 1 ] ; } } int flag = 0 ; for ( int i = 0 ; i <= k - r - 1 ; i ++ ) { if ( arr [ i ] > 0 ) { flag = 1 ; break ; } } return flag == 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 } ; int n = arr . length ; if ( check ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def check ( arr , n ) : NEW_LINE INDENT k = - 10 ** 9 NEW_LINE r = 10 ** 9 NEW_LINE for i in range ( n ) : NEW_LINE INDENT k = max ( k , arr [ i ] ) NEW_LINE r = min ( r , arr [ i ] ) NEW_LINE DEDENT k += 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ i ] = k - arr [ i ] NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( abs ( arr [ i ] ) - 1 < n and arr [ abs ( arr [ i ] ) - 1 ] > 0 ) : NEW_LINE INDENT arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ] NEW_LINE DEDENT DEDENT flag = 0 NEW_LINE for i in range ( k - r ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE break NEW_LINE DEDENT DEDENT return flag == 0 NEW_LINE DEDENT arr = [ 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE if ( check ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


# A hashing based Python 3 program to # find missing elements from an array # Print all elements of range # [ low , high ] that are not # present in arr [ 0. . n - 1 ] def printMissing ( arr , n , low , high ) : # Insert all elements of # arr [ ] in set s = set ( arr ) # Traverse through the range # and print all missing elements for x in range ( low , high + 1 ) : if x not in s : print ( x , end = ' ▁ ' ) # Driver Code arr = [ 1 , 3 , 5 , 4 ] n = len ( arr ) low , high = 1 , 10 printMissing ( arr , n , low , high ) # This code is contributed # by SamyuktaSHegde

// A hashing based C NEW_LINE // find missing elements from an array NEW_LINE using System ; NEW_LINE using System . Collections . Generic ; NEW_LINE class GFG { // Print all elements of range // [ low , high ] that are not // present in arr [ 0. . n - 1 ] static void printMissing ( int [ ] arr , int n , int low , int high ) { // Insert all elements of arr [ ] in set HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < n ; i + + ) { s . Add ( arr [ i ] ) ; } // Traverse throught the range // an print all missing elements for ( int x = low ; x <= high ; x + + ) if ( ! s . Contains ( x ) ) Console . Write ( x + " ▁ " ) ; } // Driver Code public static void Main ( ) { int [ ] arr = { 1 , 3 , 5 , 4 } ; int n = arr . Length ; int low = 1 , high = 10 ; printMissing ( arr , n , low , high ) ; } } NEW_LINE // This code is contributed by ihritik NEW_LINE


import java . util . * ; class GFG { static int minimumAdjacentDifference ( int a [ ] , int n , int k ) { int minDiff = Integer . MAX_VALUE ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { int cnt = Integer . bitCount ( i ) ; if ( cnt == n - k ) { Vector < Integer > temp = new Vector < Integer > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) temp . add ( a [ j ] ) ; } int maxDiff = Integer . MIN_VALUE ; for ( int j = 0 ; j < temp . size ( ) - 1 ; j ++ ) { maxDiff = Math . max ( maxDiff , temp . get ( j + 1 ) - temp . get ( j ) ) ; } minDiff = Math . min ( minDiff , maxDiff ) ; } } return minDiff ; } public static void main ( String args [ ] ) { int n = 5 ; int k = 2 ; int a [ ] = { 3 , 7 , 8 , 10 , 14 } ; System . out . println ( minimumAdjacentDifference ( a , n , k ) ) ; } }

import sys NEW_LINE INT_MAX = sys . maxsize ; NEW_LINE INT_MIN = - ( sys . maxsize - 1 ) NEW_LINE def minimumAdjacentDifference ( a , n , k ) : NEW_LINE INDENT minDiff = INT_MAX ; NEW_LINE for i in range ( 1 << n ) : NEW_LINE INDENT cnt = bin ( i ) . count ( '1' ) ; NEW_LINE if ( cnt == n - k ) : NEW_LINE INDENT temp = [ ] ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( ( i & ( 1 << j ) ) != 0 ) : NEW_LINE INDENT temp . append ( a [ j ] ) ; NEW_LINE DEDENT DEDENT maxDiff = INT_MIN ; NEW_LINE for j in range ( len ( temp ) - 1 ) : NEW_LINE INDENT maxDiff = max ( maxDiff , temp [ j + 1 ] - temp [ j ] ) ; NEW_LINE DEDENT minDiff = min ( minDiff , maxDiff ) ; NEW_LINE DEDENT DEDENT return minDiff ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 ; NEW_LINE k = 2 ; NEW_LINE a = [ 3 , 7 , 8 , 10 , 14 ] ; NEW_LINE print ( minimumAdjacentDifference ( a , n , k ) ) ; NEW_LINE DEDENT


import java . util . Arrays ; class GFG { static int findNumber ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int max = arr [ n - 1 ] ; int table [ ] = new int [ ( 2 * max ) + 1 ] ; table [ 0 ] = 0 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) table [ i ] = Integer . MAX_VALUE ; int ans = - 1 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] <= i ) { int res = table [ i - arr [ j ] ] ; if ( res != Integer . MAX_VALUE && res + 1 < table [ i ] ) table [ i ] = res + 1 ; } } if ( i > arr [ n - 1 ] && table [ i ] == Integer . MAX_VALUE ) { ans = i ; break ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 7 , 15 } ; int n = arr . length ; System . out . println ( findNumber ( arr , n ) ) ; } }

def findNumber ( arr , n ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE Max = arr [ n - 1 ] NEW_LINE table = [ 10 ** 9 for i in range ( ( 2 * Max ) + 1 ) ] NEW_LINE table [ 0 ] = 0 NEW_LINE ans = - 1 NEW_LINE for i in range ( 1 , 2 * Max + 1 ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( arr [ j ] <= i ) : NEW_LINE INDENT res = table [ i - arr [ j ] ] NEW_LINE if ( res != 10 ** 9 and res + 1 < table [ i ] ) : NEW_LINE INDENT table [ i ] = res + 1 NEW_LINE DEDENT DEDENT DEDENT if ( i > arr [ n - 1 ] and table [ i ] == 10 ** 9 ) : NEW_LINE INDENT ans = i NEW_LINE break NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 6 , 7 , 15 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findNumber ( arr , n ) ) NEW_LINE