import java . io . * ; class GFG { static void perfectSquares ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { if ( Math . sqrt ( i ) == ( int ) Math . sqrt ( i ) ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int l = 2 , r = 24 ; perfectSquares ( l , r ) ; } }

def perfectSquares ( l , r ) : NEW_LINE INDENT for i in range ( l , r + 1 ) : NEW_LINE INDENT if ( i ** ( .5 ) == int ( i ** ( .5 ) ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT l = 2 NEW_LINE r = 24 NEW_LINE perfectSquares ( l , r ) NEW_LINE


import java . util . * ; class GFG { static boolean isDivisible ( int arr [ ] , int n ) { int lastDigit = arr [ n - 1 ] % 10 ; if ( lastDigit == 0 ) return true ; return false ; } static public void main ( String [ ] arg ) { int arr [ ] = { 12 , 65 , 46 , 37 , 99 } ; int n = arr . length ; if ( isDivisible ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isDivisible ( arr , n ) : NEW_LINE INDENT lastDigit = arr [ n - 1 ] % 10 ; NEW_LINE if ( lastDigit == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 12 , 65 , 46 , 37 , 99 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE if ( isDivisible ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT


class GFG { static int multiply ( int x , int y ) { if ( y == 0 ) return 0 ; if ( y > 0 ) return ( x + multiply ( x , y - 1 ) ) ; if ( y < 0 ) return - multiply ( x , - y ) ; return - 1 ; } public static void main ( String [ ] args ) { System . out . print ( " \n " + multiply ( 5 , - 11 ) ) ; } }

def multiply ( x , y ) : NEW_LINE INDENT if ( y == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( y > 0 ) : NEW_LINE INDENT return ( x + multiply ( x , y - 1 ) ) NEW_LINE DEDENT if ( y < 0 ) : NEW_LINE INDENT return - multiply ( x , - y ) NEW_LINE DEDENT DEDENT print ( multiply ( 5 , - 11 ) ) NEW_LINE


class GFG { static int findElement ( int arr [ ] , int n ) { int prefixMul [ ] = new int [ n ] ; prefixMul [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefixMul [ i ] = prefixMul [ i - 1 ] * arr [ i ] ; int suffixMul [ ] = new int [ n ] ; suffixMul [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffixMul [ i ] = suffixMul [ i + 1 ] * arr [ i ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) if ( prefixMul [ i ] == suffixMul [ i ] ) return arr [ i ] ; return - 1 ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 4 , 1 , 4 , 6 } ; int n = arr . length ; System . out . println ( findElement ( arr , n ) ) ; } }

def findElement ( arr , n ) : NEW_LINE INDENT prefixMul = [ ] NEW_LINE prefixMul . append ( arr [ 0 ] ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT prefixMul . append ( prefixMul [ i - 1 ] * arr [ i ] ) NEW_LINE DEDENT suffixMul = [ None for i in range ( 0 , n ) ] NEW_LINE suffixMul [ n - 1 ] = arr [ n - 1 ] NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT suffixMul [ i ] = suffixMul [ i + 1 ] * arr [ i ] NEW_LINE DEDENT for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if prefixMul [ i ] == suffixMul [ i ] : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ 2 , 3 , 4 , 1 , 4 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findElement ( arr , n ) ) NEW_LINE


class GFG { static final int R = 3 ; static final int C = 3 ; static int pathCountRec ( int mat [ ] [ ] , int m , int n , int k ) { if ( m < 0 || n < 0 ) { return 0 ; } if ( m == 0 && n == 0 && ( k == mat [ m ] [ n ] ) ) { return 1 ; } return pathCountRec ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountRec ( mat , m , n - 1 , k - mat [ m ] [ n ] ) ; } static int pathCount ( int mat [ ] [ ] , int k ) { return pathCountRec ( mat , R - 1 , C - 1 , k ) ; } public static void main ( String [ ] args ) { int k = 12 ; int mat [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 6 , 5 } , { 3 , 2 , 1 } } ; System . out . println ( pathCount ( mat , k ) ) ; } }

R = 3 NEW_LINE C = 3 NEW_LINE def pathCountRec ( mat , m , n , k ) : NEW_LINE INDENT if m < 0 or n < 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif m == 0 and n == 0 : NEW_LINE INDENT return k == mat [ m ] [ n ] NEW_LINE DEDENT return ( pathCountRec ( mat , m - 1 , n , k - mat [ m ] [ n ] ) + pathCountRec ( mat , m , n - 1 , k - mat [ m ] [ n ] ) ) NEW_LINE DEDENT def pathCount ( mat , k ) : NEW_LINE INDENT return pathCountRec ( mat , R - 1 , C - 1 , k ) NEW_LINE DEDENT k = 12 NEW_LINE mat = [ [ 1 , 2 , 3 ] , [ 4 , 6 , 5 ] , [ 3 , 2 , 1 ] ] NEW_LINE print ( pathCount ( mat , k ) ) NEW_LINE


import java . util . * ; class GFG { static void printMatrix ( int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i == j ) System . out . print ( k + " ▁ " ) ; else System . out . print ( "0 ▁ " ) ; } System . out . print ( " \n " ) ; } } public static void main ( String [ ] args ) { int n = 3 , k = 7 ; printMatrix ( n , k ) ; } }

def printMatrix ( n , k ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT print ( k , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( "0" , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 ; k = 7 ; NEW_LINE printMatrix ( n , k ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int fastPow ( int N , int K ) { if ( K == 0 ) return 1 ; int temp = fastPow ( N , K / 2 ) ; if ( K % 2 == 0 ) return temp * temp ; else return N * temp * temp ; } static int countWays ( int N , int K ) { return K * fastPow ( K - 1 , N - 1 ) ; } public static void main ( String [ ] args ) { int N = 3 , K = 3 ; System . out . println ( countWays ( N , K ) ) ; } }

def fastPow ( N , K ) : NEW_LINE INDENT if ( K == 0 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT temp = fastPow ( N , int ( K / 2 ) ) ; NEW_LINE if ( K % 2 == 0 ) : NEW_LINE INDENT return temp * temp ; NEW_LINE DEDENT else : NEW_LINE INDENT return N * temp * temp ; NEW_LINE DEDENT DEDENT def countWays ( N , K ) : NEW_LINE INDENT return K * fastPow ( K - 1 , N - 1 ) ; NEW_LINE DEDENT N = 3 ; NEW_LINE K = 3 ; NEW_LINE print ( countWays ( N , K ) ) ; NEW_LINE


class GfG { static int findCount ( int arr [ ] , int n ) { int countOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 1 ) countOdd ++ ; if ( countOdd % 2 == 0 ) return 1 ; else return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 5 , 1 } ; int n = arr . length ; System . out . println ( findCount ( arr , n ) ) ; } }

def findCount ( arr , n ) : NEW_LINE INDENT countOdd = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 1 ) : NEW_LINE INDENT countOdd += 1 ; NEW_LINE DEDENT DEDENT if ( countOdd % 2 == 0 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 5 , 1 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( findCount ( arr , n ) ) ; NEW_LINE DEDENT


class GFG { static int l [ ] [ ] = new int [ 1001 ] [ 1001 ] ; static void initialize ( ) { l [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i < 1001 ; i ++ ) { l [ i ] [ 0 ] = 1 ; for ( int j = 1 ; j < i + 1 ; j ++ ) { l [ i ] [ j ] = ( l [ i - 1 ] [ j - 1 ] + l [ i - 1 ] [ j ] ) ; } } } static int nCr ( int n , int r ) { return l [ n ] [ r ] ; } public static void main ( String [ ] args ) { initialize ( ) ; int n = 8 ; int r = 3 ; System . out . println ( nCr ( n , r ) ) ; } }

l = [ [ 0 for i in range ( 1001 ) ] for j in range ( 1001 ) ] NEW_LINE def initialize ( ) : NEW_LINE INDENT l [ 0 ] [ 0 ] = 1 NEW_LINE for i in range ( 1 , 1001 ) : NEW_LINE INDENT l [ i ] [ 0 ] = 1 NEW_LINE for j in range ( 1 , i + 1 ) : NEW_LINE INDENT l [ i ] [ j ] = ( l [ i - 1 ] [ j - 1 ] + l [ i - 1 ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT def nCr ( n , r ) : NEW_LINE INDENT return l [ n ] [ r ] NEW_LINE DEDENT initialize ( ) NEW_LINE n = 8 NEW_LINE r = 3 NEW_LINE print ( nCr ( n , r ) ) NEW_LINE


class GFG { public static int findNature ( int a , int b , int n ) { int [ ] seq = new int [ 100 ] ; seq [ 0 ] = a ; seq [ 1 ] = b ; for ( int i = 2 ; i <= n ; i ++ ) seq [ i ] = seq [ i - 1 ] + seq [ i - 2 ] ; if ( ( seq [ n ] & 1 ) != 0 ) return 1 ; else return 0 ; } public static void main ( String [ ] args ) { int a = 2 , b = 4 ; int n = 3 ; if ( findNature ( a , b , n ) == 1 ) System . out . println ( " Odd ▁ " ) ; else System . out . println ( " Even ▁ " ) ; } }

MAX = 100 ; NEW_LINE def findNature ( a , b , n ) : NEW_LINE INDENT seq = [ 0 ] * MAX ; NEW_LINE seq [ 0 ] = a ; NEW_LINE seq [ 1 ] = b ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT seq [ i ] = seq [ i - 1 ] + seq [ i - 2 ] ; NEW_LINE DEDENT return ( seq [ n ] & 1 ) ; NEW_LINE DEDENT a = 2 ; NEW_LINE b = 4 ; NEW_LINE n = 3 ; NEW_LINE if ( findNature ( a , b , n ) ) : NEW_LINE INDENT print ( " Odd " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Even " ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean isPerfectCubeString ( String str ) { int sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) sum += ( int ) str . charAt ( i ) ; double cr = Math . round ( Math . cbrt ( sum ) ) ; return ( cr * cr * cr == sum ) ; } public static void main ( String [ ] args ) { String str = " ll " ; if ( isPerfectCubeString ( str ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

from math import ceil NEW_LINE def isPerfectCubeString ( str1 ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( len ( str1 ) ) : NEW_LINE INDENT sum += ord ( str1 [ i ] ) NEW_LINE DEDENT cr = ceil ( ( sum ) ** ( 1 / 3 ) ) NEW_LINE return ( cr * cr * cr == sum ) NEW_LINE DEDENT str1 = " ll " NEW_LINE if ( isPerfectCubeString ( str1 ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class GFG { static int binarySearchCount ( int arr [ ] , int n , int key ) { int left = 0 , right = n ; int mid = 0 ; while ( left < right ) { mid = ( right + left ) >> 1 ; if ( arr [ mid ] == key ) { while ( mid + 1 < n && arr [ mid + 1 ] == key ) mid ++ ; break ; } else if ( arr [ mid ] > key ) right = mid ; else left = mid + 1 ; } while ( mid > - 1 && arr [ mid ] > key ) mid -- ; return mid + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 5 , 8 , 10 } ; int key = 11 ; int n = arr . length ; System . out . print ( binarySearchCount ( arr , n , key ) ) ; } }

def binarySearchCount ( arr , n , key ) : NEW_LINE INDENT left = 0 NEW_LINE right = n NEW_LINE mid = 0 NEW_LINE while ( left < right ) : NEW_LINE INDENT mid = ( right + left ) // 2 NEW_LINE if ( arr [ mid ] == key ) : NEW_LINE INDENT while ( mid + 1 < n and arr [ mid + 1 ] == key ) : NEW_LINE INDENT mid += 1 NEW_LINE DEDENT break NEW_LINE DEDENT elif ( arr [ mid ] > key ) : NEW_LINE INDENT right = mid NEW_LINE DEDENT else : NEW_LINE INDENT left = mid + 1 NEW_LINE DEDENT DEDENT while ( mid > - 1 and arr [ mid ] > key ) : NEW_LINE INDENT mid -= 1 NEW_LINE DEDENT return mid + 1 NEW_LINE DEDENT arr = [ 1 , 2 , 4 , 5 , 8 , 10 ] NEW_LINE key = 11 NEW_LINE n = len ( arr ) NEW_LINE print ( binarySearchCount ( arr , n , key ) ) NEW_LINE


import java . util . Arrays ; class Test { static int arr1 [ ] = new int [ ] { 1 , 5 , 9 , 10 , 15 , 20 } ; static int arr2 [ ] = new int [ ] { 2 , 3 , 8 , 13 } ; static void merge ( int m , int n ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { int j , last = arr1 [ m - 1 ] ; for ( j = m - 2 ; j >= 0 && arr1 [ j ] > arr2 [ i ] ; j -- ) arr1 [ j + 1 ] = arr1 [ j ] ; if ( j != m - 2 || last > arr2 [ i ] ) { arr1 [ j + 1 ] = arr2 [ i ] ; arr2 [ i ] = last ; } } } public static void main ( String [ ] args ) { merge ( arr1 . length , arr2 . length ) ; System . out . print ( " After ▁ Merging ▁ nFirst ▁ Array : ▁ " ) ; System . out . println ( Arrays . toString ( arr1 ) ) ; System . out . print ( " Second ▁ Array : ▁ ▁ " ) ; System . out . println ( Arrays . toString ( arr2 ) ) ; } }

def merge ( ar1 , ar2 , m , n ) : NEW_LINE INDENT for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT last = ar1 [ m - 1 ] NEW_LINE j = m - 2 NEW_LINE while ( j >= 0 and ar1 [ j ] > ar2 [ i ] ) : NEW_LINE INDENT ar1 [ j + 1 ] = ar1 [ j ] NEW_LINE j -= 1 NEW_LINE DEDENT if ( j != m - 2 or last > ar2 [ i ] ) : NEW_LINE INDENT ar1 [ j + 1 ] = ar2 [ i ] NEW_LINE ar2 [ i ] = last NEW_LINE DEDENT DEDENT DEDENT ar1 = [ 1 , 5 , 9 , 10 , 15 , 20 ] NEW_LINE ar2 = [ 2 , 3 , 8 , 13 ] NEW_LINE m = len ( ar1 ) NEW_LINE n = len ( ar2 ) NEW_LINE merge ( ar1 , ar2 , m , n ) NEW_LINE print ( " After ▁ Merging ▁ \n First ▁ Array : " , end = " " ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT print ( ar1 [ i ] , " ▁ " , end = " " ) NEW_LINE DEDENT print ( " \n Second ▁ Array : ▁ " , end = " " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( ar2 [ i ] , " ▁ " , end = " " ) NEW_LINE DEDENT


class GFG { static int maxPrimefactorNum ( int N ) { if ( N < 2 ) return 0 ; boolean [ ] arr = new boolean [ N + 1 ] ; int prod = 1 , res = 0 ; for ( int p = 2 ; p * p <= N ; p ++ ) { if ( arr [ p ] == false ) { for ( int i = p * 2 ; i <= N ; i += p ) arr [ i ] = true ; prod *= p ; if ( prod > N ) return res ; res ++ ; } } return res ; } public static void main ( String [ ] args ) { int N = 500 ; System . out . println ( maxPrimefactorNum ( N ) ) ; } }

def maxPrimefactorNum ( N ) : NEW_LINE INDENT if ( N < 2 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT arr = [ True ] * ( N + 1 ) ; NEW_LINE prod = 1 ; NEW_LINE res = 0 ; NEW_LINE p = 2 ; NEW_LINE while ( p * p <= N ) : NEW_LINE INDENT if ( arr [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , N + 1 , p ) : NEW_LINE INDENT arr [ i ] = False ; NEW_LINE DEDENT prod *= p ; NEW_LINE if ( prod > N ) : NEW_LINE INDENT return res ; NEW_LINE DEDENT res += 1 ; NEW_LINE DEDENT p += 1 ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT N = 500 ; NEW_LINE print ( maxPrimefactorNum ( N ) ) ; NEW_LINE


import static java . lang . Math . cos ; class GFG { static void cal_cos ( float n ) { float accuracy = ( float ) 0.0001 , x1 , denominator , cosx , cosval ; n = n * ( float ) ( 3.142 / 180.0 ) ; x1 = 1 ; cosx = x1 ; cosval = ( float ) cos ( n ) ; int i = 1 ; do { denominator = 2 * i * ( 2 * i - 1 ) ; x1 = - x1 * n * n / denominator ; cosx = cosx + x1 ; i = i + 1 ; } while ( accuracy <= cosval - cosx ) ; System . out . println ( cosx ) ; } public static void main ( String [ ] args ) { float n = 30 ; cal_cos ( n ) ; } }

from math import fabs , cos NEW_LINE def cal_cos ( n ) : NEW_LINE INDENT accuracy = 0.0001 NEW_LINE n = n * ( 3.142 / 180.0 ) NEW_LINE x1 = 1 NEW_LINE cosx = x1 NEW_LINE cosval = cos ( n ) NEW_LINE i = 1 NEW_LINE denominator = 2 * i * ( 2 * i - 1 ) NEW_LINE x1 = - x1 * n * n / denominator NEW_LINE cosx = cosx + x1 NEW_LINE i = i + 1 NEW_LINE while ( accuracy <= fabs ( cosval - cosx ) ) : NEW_LINE INDENT denominator = 2 * i * ( 2 * i - 1 ) NEW_LINE x1 = - x1 * n * n / denominator NEW_LINE cosx = cosx + x1 NEW_LINE i = i + 1 NEW_LINE DEDENT print ( ' { 0 : . 6 } ' . format ( cosx ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 30 NEW_LINE cal_cos ( n ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int sumDigits ( int n ) { int digit_sum = 0 ; while ( n > 0 ) { digit_sum += n % 10 ; n /= 10 ; } return digit_sum ; } static int productOfNumbers ( int [ ] arr , int n ) { int sum = Integer . MIN_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int product = arr [ i ] * arr [ j ] ; sum = Math . max ( sum , sumDigits ( product ) ) ; } } return sum ; } public static void main ( String [ ] args ) { int [ ] arr = { 4 , 3 , 5 } ; int n = arr . length ; System . out . print ( productOfNumbers ( arr , n ) ) ; } }

import sys NEW_LINE def sumDigits ( n ) : NEW_LINE INDENT digit_sum = 0 ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT digit_sum += n % 10 ; NEW_LINE n /= 10 ; NEW_LINE DEDENT return digit_sum ; NEW_LINE DEDENT def productOfNumbers ( arr , n ) : NEW_LINE INDENT sum = - sys . maxsize - 1 ; NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT product = arr [ i ] * arr [ j ] ; NEW_LINE sum = max ( sum , sumDigits ( product ) ) ; NEW_LINE DEDENT DEDENT return sum ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 3 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( int ( productOfNumbers ( arr , n ) ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { public static int findMaxRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . max ( A [ n - 1 ] , findMaxRec ( A , n - 1 ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . length ; System . out . println ( findMaxRec ( A , n ) ) ; } }

def findMaxRec ( A , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return A [ 0 ] NEW_LINE DEDENT return max ( A [ n - 1 ] , findMaxRec ( A , n - 1 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 1 , 4 , 45 , 6 , - 50 , 10 , 2 ] NEW_LINE n = len ( A ) NEW_LINE print ( findMaxRec ( A , n ) ) NEW_LINE DEDENT


class GFG { static int powmod ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int discreteLogarithm ( int a , int b , int m ) { int n = ( int ) ( Math . sqrt ( m ) + 1 ) ; int [ ] value = new int [ m ] ; for ( int i = n ; i >= 1 ; -- i ) value [ powmod ( a , i * n , m ) ] = i ; for ( int j = 0 ; j < n ; ++ j ) { int cur = ( powmod ( a , j , m ) * b ) % m ; if ( value [ cur ] > 0 ) { int ans = value [ cur ] * n - j ; if ( ans < m ) return ans ; } } return - 1 ; } public static void main ( String [ ] args ) { int a = 2 , b = 3 , m = 5 ; System . out . println ( discreteLogarithm ( a , b , m ) ) ; a = 3 ; b = 7 ; m = 11 ; System . out . println ( discreteLogarithm ( a , b , m ) ) ; } }

import math ; NEW_LINE def powmod ( x , y , p ) : NEW_LINE INDENT res = 1 ; NEW_LINE x = x % p ; NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p ; NEW_LINE DEDENT y = y >> 1 ; NEW_LINE x = ( x * x ) % p ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT def discreteLogarithm ( a , b , m ) : NEW_LINE INDENT n = int ( math . sqrt ( m ) + 1 ) ; NEW_LINE value = [ 0 ] * m ; NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT value [ powmod ( a , i * n , m ) ] = i ; NEW_LINE DEDENT for j in range ( n ) : NEW_LINE INDENT cur = ( powmod ( a , j , m ) * b ) % m ; NEW_LINE if ( value [ cur ] ) : NEW_LINE INDENT ans = value [ cur ] * n - j ; NEW_LINE if ( ans < m ) : NEW_LINE INDENT return ans ; NEW_LINE DEDENT DEDENT DEDENT return - 1 ; NEW_LINE DEDENT a = 2 ; NEW_LINE b = 3 ; NEW_LINE m = 5 ; NEW_LINE print ( discreteLogarithm ( a , b , m ) ) ; NEW_LINE a = 3 ; NEW_LINE b = 7 ; NEW_LINE m = 11 ; NEW_LINE print ( discreteLogarithm ( a , b , m ) ) ; NEW_LINE


import java . util . Arrays ; import java . io . * ; class GFG { static void maxProductSum ( String str , int m ) { int n = str . length ( ) ; int product = 1 , sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { sum += ( str . charAt ( i ) - '0' ) ; product *= ( str . charAt ( i ) - '0' ) ; } int maxProd = product ; int maxSum = sum ; for ( int i = m ; i < n ; i ++ ) { product = product * ( str . charAt ( i ) - '0' ) / ( ( str . charAt ( i - m ) ) - '0' ) ; sum = sum + ( str . charAt ( i ) - '0' ) - ( ( str . charAt ( i - m ) ) - '0' ) ; maxProd = Math . max ( maxProd , product ) ; maxSum = Math . max ( maxSum , sum ) ; } System . out . println ( " Maximum ▁ Product ▁ = ▁ " + maxProd ) ; System . out . println ( " \n Maximum ▁ Sum ▁ = ▁ " + maxSum ) ; } public static void main ( String [ ] args ) { String str = "3675356291" ; int m = 5 ; maxProductSum ( str , m ) ; } }

def maxProductSum ( str , m ) : NEW_LINE INDENT n = len ( str ) NEW_LINE product = 1 NEW_LINE sum = 0 NEW_LINE for i in range ( m ) : NEW_LINE INDENT sum += ( ord ( str [ i ] ) - ord ( '0' ) ) NEW_LINE product *= ( ord ( str [ i ] ) - ord ( '0' ) ) NEW_LINE DEDENT maxProd = product NEW_LINE maxSum = sum NEW_LINE for i in range ( m , n ) : NEW_LINE INDENT product = ( product * ( ord ( str [ i ] ) - ord ( '0' ) ) // ( ( ord ( str [ i - m ] ) ) - ord ( '0' ) ) ) NEW_LINE sum = ( sum + ( ord ( str [ i ] ) - ord ( '0' ) ) - ( ( ord ( str [ i - m ] ) ) - ord ( '0' ) ) ) NEW_LINE maxProd = max ( maxProd , product ) NEW_LINE maxSum = max ( maxSum , sum ) NEW_LINE DEDENT print ( " Maximum ▁ Product ▁ = " , maxProd ) NEW_LINE print ( " Maximum ▁ Sum ▁ = " , maxSum ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = "3675356291" NEW_LINE m = 5 NEW_LINE maxProductSum ( str , m ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int compositeProduct ( int arr [ ] , int n ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; boolean [ ] prime = new boolean [ max_val + 1 ] ; Arrays . fill ( prime , true ) ; prime [ 0 ] = true ; prime [ 1 ] = true ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) { prime [ i ] = false ; } } } int product = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! prime [ arr [ i ] ] ) { product *= arr [ i ] ; } } return product ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 , 7 } ; int n = arr . length ; System . out . println ( compositeProduct ( arr , n ) ) ; } }

import math as mt NEW_LINE def compositeProduct ( arr , n ) : NEW_LINE INDENT max_val = max ( arr ) NEW_LINE prime = [ True for i in range ( max_val + 1 ) ] NEW_LINE prime [ 0 ] = True NEW_LINE prime [ 1 ] = True NEW_LINE for p in range ( 2 , mt . ceil ( mt . sqrt ( max_val ) ) ) : NEW_LINE INDENT if prime [ p ] : NEW_LINE INDENT for i in range ( p * 2 , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT product = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if prime [ arr [ i ] ] == False : NEW_LINE INDENT product *= arr [ i ] NEW_LINE DEDENT DEDENT return product NEW_LINE DEDENT arr = [ 2 , 3 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( compositeProduct ( arr , n ) ) NEW_LINE


import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static int countIntervals ( int [ ] [ ] arr , int V , int N ) { int count = 0 ; int li , ri ; for ( int i = 0 ; i < N ; i ++ ) { li = arr [ i ] [ 0 ] ; ri = arr [ i ] [ 1 ] ; if ( V >= li && V <= ri ) count ++ ; } return count ; } public static void main ( String args [ ] ) { int [ ] [ ] arr = { { 1 , 10 } , { 5 , 10 } , { 15 , 25 } , { 7 , 12 } , { 20 , 25 } } ; int V = 7 ; int N = arr . length ; System . out . println ( countIntervals ( arr , V , N ) ) ; } }

def countIntervals ( arr , V , N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT li = arr [ i ] [ 0 ] NEW_LINE ri = arr [ i ] [ 1 ] NEW_LINE if ( V >= li and V <= ri ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ [ 1 , 10 ] , [ 5 , 10 ] , [ 15 , 25 ] , [ 7 , 12 ] , [ 20 , 25 ] ] NEW_LINE V = 7 NEW_LINE N = len ( arr ) NEW_LINE print ( ( countIntervals ( arr , V , N ) ) ) NEW_LINE DEDENT


class GFG { static void findUniquePair ( int [ ] arr , int n ) { int XOR = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) XOR = XOR ^ arr [ i ] ; int set_bit_no = XOR & ~ ( XOR - 1 ) ; int x = 0 , y = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & set_bit_no ) > 0 ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } System . out . println ( " The ▁ unique ▁ pair ▁ is ▁ ( " + x + " , " + y + " ) " ) ; } public static void main ( String [ ] args ) { int [ ] a = { 6 , 1 , 3 , 5 , 1 , 3 , 7 , 6 } ; int n = a . length ; findUniquePair ( a , n ) ; } }

def findUniquePair ( arr , n ) : NEW_LINE INDENT XOR = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT XOR = XOR ^ arr [ i ] NEW_LINE DEDENT set_bit_no = XOR & ~ ( XOR - 1 ) NEW_LINE x = 0 NEW_LINE y = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] & set_bit_no ) : NEW_LINE INDENT x = x ^ arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT y = y ^ arr [ i ] NEW_LINE DEDENT DEDENT print ( " The ▁ unique ▁ pair ▁ is ▁ ( " , x , " , ▁ " , y , " ) " , sep = " " ) NEW_LINE DEDENT a = [ 6 , 1 , 3 , 5 , 1 , 3 , 7 , 6 ] NEW_LINE n = len ( a ) NEW_LINE findUniquePair ( a , n ) NEW_LINE


class coin { static int minCoins ( int coins [ ] , int m , int V ) { if ( V == 0 ) return 0 ; int res = Integer . MAX_VALUE ; for ( int i = 0 ; i < m ; i ++ ) { if ( coins [ i ] <= V ) { int sub_res = minCoins ( coins , m , V - coins [ i ] ) ; if ( sub_res != Integer . MAX_VALUE && sub_res + 1 < res ) res = sub_res + 1 ; } } return res ; } public static void main ( String args [ ] ) { int coins [ ] = { 9 , 6 , 5 , 1 } ; int m = coins . length ; int V = 11 ; System . out . println ( " Minimum ▁ coins ▁ required ▁ is ▁ " + minCoins ( coins , m , V ) ) ; } }

import sys NEW_LINE def minCoins ( coins , m , V ) : NEW_LINE INDENT if ( V == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT res = sys . maxsize NEW_LINE for i in range ( 0 , m ) : NEW_LINE INDENT if ( coins [ i ] <= V ) : NEW_LINE INDENT sub_res = minCoins ( coins , m , V - coins [ i ] ) NEW_LINE if ( sub_res != sys . maxsize and sub_res + 1 < res ) : NEW_LINE INDENT res = sub_res + 1 NEW_LINE DEDENT DEDENT DEDENT return res NEW_LINE DEDENT coins = [ 9 , 6 , 5 , 1 ] NEW_LINE m = len ( coins ) NEW_LINE V = 11 NEW_LINE print ( " Minimum ▁ coins ▁ required ▁ is " , minCoins ( coins , m , V ) ) NEW_LINE


class GfG { static int foo ( ) { return 0 ; } public static int my_rand ( ) { int i ; i = 5 * foo ( ) + foo ( ) - 5 ; if ( i < 22 ) return i % 7 + 1 ; return my_rand ( ) ; } public static void main ( String [ ] args ) { System . out . println ( my_rand ( ) ) ; } }

def foo ( ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT def my_rand ( ) : NEW_LINE INDENT i = 0 ; NEW_LINE i = ( 5 * foo ( ) ) + ( foo ( ) - 5 ) ; NEW_LINE if ( i < 22 ) : NEW_LINE INDENT if ( i < 0 ) : NEW_LINE INDENT return ( i % 7 - 7 ) + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return ( i % 7 ) + 1 ; NEW_LINE DEDENT DEDENT return my_rand ( ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( my_rand ( ) ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int findLastIndex ( String str , Character x ) { int index = - 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( str . charAt ( i ) == x ) index = i ; return index ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; Character x = ' e ' ; int index = findLastIndex ( str , x ) ; if ( index == - 1 ) System . out . println ( " Character ▁ not ▁ found " ) ; else System . out . println ( " Last ▁ index ▁ is ▁ " + index ) ; } }

def findLastIndex ( str , x ) : NEW_LINE INDENT index = - 1 NEW_LINE for i in range ( 0 , len ( str ) ) : NEW_LINE INDENT if str [ i ] == x : NEW_LINE INDENT index = i NEW_LINE DEDENT DEDENT return index NEW_LINE DEDENT str = " geeksforgeeks " NEW_LINE x = ' e ' NEW_LINE index = findLastIndex ( str , x ) NEW_LINE if index == - 1 : NEW_LINE INDENT print ( " Character ▁ not ▁ found " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' Last ▁ index ▁ is ' , index ) NEW_LINE DEDENT


import java . lang . * ; class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 || n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static int primeBitsInRange ( int l , int r ) { int tot_bit , count = 0 ; for ( int i = l ; i <= r ; i ++ ) { tot_bit = Integer . bitCount ( i ) ; if ( isPrime ( tot_bit ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int l = 6 , r = 10 ; System . out . println ( primeBitsInRange ( l , r ) ) ; } }

def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : return False ; NEW_LINE if ( n <= 3 ) : return True ; NEW_LINE if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT i = 5 ; NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT i = i + 6 ; NEW_LINE DEDENT return True ; NEW_LINE DEDENT def primeBitsInRange ( l , r ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT tot_bit = bin ( i ) . count ( '1' ) ; NEW_LINE if ( isPrime ( tot_bit ) ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT l = 6 ; NEW_LINE r = 10 ; NEW_LINE print ( primeBitsInRange ( l , r ) ) ; NEW_LINE


public class GFG { static int sum ( int x , int y , int n ) { int sum1 = ( int ) ( ( Math . pow ( x , 2 ) * ( Math . pow ( x , 2 * n ) - 1 ) ) / ( Math . pow ( x , 2 ) - 1 ) ) ; int sum2 = ( int ) ( ( x * y * ( Math . pow ( x , n ) * Math . pow ( y , n ) - 1 ) ) / ( x * y - 1 ) ) ; return sum1 + sum2 ; } public static void main ( String args [ ] ) { int x = 2 , y = 2 , n = 2 ; System . out . println ( sum ( x , y , n ) ) ; } }

def sum ( x , y , n ) : NEW_LINE INDENT sum1 = ( ( x ** 2 ) * ( x ** ( 2 * n ) - 1 ) ) // ( x ** 2 - 1 ) NEW_LINE sum2 = ( x * y * ( x ** n * y ** n - 1 ) ) // ( x * y - 1 ) NEW_LINE return ( sum1 + sum2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 2 NEW_LINE y = 2 NEW_LINE n = 2 NEW_LINE print ( sum ( x , y , n ) ) NEW_LINE DEDENT


class GFG { static int calculateAreaSum ( int l , int b ) { int size = 1 ; int maxSize = Math . min ( l , b ) ; int totalArea = 0 ; for ( int i = 1 ; i <= maxSize ; i ++ ) { int totalSquares = ( l - size + 1 ) * ( b - size + 1 ) ; int area = totalSquares * size * size ; totalArea += area ; size ++ ; } return totalArea ; } public static void main ( String [ ] args ) { int l = 4 , b = 3 ; System . out . println ( calculateAreaSum ( l , b ) ) ; } }

def calculateAreaSum ( l , b ) : NEW_LINE INDENT size = 1 NEW_LINE maxSize = min ( l , b ) NEW_LINE totalArea = 0 NEW_LINE for i in range ( 1 , maxSize + 1 ) : NEW_LINE INDENT totalSquares = ( ( l - size + 1 ) * ( b - size + 1 ) ) NEW_LINE area = ( totalSquares * size * size ) NEW_LINE totalArea += area NEW_LINE size += 1 NEW_LINE DEDENT return totalArea NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l = 4 NEW_LINE b = 3 NEW_LINE print ( calculateAreaSum ( l , b ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { public static void main ( String [ ] args ) { int x = 10 ; int y = 5 ; x = x * y ; y = x / y ; x = x / y ; System . out . println ( " After ▁ swaping : " + " ▁ x ▁ = ▁ " + x + " , ▁ y ▁ = ▁ " + y ) ; } }

x = 10 NEW_LINE y = 5 NEW_LINE x = x * y NEW_LINE y = x // y ; NEW_LINE x = x // y ; NEW_LINE print ( " After ▁ Swapping : ▁ x ▁ = " , x , " ▁ y ▁ = " , y ) ; NEW_LINE


import java . util . * ; import java . lang . * ; class GFG { static int numberOfSolutions ( int n ) { int c = 0 ; for ( int x = 0 ; x <= n ; ++ x ) if ( n == x + ( n ^ x ) ) ++ c ; return c ; } public static void main ( String args [ ] ) { int n = 3 ; System . out . print ( numberOfSolutions ( n ) ) ; } }

def numberOfSolutions ( n ) : NEW_LINE INDENT c = 0 NEW_LINE for x in range ( n + 1 ) : NEW_LINE INDENT if ( n == ( x + ( n ^ x ) ) ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 NEW_LINE print ( numberOfSolutions ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int countPoints ( int n , int m , int a [ ] , int [ ] b , int x , int y ) { Arrays . sort ( a ) ; Arrays . sort ( b ) ; int j = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( a [ i ] + y < b [ j ] ) break ; if ( b [ j ] >= a [ i ] - x && b [ j ] <= a [ i ] + y ) { count ++ ; j ++ ; break ; } else j ++ ; } } return count ; } public static void main ( String args [ ] ) { int x = 1 , y = 4 ; int [ ] a = { 1 , 5 } ; int n = a . length ; int [ ] b = { 1 , 1 , 2 } ; int m = a . length ; System . out . println ( countPoints ( n , m , a , b , x , y ) ) ; } }

def countPoints ( n , m , a , b , x , y ) : NEW_LINE INDENT a . sort ( ) NEW_LINE b . sort ( ) NEW_LINE j , count = 0 , 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT while j < m : NEW_LINE INDENT if a [ i ] + y < b [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT if ( b [ j ] >= a [ i ] - x and b [ j ] <= a [ i ] + y ) : NEW_LINE INDENT count += 1 NEW_LINE j += 1 NEW_LINE break NEW_LINE DEDENT else : NEW_LINE INDENT j += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x , y = 1 , 4 NEW_LINE a = [ 1 , 5 ] NEW_LINE n = len ( a ) NEW_LINE b = [ 1 , 1 , 2 ] NEW_LINE m = len ( b ) NEW_LINE print ( countPoints ( n , m , a , b , x , y ) ) NEW_LINE DEDENT


class GFG { static int lcs ( String X , String Y , int m , int n ) { if ( m == 0 || n == 0 ) { return 0 ; } if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) { return 1 + lcs ( X , Y , m - 1 , n - 1 ) ; } else { return Math . max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ; } } public static void main ( String [ ] args ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; int m = X . length ( ) ; int n = Y . length ( ) ; System . out . println ( " Length ▁ of ▁ LCS : ▁ " + lcs ( X , Y , m , n ) ) ; } }

def lcs ( X , Y , m , n ) : NEW_LINE INDENT if ( m == 0 or n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( X [ m - 1 ] == Y [ n - 1 ] ) : NEW_LINE INDENT return 1 + lcs ( X , Y , m - 1 , n - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT return max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = " AGGTAB " NEW_LINE Y = " GXTXAYB " NEW_LINE m = len ( X ) NEW_LINE n = len ( Y ) NEW_LINE print ( " Length ▁ of ▁ LCS : " , lcs ( X , Y , m , n ) ) NEW_LINE DEDENT


public class GFG { static int sum ( int N , int X , int Y ) { int S1 , S2 , S3 ; S1 = ( ( N / X ) ) * ( 2 * X + ( N / X - 1 ) * X ) / 2 ; S2 = ( ( N / Y ) ) * ( 2 * Y + ( N / Y - 1 ) * Y ) / 2 ; S3 = ( ( N / ( X * Y ) ) ) * ( 2 * ( X * Y ) + ( N / ( X * Y ) - 1 ) * ( X * Y ) ) / 2 ; return S1 + S2 - S3 ; } public static void main ( String [ ] args ) { int N = 14 ; int X = 3 , Y = 5 ; System . out . println ( sum ( N , X , Y ) ) ; } }

from math import ceil , floor NEW_LINE def sum ( N , X , Y ) : NEW_LINE INDENT S1 = floor ( floor ( N / X ) * floor ( 2 * X + floor ( N / X - 1 ) * X ) / 2 ) NEW_LINE S2 = floor ( floor ( N / Y ) ) * floor ( 2 * Y + floor ( N / Y - 1 ) * Y ) / 2 NEW_LINE S3 = floor ( floor ( N / ( X * Y ) ) ) * floor ( 2 * ( X * Y ) + floor ( N / ( X * Y ) - 1 ) * ( X * Y ) ) / 2 NEW_LINE return S1 + S2 - S3 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 14 NEW_LINE X = 3 NEW_LINE Y = 5 NEW_LINE print ( int ( sum ( N , X , Y ) ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int numberOfDistinct ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { ans ++ ; if ( ( n / i ) != i ) ans ++ ; } } return ans ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( numberOfDistinct ( n ) ) ; } }

import math NEW_LINE def numberOfDistinct ( n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE if ( ( n // i ) != i ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 NEW_LINE print ( numberOfDistinct ( n ) ) NEW_LINE DEDENT


class GFG { static boolean isVowel ( char c ) { return ( c == ' A ' || c == ' E ' || c == ' I ' || c == ' O ' || c == ' U ' || c == ' a ' || c == ' e ' || c == ' i ' || c == ' o ' || c == ' u ' ) ; } static String pigLatin ( String s ) { int len = s . length ( ) ; int index = - 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( s . charAt ( i ) ) ) { index = i ; break ; } } if ( index == - 1 ) return " - 1" ; return s . substring ( index ) + s . substring ( 0 , index ) + " ay " ; } public static void main ( String [ ] args ) { String str = pigLatin ( " graphic " ) ; if ( str == " - 1" ) System . out . print ( " No ▁ vowels ▁ found . " + " Pig ▁ Latin ▁ not ▁ possible " ) ; else System . out . print ( str ) ; } }

def isVowel ( c ) : NEW_LINE INDENT return ( c == ' A ' or c == ' E ' or c == ' I ' or c == ' O ' or c == ' U ' or c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) ; NEW_LINE DEDENT def pigLatin ( s ) : NEW_LINE INDENT length = len ( s ) ; NEW_LINE index = - 1 ; NEW_LINE for i in range ( length ) : NEW_LINE INDENT if ( isVowel ( s [ i ] ) ) : NEW_LINE INDENT index = i ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( index == - 1 ) : NEW_LINE INDENT return " - 1" ; NEW_LINE DEDENT return s [ index : ] + s [ 0 : index ] + " ay " ; NEW_LINE DEDENT str = pigLatin ( " graphic " ) ; NEW_LINE if ( str == " - 1" ) : NEW_LINE INDENT print ( " No ▁ vowels ▁ found . ▁ Pig ▁ Latin ▁ not ▁ possible " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( str ) ; NEW_LINE DEDENT


class GFG { static int countMinSwaps ( String st ) { int min_swaps = 0 ; int odd_0 = 0 , even_0 = 0 ; int odd_1 = 0 , even_1 = 0 ; int n = st . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( st . charAt ( i ) == '1' ) even_1 ++ ; else even_0 ++ ; } else { if ( st . charAt ( i ) == '1' ) odd_1 ++ ; else odd_0 ++ ; } } int cnt_swaps_1 = Math . min ( even_0 , odd_1 ) ; int cnt_swaps_2 = Math . min ( even_1 , odd_0 ) ; return Math . min ( cnt_swaps_1 , cnt_swaps_2 ) ; } public static void main ( String [ ] args ) { String st = "000111" ; System . out . println ( countMinSwaps ( st ) ) ; } }

def countMinSwaps ( st ) : NEW_LINE INDENT min_swaps = 0 NEW_LINE odd_0 , even_0 = 0 , 0 NEW_LINE odd_1 , even_1 = 0 , 0 NEW_LINE n = len ( st ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT if st [ i ] == "1" : NEW_LINE INDENT even_1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT even_0 += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if st [ i ] == "1" : NEW_LINE INDENT odd_1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd_0 += 1 NEW_LINE DEDENT DEDENT DEDENT cnt_swaps_1 = min ( even_0 , odd_1 ) NEW_LINE cnt_swaps_2 = min ( even_1 , odd_0 ) NEW_LINE return min ( cnt_swaps_1 , cnt_swaps_2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT st = "000111" NEW_LINE print ( countMinSwaps ( st ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int N = 3 ; static void rotateMatrix ( int mat [ ] [ ] ) { for ( int i = N - 1 ; i >= 0 ; i -- ) { for ( int j = N - 1 ; j >= 0 ; j -- ) System . out . print ( mat [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; rotateMatrix ( mat ) ; } }

N = 3 ; NEW_LINE def rotateMatrix ( mat ) : NEW_LINE INDENT i = N - 1 ; NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT j = N - 1 ; NEW_LINE while ( j >= 0 ) : NEW_LINE INDENT print ( mat [ i ] [ j ] , end = " ▁ " ) ; NEW_LINE j = j - 1 ; NEW_LINE DEDENT print ( ) ; NEW_LINE i = i - 1 ; NEW_LINE DEDENT DEDENT mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; NEW_LINE rotateMatrix ( mat ) ; NEW_LINE


import java . io . * ; class GFG { static int nCr ( int n , int r ) { int ans = 1 ; for ( int i = 1 ; i <= r ; i += 1 ) { ans *= ( n - r + i ) ; ans /= i ; } return ans ; } static int total_ways ( int N , int X ) { return ( nCr ( N - 1 , X - 1 ) + nCr ( N - 1 , X ) ) ; } public static void main ( String [ ] args ) { int N = 5 , X = 3 ; System . out . println ( total_ways ( N , X ) ) ; } }

def nCr ( n , r ) : NEW_LINE INDENT ans = 1 ; NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT ans *= ( n - r + i ) ; NEW_LINE ans //= i ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT def total_ways ( N , X ) : NEW_LINE INDENT return ( nCr ( N - 1 , X - 1 ) + nCr ( N - 1 , X ) ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 ; X = 3 ; NEW_LINE print ( total_ways ( N , X ) ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int totalSumDivisibleByNum ( int digit , int number ) { int firstnum = ( int ) Math . pow ( 10 , digit - 1 ) ; int lastnum = ( int ) Math . pow ( 10 , digit ) ; firstnum = ( firstnum - firstnum % number ) + number ; lastnum = ( lastnum - lastnum % number ) ; int count = ( ( lastnum - firstnum ) / number + 1 ) ; return ( ( lastnum + firstnum ) * count ) / 2 ; } public static void main ( String [ ] args ) { int n = 3 , number = 7 ; System . out . println ( totalSumDivisibleByNum ( n , number ) ) ; } }

def totalSumDivisibleByNum ( digit , number ) : NEW_LINE INDENT firstnum = pow ( 10 , digit - 1 ) NEW_LINE lastnum = pow ( 10 , digit ) NEW_LINE firstnum = ( firstnum - firstnum % number ) + number NEW_LINE lastnum = ( lastnum - lastnum % number ) NEW_LINE count = ( ( lastnum - firstnum ) / number + 1 ) NEW_LINE return int ( ( ( lastnum + firstnum ) * count ) / 2 ) NEW_LINE DEDENT digit = 3 ; num = 7 NEW_LINE print ( totalSumDivisibleByNum ( digit , num ) ) NEW_LINE


class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } public static void main ( String args [ ] ) { if ( isPrime ( 11 ) ) System . out . println ( " ▁ true " ) ; else System . out . println ( " ▁ false " ) ; if ( isPrime ( 15 ) ) System . out . println ( " ▁ true " ) ; else System . out . println ( " ▁ false " ) ; } }

def isPrime ( n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT print ( " true " ) if isPrime ( 11 ) else print ( " false " ) NEW_LINE print ( " true " ) if isPrime ( 14 ) else print ( " false " ) NEW_LINE


import java . util . * ; class GFG { static void PowerOfTwo ( int [ ] x , int n ) { Arrays . sort ( x ) ; ArrayList < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = 1 ; j < 31 ; ++ j ) { int lx = x [ i ] - ( 1 << j ) ; int rx = x [ i ] + ( 1 << j ) ; boolean isl = Arrays . binarySearch ( x , lx ) < 0 ? false : true ; boolean isr = Arrays . binarySearch ( x , rx ) < 0 ? false : true ; if ( isl && isr && res . size ( ) < 3 ) { res . clear ( ) ; res . add ( lx ) ; res . add ( x [ i ] ) ; res . add ( rx ) ; } if ( isl && res . size ( ) < 2 ) { res . clear ( ) ; res . add ( lx ) ; res . add ( x [ i ] ) ; } if ( isr && res . size ( ) < 2 ) { res . clear ( ) ; res . add ( x [ i ] ) ; res . add ( rx ) ; } } } if ( res . size ( ) == 0 ) { System . out . println ( " - 1" ) ; return ; } for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int [ ] a = { 3 , 4 , 5 , 6 , 7 } ; int n = a . length ; PowerOfTwo ( a , n ) ; } }

def PowerOfTwo ( x , n ) : NEW_LINE INDENT x . sort ( ) NEW_LINE res = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( 1 , 31 ) : NEW_LINE INDENT lx = x [ i ] - ( 1 << j ) NEW_LINE rx = x [ i ] + ( 1 << j ) NEW_LINE if lx in x : NEW_LINE INDENT isl = True NEW_LINE DEDENT else : NEW_LINE INDENT isl = False NEW_LINE DEDENT if rx in x : NEW_LINE INDENT isr = True NEW_LINE DEDENT else : NEW_LINE INDENT isr = False NEW_LINE DEDENT if ( isl and isr and len ( res ) < 3 ) : NEW_LINE INDENT res = [ lx , x [ i ] , rx ] NEW_LINE DEDENT if ( isl and len ( res ) < 2 ) : NEW_LINE INDENT res = [ lx , x [ i ] ] NEW_LINE DEDENT if ( isr and len ( res ) < 2 ) : NEW_LINE INDENT res = [ x [ i ] , rx ] NEW_LINE DEDENT DEDENT DEDENT if ( not len ( res ) ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE return NEW_LINE DEDENT for it in res : NEW_LINE INDENT print ( it , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 3 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( a ) NEW_LINE PowerOfTwo ( a , n ) NEW_LINE DEDENT


class GFG { static void printPermutation ( int n , int k ) { for ( int i = 1 ; i <= n ; i ++ ) { int x = 2 * i - 1 ; int y = 2 * i ; if ( i <= k ) System . out . print ( y + " ▁ " + x + " ▁ " ) ; else System . out . print ( x + " ▁ " + y + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 2 , k = 1 ; printPermutation ( n , k ) ; } }

def printPermutation ( n , k ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT x = 2 * i - 1 ; NEW_LINE y = 2 * i ; NEW_LINE if ( i <= k ) : NEW_LINE INDENT print ( y , x , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( x , y , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 2 ; k = 1 ; NEW_LINE printPermutation ( n , k ) ; NEW_LINE DEDENT


import java . util . * ; public class GFG { static int [ ] getFrequencies ( String str ) { int freq [ ] = new int [ 26 ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { freq [ str . charAt ( i ) - ' a ' ] ++ ; } return freq ; } static int countMinParts ( String str ) { int n = str . length ( ) ; int freq [ ] = getFrequencies ( str ) ; List < Integer > oddFreq = new ArrayList < > ( ) ; List < Integer > evenFreq = new ArrayList < > ( ) ; int i , sumEven = 0 ; for ( i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] == 0 ) continue ; if ( freq [ i ] % 2 == 0 ) evenFreq . add ( freq [ i ] ) ; else oddFreq . add ( freq [ i ] ) ; } for ( i = 0 ; i < evenFreq . size ( ) ; i ++ ) { sumEven += evenFreq . get ( i ) ; } if ( oddFreq . size ( ) == 0 ) return 1 ; if ( sumEven == 0 ) { if ( oddFreq . size ( ) == 1 ) return 1 ; return 0 ; } i = 0 ; while ( i < oddFreq . size ( ) ) { if ( ( sumEven / 2 ) % oddFreq . size ( ) == 0 ) return oddFreq . size ( ) ; if ( oddFreq . get ( i ) == 1 ) { i ++ ; continue ; } sumEven += 2 ; oddFreq . set ( i , oddFreq . get ( i ) - 2 ) ; } return n ; } public static void main ( String [ ] args ) { String s = " noonpeep " ; System . out . println ( countMinParts ( s ) ) ; } }

def getFrequencies ( string ) : NEW_LINE INDENT freq = [ 0 ] * 26 NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT freq [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT return freq NEW_LINE DEDENT def countMinParts ( string ) : NEW_LINE INDENT n = len ( string ) NEW_LINE freq = getFrequencies ( string ) NEW_LINE oddFreq = [ ] NEW_LINE evenFreq = [ ] NEW_LINE sumEven = 0 NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT if freq [ i ] == 0 : NEW_LINE INDENT continue NEW_LINE DEDENT if freq [ i ] % 2 == 0 : NEW_LINE INDENT evenFreq . append ( freq [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT oddFreq . append ( freq [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( evenFreq ) ) : NEW_LINE INDENT sumEven += evenFreq [ i ] NEW_LINE DEDENT if len ( oddFreq ) == 0 : NEW_LINE INDENT return 1 NEW_LINE DEDENT if sumEven == 0 : NEW_LINE INDENT if len ( oddFreq ) == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT i = 0 NEW_LINE while ( i < len ( oddFreq ) ) : NEW_LINE INDENT if ( ( sumEven / 2 ) % len ( oddFreq ) == 0 ) : NEW_LINE INDENT return len ( oddFreq ) NEW_LINE DEDENT if ( oddFreq [ i ] == 1 ) : NEW_LINE INDENT i += 1 NEW_LINE continue NEW_LINE DEDENT sumEven += 2 NEW_LINE oddFreq [ i ] = oddFreq [ i ] - 2 NEW_LINE DEDENT return n NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " noonpeep " NEW_LINE print ( countMinParts ( s ) ) NEW_LINE DEDENT


class GFG { static boolean isPossible ( int a [ ] , int n ) { int k = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != i + 1 ) k ++ ; } if ( k <= 2 ) return true ; return false ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 2 , 3 , 4 , 1 } ; int n = a . length ; if ( isPossible ( a , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isPossible ( a , n ) : NEW_LINE INDENT k = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] != i + 1 ) : NEW_LINE INDENT k += 1 ; NEW_LINE DEDENT DEDENT if ( k <= 2 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 5 , 2 , 3 , 4 , 1 ] ; NEW_LINE n = len ( a ) ; NEW_LINE if ( isPossible ( a , n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { public static long maxOR ( long arr [ ] , int n , int k , int x ) { long preSum [ ] = new long [ n + 1 ] ; long suffSum [ ] = new long [ n + 1 ] ; long res = 0 , pow = 1 ; for ( int i = 0 ; i < k ; i ++ ) pow *= x ; preSum [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) preSum [ i + 1 ] = preSum [ i ] | arr [ i ] ; suffSum [ n ] = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) suffSum [ i ] = suffSum [ i + 1 ] | arr [ i ] ; res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res = Math . max ( res , preSum [ i ] | ( arr [ i ] * pow ) | suffSum [ i + 1 ] ) ; return res ; } public static void main ( String args [ ] ) { long arr [ ] = { 1 , 2 , 4 , 8 } ; int n = 4 ; int k = 2 , x = 3 ; long ans = maxOR ( arr , n , k , x ) ; System . out . println ( ans ) ; } }

def maxOR ( arr , n , k , x ) : NEW_LINE INDENT preSum = [ 0 ] * ( n + 1 ) NEW_LINE suffSum = [ 0 ] * ( n + 1 ) NEW_LINE pow = 1 NEW_LINE for i in range ( 0 , k ) : NEW_LINE INDENT pow *= x NEW_LINE DEDENT preSum [ 0 ] = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT preSum [ i + 1 ] = preSum [ i ] | arr [ i ] NEW_LINE DEDENT suffSum [ n ] = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT suffSum [ i ] = suffSum [ i + 1 ] | arr [ i ] NEW_LINE DEDENT res = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT res = max ( res , preSum [ i ] | ( arr [ i ] * pow ) | suffSum [ i + 1 ] ) NEW_LINE DEDENT return res NEW_LINE DEDENT arr = [ 1 , 2 , 4 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE k = 2 NEW_LINE x = 3 NEW_LINE print ( maxOR ( arr , n , k , x ) ) NEW_LINE


import java . util . * ; class GFG { static int MAX = 1000001 ; static int countNum ( int N , int K ) { int [ ] sumPF = new int [ MAX ] ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == 0 ) { for ( int j = i ; j < N ; j += i ) { sumPF [ j ] += i ; } } } int count = 0 ; for ( int i = 2 ; i < N ; i ++ ) { if ( sumPF [ i ] == K ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int N = 20 , K = 7 ; System . out . println ( countNum ( N , K ) ) ; } }

MAX = 1000001 NEW_LINE def countNum ( N , K ) : NEW_LINE INDENT sumPF = [ 0 ] * MAX ; NEW_LINE for i in range ( 2 , N ) : NEW_LINE INDENT if ( sumPF [ i ] == 0 ) : NEW_LINE INDENT for j in range ( i , N , i ) : NEW_LINE INDENT sumPF [ j ] += i ; NEW_LINE DEDENT DEDENT DEDENT count = 0 ; NEW_LINE for i in range ( 2 , N ) : NEW_LINE INDENT if ( sumPF [ i ] == K ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 20 ; K = 7 ; NEW_LINE print ( countNum ( N , K ) ) ; NEW_LINE DEDENT


class GFG { static int getMaxLength ( boolean arr [ ] , int n ) { int count = 0 ; int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == false ) count = 0 ; else { count ++ ; result = Math . max ( result , count ) ; } } return result ; } public static void main ( String [ ] args ) { boolean arr [ ] = { true , true , false , false , true , false , true , false , true , true , true , true } ; int n = arr . length ; System . out . println ( getMaxLength ( arr , n ) ) ; } }

def getMaxLength ( arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE result = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT count = 0 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE result = max ( result , count ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ 1 , 1 , 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( getMaxLength ( arr , n ) ) NEW_LINE


import java . io . * ; class GFG { static int countIntegralSolutions ( int n ) { int result = 0 ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n - i ; j ++ ) for ( int k = 0 ; k <= ( n - i - j ) ; k ++ ) if ( i + j + k == n ) result ++ ; return result ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countIntegralSolutions ( n ) ) ; } }

def countIntegralSolutions ( n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT for k in range ( n + 1 ) : NEW_LINE INDENT if i + j + k == n : NEW_LINE INDENT result += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return result NEW_LINE DEDENT n = 3 NEW_LINE print ( countIntegralSolutions ( n ) ) NEW_LINE


class GFG { static double square ( double a ) { if ( a < 0 ) return - 1 ; double x = 0.464 * a ; return x ; } public static void main ( String [ ] args ) { double a = 5 ; System . out . println ( square ( a ) ) ; } }

def square ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT x = 0.464 * a NEW_LINE return x NEW_LINE DEDENT a = 5 NEW_LINE print ( square ( a ) ) NEW_LINE


class GFG { static int nthTerm ( int N ) { int nth = 0 ; if ( N % 2 == 1 ) nth = ( N * N ) + 1 ; else nth = ( N * N ) - 1 ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( nthTerm ( N ) + " \n " ) ; } }

def nthTerm ( N ) : NEW_LINE INDENT nth = 0 ; NEW_LINE if ( N % 2 == 1 ) : NEW_LINE INDENT nth = ( N * N ) + 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT nth = ( N * N ) - 1 ; NEW_LINE DEDENT return nth ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 ; NEW_LINE print ( nthTerm ( N ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static int max_intersection ( int center [ ] , int length , int k ) { Arrays . sort ( center ) ; if ( center [ 2 ] - center [ 0 ] >= 2 * k + length ) { return 0 ; } else if ( center [ 2 ] - center [ 0 ] >= 2 * k ) { return ( 2 * k - ( center [ 2 ] - center [ 0 ] - length ) ) ; } else return length ; } public static void main ( String args [ ] ) { int center [ ] = { 1 , 2 , 3 } ; int L = 1 ; int K = 1 ; System . out . println ( max_intersection ( center , L , K ) ) ; } }

def max_intersection ( center , length , k ) : NEW_LINE INDENT center . sort ( ) ; NEW_LINE if ( center [ 2 ] - center [ 0 ] >= 2 * k + length ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT elif ( center [ 2 ] - center [ 0 ] >= 2 * k ) : NEW_LINE INDENT return ( 2 * k - ( center [ 2 ] - center [ 0 ] - length ) ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return length ; NEW_LINE DEDENT DEDENT center = [ 1 , 2 , 3 ] ; NEW_LINE L = 1 ; NEW_LINE K = 1 ; NEW_LINE print ( max_intersection ( center , L , K ) ) ; NEW_LINE


import java . io . * ; class GFG { static boolean isValid ( long i , long m ) { long sq_i = ( long ) Math . sqrt ( i ) ; long sq = Math . min ( m , sq_i ) ; for ( long j = 2 ; j <= sq ; j ++ ) if ( i % j == 0 ) return false ; return true ; } static void findLargestNum ( long n , long m ) { for ( long i = n ; i > m ; i -- ) { if ( isValid ( i , m ) ) { System . out . println ( i ) ; return ; } } System . out . println ( " Number ▁ Doesn ' t ▁ Exists " ) ; } public static void main ( String [ ] args ) { long n = 16 , m = 3 ; findLargestNum ( n , m ) ; } }

import math NEW_LINE def isValid ( i , m ) : NEW_LINE INDENT sq_i = math . sqrt ( i ) NEW_LINE sq = min ( m , sq_i ) NEW_LINE for j in range ( 2 , sq + 1 ) : NEW_LINE INDENT if ( i % j == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def findLargestNum ( n , m ) : NEW_LINE INDENT for i in range ( n , m , - 1 ) : NEW_LINE INDENT if ( isValid ( i , m ) ) : NEW_LINE INDENT print ( " { } \n " . format ( i ) ) ; NEW_LINE return NEW_LINE DEDENT DEDENT print ( " Number ▁ Doesn ' t ▁ Exists \n " ) NEW_LINE DEDENT n = 16 NEW_LINE m = 3 NEW_LINE findLargestNum ( n , m ) NEW_LINE


class GFG { static int countSquares ( int n ) { return ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( " Count ▁ of ▁ squares ▁ is ▁ " + countSquares ( n ) ) ; } }

def countSquares ( n ) : NEW_LINE INDENT return ( ( n * ( n + 1 ) / 2 ) * ( 2 * n + 1 ) / 3 ) NEW_LINE DEDENT n = 4 NEW_LINE print ( " Count ▁ of ▁ squares ▁ is ▁ " , countSquares ( n ) ) NEW_LINE


import java . io . * ; import java . util . * ; import java . text . * ; import java . math . * ; import java . util . regex . * ; class GFG { public static void maxOverlap ( int [ ] start , int [ ] end , int n ) { int maxa = Arrays . stream ( start ) . max ( ) . getAsInt ( ) ; int maxb = Arrays . stream ( end ) . max ( ) . getAsInt ( ) ; int maxc = Math . max ( maxa , maxb ) ; int [ ] x = new int [ maxc + 2 ] ; Arrays . fill ( x , 0 ) ; int cur = 0 , idx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ++ x [ start [ i ] ] ; -- x [ end [ i ] + 1 ] ; } int maxy = Integer . MIN_VALUE ; for ( int i = 0 ; i <= maxc ; i ++ ) { cur += x [ i ] ; if ( maxy < cur ) { maxy = cur ; idx = i ; } } System . out . println ( " Maximum ▁ value ▁ is : " + maxy + " ▁ at ▁ position : ▁ " + idx + " " ) ; } public static void main ( String [ ] args ) { int [ ] start = new int [ ] { 13 , 28 , 29 , 14 , 40 , 17 , 3 } ; int [ ] end = new int [ ] { 107 , 95 , 111 , 105 , 70 , 127 , 74 } ; int n = start . length ; maxOverlap ( start , end , n ) ; } }

import sys NEW_LINE def maxOverlap ( start , end ) : NEW_LINE INDENT n = len ( start ) NEW_LINE maxa = max ( start ) NEW_LINE maxb = max ( end ) NEW_LINE maxc = max ( maxa , maxb ) NEW_LINE x = ( maxc + 2 ) * [ 0 ] NEW_LINE cur = 0 ; idx = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT x [ start [ i ] ] += 1 NEW_LINE x [ end [ i ] + 1 ] -= 1 NEW_LINE DEDENT maxy = - 1 NEW_LINE for i in range ( 0 , maxc + 1 ) : NEW_LINE INDENT cur += x [ i ] NEW_LINE if maxy < cur : NEW_LINE INDENT maxy = cur NEW_LINE idx = i NEW_LINE DEDENT DEDENT print ( " Maximum ▁ value ▁ is : ▁ { 0 : d } " . format ( maxy ) , " ▁ at ▁ position : ▁ { 0 : d } " . format ( idx ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT start = [ 13 , 28 , 29 , 14 , 40 , 17 , 3 ] NEW_LINE end = [ 107 , 95 , 111 , 105 , 70 , 127 , 74 ] NEW_LINE maxOverlap ( start , end ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void constructDp ( int dp [ ] [ ] , String str ) { int l = str . length ( ) ; int [ ] [ ] isPalin = new int [ l + 1 ] [ l + 1 ] ; for ( int i = 0 ; i <= l ; i ++ ) { for ( int j = 0 ; j <= l ; j ++ ) { isPalin [ i ] [ j ] = dp [ i ] [ j ] = 0 ; } } for ( int i = l - 1 ; i >= 0 ; i -- ) { isPalin [ i ] [ i ] = 1 ; dp [ i ] [ i ] = 1 ; for ( int j = i + 1 ; j < l ; j ++ ) { isPalin [ i ] [ j ] = ( str . charAt ( i ) == str . charAt ( j ) && ( i + 1 > j - 1 || ( isPalin [ i + 1 ] [ j - 1 ] ) != 0 ) ) ? 1 : 0 ; dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] + isPalin [ i ] [ j ] ; } } } static int countOfPalindromeInRange ( int dp [ ] [ ] , int l , int r ) { return dp [ l ] [ r ] ; } public static void main ( String args [ ] ) { int MAX = 50 ; String str = " xyaabax " ; int [ ] [ ] dp = new int [ MAX ] [ MAX ] ; constructDp ( dp , str ) ; int l = 3 ; int r = 5 ; System . out . println ( countOfPalindromeInRange ( dp , l , r ) ) ; } }

M = 50 NEW_LINE def constructDP ( dp , string ) : NEW_LINE INDENT l = len ( string ) NEW_LINE isPalin = [ [ 0 for i in range ( l + 1 ) ] for j in range ( l + 1 ) ] NEW_LINE for i in range ( l - 1 , - 1 , - 1 ) : NEW_LINE INDENT isPalin [ i ] [ i ] , dp [ i ] [ i ] = 1 , 1 NEW_LINE for j in range ( i + 1 , l ) : NEW_LINE INDENT isPalin [ i ] [ j ] = ( string [ i ] == string [ j ] and ( i + 1 > j - 1 or isPalin [ i + 1 ] [ j - 1 ] ) ) NEW_LINE dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i + 1 ] [ j ] - dp [ i + 1 ] [ j - 1 ] + isPalin [ i ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT def countOfPalindromeInRange ( dp , l , r ) : NEW_LINE INDENT return dp [ l ] [ r ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " xyaabax " NEW_LINE dp = [ [ 0 for i in range ( M ) ] for j in range ( M ) ] NEW_LINE constructDP ( dp , string ) NEW_LINE l , r = 3 , 5 NEW_LINE print ( countOfPalindromeInRange ( dp , l , r ) ) NEW_LINE DEDENT


class GFG { public static int areCornerEqual ( String s ) { int n = s . length ( ) ; if ( n < 2 ) return - 1 ; if ( s . charAt ( 0 ) == s . charAt ( n - 1 ) ) return 1 ; else return 0 ; } public static void main ( String [ ] args ) { String s = " GfG " ; int res = areCornerEqual ( s ) ; if ( res == - 1 ) System . out . println ( " Invalid ▁ Input " ) ; else if ( res == 1 ) System . out . println ( " Equal " ) ; else System . out . println ( " Not ▁ Equal " ) ; } }

st = " GfG " NEW_LINE if ( st [ 0 ] == st [ - 1 ] ) : NEW_LINE INDENT print ( " Equal " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Equal " ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public void bfs ( int x , int num ) { Queue < Integer > q = new LinkedList < Integer > ( ) ; q . add ( num ) ; while ( ! q . isEmpty ( ) ) { num = q . peek ( ) ; q . poll ( ) ; if ( num <= x ) { System . out . print ( num + " ▁ " ) ; int last_digit = num % 10 ; if ( last_digit == 0 ) { q . add ( ( num * 10 ) + ( last_digit + 1 ) ) ; } else if ( last_digit == 9 ) { q . add ( ( num * 10 ) + ( last_digit - 1 ) ) ; } else { q . add ( ( num * 10 ) + ( last_digit - 1 ) ) ; q . add ( ( num * 10 ) + ( last_digit + 1 ) ) ; } } } } public void printJumping ( int x ) { System . out . print ( "0 ▁ " ) ; for ( int i = 1 ; i <= 9 && i <= x ; i ++ ) { this . bfs ( x , i ) ; } } public static void main ( String [ ] args ) throws IOException { int x = 40 ; GFG obj = new GFG ( ) ; obj . printJumping ( x ) ; } }

class Queue : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . lst = [ ] NEW_LINE DEDENT def is_empty ( self ) : NEW_LINE INDENT return self . lst == [ ] NEW_LINE DEDENT def enqueue ( self , elem ) : NEW_LINE INDENT self . lst . append ( elem ) NEW_LINE DEDENT def dequeue ( self ) : NEW_LINE INDENT return self . lst . pop ( 0 ) NEW_LINE DEDENT DEDENT def bfs ( x , num ) : NEW_LINE INDENT q = Queue ( ) NEW_LINE q . enqueue ( num ) NEW_LINE while ( not q . is_empty ( ) ) : NEW_LINE INDENT num = q . dequeue ( ) NEW_LINE if num <= x : NEW_LINE INDENT print ( str ( num ) , end = ' ▁ ' ) NEW_LINE last_dig = num % 10 NEW_LINE if last_dig == 0 : NEW_LINE INDENT q . enqueue ( ( num * 10 ) + ( last_dig + 1 ) ) NEW_LINE DEDENT elif last_dig == 9 : NEW_LINE INDENT q . enqueue ( ( num * 10 ) + ( last_dig - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT q . enqueue ( ( num * 10 ) + ( last_dig - 1 ) ) NEW_LINE q . enqueue ( ( num * 10 ) + ( last_dig + 1 ) ) NEW_LINE DEDENT DEDENT DEDENT DEDENT def printJumping ( x ) : NEW_LINE INDENT print ( str ( 0 ) , end = ' ▁ ' ) NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT bfs ( x , i ) NEW_LINE DEDENT DEDENT x = 40 NEW_LINE printJumping ( x ) NEW_LINE


import java . util . * ; class GFG { public static int findMinRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . length ; System . out . println ( findMinRec ( A , n ) ) ; } }

def findMinRec ( A , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return A [ 0 ] NEW_LINE DEDENT return min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT A = [ 1 , 4 , 45 , 6 , - 50 , 10 , 2 ] NEW_LINE n = len ( A ) NEW_LINE print ( findMinRec ( A , n ) ) NEW_LINE DEDENT


class GFG { static boolean check ( int arr [ ] , int n ) { int modify = 0 ; if ( arr [ 0 ] > arr [ 1 ] ) { arr [ 0 ] = arr [ 1 ] / 2 ; modify ++ ; } for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( arr [ i - 1 ] < arr [ i ] && arr [ i + 1 ] < arr [ i ] ) || ( arr [ i - 1 ] > arr [ i ] && arr [ i + 1 ] > arr [ i ] ) ) { arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) / 2 ; if ( arr [ i ] == arr [ i - 1 ] || arr [ i ] == arr [ i + 1 ] ) return false ; modify ++ ; } } if ( arr [ n - 1 ] < arr [ n - 2 ] ) modify ++ ; if ( modify > 1 ) return false ; return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 8 , 6 , 9 , 12 } ; int n = arr . length ; if ( check ( arr , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

def check ( arr , n ) : NEW_LINE INDENT modify = 0 NEW_LINE if ( arr [ 0 ] > arr [ 1 ] ) : NEW_LINE INDENT arr [ 0 ] = arr [ 1 ] // 2 NEW_LINE modify += 1 NEW_LINE DEDENT for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( ( arr [ i - 1 ] < arr [ i ] and arr [ i + 1 ] < arr [ i ] ) or ( arr [ i - 1 ] > arr [ i ] and arr [ i + 1 ] > arr [ i ] ) ) : NEW_LINE INDENT arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) // 2 NEW_LINE if ( arr [ i ] == arr [ i - 1 ] or arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT modify += 1 NEW_LINE DEDENT DEDENT if ( arr [ n - 1 ] < arr [ n - 2 ] ) : NEW_LINE INDENT modify += 1 NEW_LINE DEDENT if ( modify > 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 4 , 8 , 6 , 9 , 12 ] 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 DEDENT


class GFG { static boolean isPerfectSquare ( int N ) { double sr = Math . sqrt ( N ) ; return ( sr - Math . floor ( sr ) ) == 0 ; } static void BetrothedNumbers ( int n , int m ) { int Sum1 = 1 ; int Sum2 = 1 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { Sum1 += i + ( isPerfectSquare ( n ) ? 0 : n / i ) ; } } for ( int i = 2 ; i <= Math . sqrt ( m ) ; i ++ ) { if ( m % i == 0 ) { Sum2 += i + ( isPerfectSquare ( m ) ? 0 : m / i ) ; } } if ( ( n + 1 == Sum2 ) && ( m + 1 == Sum1 ) ) { System . out . print ( " YES " + " \n " ) ; } else { System . out . print ( " NO " + " \n " ) ; } } public static void main ( String [ ] args ) { int N = 9504 ; int M = 20734 ; BetrothedNumbers ( N , M ) ; } }

from math import sqrt , floor NEW_LINE def isPerfectSquare ( N ) : NEW_LINE INDENT sr = sqrt ( N ) NEW_LINE return ( sr - floor ( sr ) ) == 0 NEW_LINE DEDENT def BetrothedNumbers ( n , m ) : NEW_LINE INDENT Sum1 = 1 NEW_LINE Sum2 = 1 NEW_LINE for i in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( isPerfectSquare ( n ) ) : NEW_LINE INDENT Sum1 += i NEW_LINE DEDENT else : NEW_LINE INDENT Sum1 += i + n / i NEW_LINE DEDENT DEDENT DEDENT for i in range ( 2 , int ( sqrt ( m ) ) + 1 , 1 ) : NEW_LINE INDENT if ( m % i == 0 ) : NEW_LINE INDENT if ( isPerfectSquare ( m ) ) : NEW_LINE INDENT Sum2 += i NEW_LINE DEDENT else : NEW_LINE INDENT Sum2 += i + ( m / i ) NEW_LINE DEDENT DEDENT DEDENT if ( ( n + 1 == Sum2 ) and ( m + 1 == Sum1 ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 9504 NEW_LINE M = 20734 NEW_LINE BetrothedNumbers ( N , M ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int maximumXor ( int arr [ ] , int n ) { Stack < Integer > sForward = new Stack < Integer > ( ) , sBackward = new Stack < Integer > ( ) ; int ans = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { while ( ! sForward . isEmpty ( ) && arr [ i ] < arr [ sForward . peek ( ) ] ) { ans = Math . max ( ans , arr [ i ] ^ arr [ sForward . peek ( ) ] ) ; sForward . pop ( ) ; } sForward . add ( i ) ; while ( ! sBackward . isEmpty ( ) && arr [ n - i - 1 ] < arr [ sBackward . peek ( ) ] ) { ans = Math . max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward . peek ( ) ] ) ; sBackward . pop ( ) ; } sBackward . add ( n - i - 1 ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 1 , 2 } ; int n = arr . length ; System . out . print ( maximumXor ( arr , n ) ) ; } }

def maximumXor ( arr : list , n : int ) -> int : NEW_LINE INDENT sForward , sBackward = [ ] , [ ] NEW_LINE ans = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT while len ( sForward ) > 0 and arr [ i ] < arr [ sForward [ - 1 ] ] : NEW_LINE INDENT ans = max ( ans , arr [ i ] ^ arr [ sForward [ - 1 ] ] ) NEW_LINE sForward . pop ( ) NEW_LINE DEDENT sForward . append ( i ) NEW_LINE while len ( sBackward ) > 0 and arr [ n - i - 1 ] < arr [ sBackward [ - 1 ] ] : NEW_LINE INDENT ans = max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward [ - 1 ] ] ) NEW_LINE sBackward . pop ( ) NEW_LINE DEDENT sBackward . append ( n - i - 1 ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 8 , 1 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maximumXor ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int maxDiff ( int arr [ ] , int n ) { int maxDiff = - 1 ; int maxRight = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > maxRight ) maxRight = arr [ i ] ; else { int diff = maxRight - arr [ i ] ; if ( diff > maxDiff ) { maxDiff = diff ; } } } return maxDiff ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 90 , 10 , 110 } ; int n = arr . length ; System . out . println ( " Maximum ▁ difference ▁ is ▁ " + maxDiff ( arr , n ) ) ; } }

def maxDiff ( arr , n ) : NEW_LINE INDENT maxDiff = - 1 NEW_LINE maxRight = arr [ n - 1 ] NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] > maxRight ) : NEW_LINE INDENT maxRight = arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT diff = maxRight - arr [ i ] NEW_LINE if ( diff > maxDiff ) : NEW_LINE INDENT maxDiff = diff NEW_LINE DEDENT DEDENT DEDENT return maxDiff NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 90 , 10 , 110 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , n ) ) NEW_LINE DEDENT


class GFG { public static int CntDivbyX ( int arr [ ] , int n , int x ) { int number = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { number = ( number * 2 + arr [ i ] ) % x ; if ( number == 0 ) count += 1 ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 0 } ; int n = 7 ; int x = 2 ; System . out . print ( CntDivbyX ( arr , n , x ) ) ; } }

def CntDivbyX ( arr , n , x ) : NEW_LINE INDENT number = 0 NEW_LINE count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT number = ( number * 2 + arr [ i ] ) % x NEW_LINE if number == 0 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ] NEW_LINE n = 7 NEW_LINE x = 2 NEW_LINE print ( CntDivbyX ( arr , n , x ) ) NEW_LINE


class GFG { static int sumOfFactors ( int n ) { int sum = 0 ; for ( int f = 1 ; f <= n / 2 ; f ++ ) { if ( n % f == 0 ) { sum += f ; } } return sum ; } static int getSum ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 && arr [ i ] == sumOfFactors ( arr [ i ] ) ) { sum += arr [ i ] ; } } return sum ; } public static void main ( String [ ] args ) { int [ ] arr = { 17 , 6 , 10 , 6 , 4 } ; int n = arr . length ; System . out . print ( getSum ( arr , n ) ) ; } }

def sumOfFactors ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for f in range ( 1 , n // 2 + 1 ) : NEW_LINE INDENT if ( n % f == 0 ) : NEW_LINE INDENT sum += f NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT def getSum ( arr , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > 0 and arr [ i ] == sumOfFactors ( arr [ i ] ) ) : NEW_LINE INDENT sum += arr [ i ] NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT arr = [ 17 , 6 , 10 , 6 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( getSum ( arr , n ) ) NEW_LINE


class GfG { static long getTrailingZeroes ( long n ) { long count = 0 ; long val , powerTwo = 2 ; do { val = n / powerTwo ; count += val ; powerTwo *= 2 ; } while ( val != 0 ) ; return ( count / 4 ) ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( getTrailingZeroes ( n ) ) ; } }

def getTrailingZeroes ( n ) : NEW_LINE INDENT count = 0 NEW_LINE val , powerTwo = 1 , 2 NEW_LINE while ( val != 0 ) : NEW_LINE INDENT val = n // powerTwo NEW_LINE count += val NEW_LINE powerTwo *= 2 NEW_LINE DEDENT return ( count // 4 ) NEW_LINE DEDENT n = 6 NEW_LINE print ( getTrailingZeroes ( n ) ) NEW_LINE


import java . util . * ; class Solution { static int maxGCD ( int N , int P ) { int ans = 1 ; Map < Integer , Integer > prime_factors = new HashMap < Integer , Integer > ( ) ; for ( int i = 2 ; i * i <= P ; i ++ ) { while ( P % i == 0 ) { if ( prime_factors . get ( i ) == null ) prime_factors . put ( i , 1 ) ; else prime_factors . put ( i , ( prime_factors . get ( i ) + 1 ) ) ; P /= i ; } } if ( P != 1 ) if ( prime_factors . get ( P ) == null ) prime_factors . put ( P , 1 ) ; else prime_factors . put ( P , ( prime_factors . get ( P ) + 1 ) ) ; Set < Map . Entry < Integer , Integer > > st = prime_factors . entrySet ( ) ; for ( Map . Entry < Integer , Integer > me : st ) { ans *= Math . pow ( me . getKey ( ) , me . getValue ( ) / N ) ; } return ans ; } public static void main ( String args [ ] ) { int N = 3 , P = 24 ; System . out . println ( maxGCD ( N , P ) ) ; } }

from math import sqrt NEW_LINE def maxGCD ( N , P ) : NEW_LINE INDENT ans = 1 NEW_LINE prime_factors = { } NEW_LINE for i in range ( 2 , int ( sqrt ( P ) + 1 ) ) : NEW_LINE INDENT while ( P % i == 0 ) : NEW_LINE INDENT if i not in prime_factors : NEW_LINE INDENT prime_factors [ i ] = 0 NEW_LINE DEDENT prime_factors [ i ] += 1 NEW_LINE P //= i NEW_LINE DEDENT DEDENT if ( P != 1 ) : NEW_LINE INDENT prime_factors [ P ] += 1 NEW_LINE DEDENT for key , value in prime_factors . items ( ) : NEW_LINE INDENT ans *= pow ( key , value // N ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N , P = 3 , 24 NEW_LINE print ( maxGCD ( N , P ) ) NEW_LINE DEDENT


class GFG { static int findNumber ( int n , int m ) { int num = ( m - 1 ) * 9 + n ; return num ; } public static void main ( String args [ ] ) { int n = 2 , m = 5 ; System . out . print ( findNumber ( n , m ) ) ; } }

def findNumber ( n , m ) : NEW_LINE INDENT num = ( m - 1 ) * 9 + n ; NEW_LINE return num ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 2 ; NEW_LINE m = 5 ; NEW_LINE print ( findNumber ( n , m ) ) NEW_LINE DEDENT


public class GFG { static boolean checkPrime ( int numberToCheck ) { if ( numberToCheck == 1 ) { return false ; } for ( int i = 2 ; i * i <= numberToCheck ; i ++ ) { if ( numberToCheck % i == 0 ) { return false ; } } return true ; } static int primeSum ( int l , int r ) { int sum = 0 ; for ( int i = r ; i >= l ; i -- ) { boolean isPrime = checkPrime ( i ) ; if ( isPrime ) { sum = sum + i ; } } return sum ; } public static void main ( String [ ] args ) { int l = 4 , r = 13 ; System . out . println ( primeSum ( l , r ) ) ; } }

from math import sqrt NEW_LINE def checkPrime ( numberToCheck ) : NEW_LINE INDENT if numberToCheck == 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( numberToCheck ) ) + 1 ) : NEW_LINE INDENT if numberToCheck % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def primeSum ( l , r ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( r , ( l - 1 ) , - 1 ) : NEW_LINE INDENT isPrime = checkPrime ( i ) NEW_LINE if ( isPrime ) : NEW_LINE INDENT sum += i NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l , r = 4 , 13 NEW_LINE print ( primeSum ( l , r ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int countways ( int a [ ] , int n ) { int cnt [ ] = new int [ n ] ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += a [ i ] ; } if ( s % 3 != 0 ) return 0 ; s /= 3 ; int ss = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { ss += a [ i ] ; if ( ss == s ) cnt [ i ] = 1 ; } for ( int i = n - 2 ; i >= 0 ; i -- ) cnt [ i ] += cnt [ i + 1 ] ; int ans = 0 ; ss = 0 ; for ( int i = 0 ; i + 2 < n ; i ++ ) { ss += a [ i ] ; if ( ss == s ) ans += cnt [ i + 2 ] ; } return ans ; } public static void main ( String [ ] args ) { int n = 5 ; int a [ ] = { 1 , 2 , 3 , 0 , 3 } ; System . out . println ( countways ( a , n ) ) ; } }

def countways ( a , n ) : NEW_LINE INDENT cnt = [ 0 for i in range ( n ) ] NEW_LINE s = 0 NEW_LINE s = sum ( a ) NEW_LINE if ( s % 3 != 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT s //= 3 NEW_LINE ss = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT ss += a [ i ] NEW_LINE if ( ss == s ) : NEW_LINE INDENT cnt [ i ] = 1 NEW_LINE DEDENT DEDENT for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT cnt [ i ] += cnt [ i + 1 ] NEW_LINE DEDENT ans = 0 NEW_LINE ss = 0 NEW_LINE for i in range ( 0 , n - 2 ) : NEW_LINE INDENT ss += a [ i ] NEW_LINE if ( ss == s ) : NEW_LINE INDENT ans += cnt [ i + 2 ] NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT n = 5 NEW_LINE a = [ 1 , 2 , 3 , 0 , 3 ] NEW_LINE print ( countways ( a , n ) ) NEW_LINE


class GFG { static void lower ( int matrix [ ] [ ] , int row , int col ) { int i , j ; for ( i = 0 ; i < row ; i ++ ) { for ( j = 0 ; j < col ; j ++ ) { if ( i < j ) { System . out . print ( "0" + " ▁ " ) ; } else System . out . print ( matrix [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } static void upper ( int matrix [ ] [ ] , int row , int col ) { int i , j ; for ( i = 0 ; i < row ; i ++ ) { for ( j = 0 ; j < col ; j ++ ) { if ( i > j ) { System . out . print ( "0" + " ▁ " ) ; } else System . out . print ( matrix [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String args [ ] ) { int matrix [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int row = 3 , col = 3 ; System . out . println ( " Lower ▁ triangular ▁ matrix : ▁ " ) ; lower ( matrix , row , col ) ; System . out . println ( " Upper ▁ triangular ▁ matrix : ▁ " ) ; upper ( matrix , row , col ) ; } }

def lower ( matrix , row , col ) : NEW_LINE INDENT for i in range ( 0 , row ) : NEW_LINE INDENT for j in range ( 0 , col ) : NEW_LINE INDENT if ( i < j ) : NEW_LINE INDENT print ( "0" , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( matrix [ i ] [ j ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( " ▁ " ) ; NEW_LINE DEDENT DEDENT def upper ( matrix , row , col ) : NEW_LINE INDENT for i in range ( 0 , row ) : NEW_LINE INDENT for j in range ( 0 , col ) : NEW_LINE INDENT if ( i > j ) : NEW_LINE INDENT print ( "0" , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( matrix [ i ] [ j ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( " ▁ " ) ; NEW_LINE DEDENT DEDENT matrix = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] ; NEW_LINE row = 3 ; NEW_LINE col = 3 ; NEW_LINE print ( " Lower ▁ triangular ▁ matrix : ▁ " ) ; NEW_LINE lower ( matrix , row , col ) ; NEW_LINE print ( " Upper ▁ triangular ▁ matrix : ▁ " ) ; NEW_LINE upper ( matrix , row , col ) ; NEW_LINE


public class GFG { static void find_array ( int [ ] a , int n ) { int x = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] += x ; System . out . print ( a [ i ] + " ▁ " ) ; x = Math . max ( x , a [ i ] ) ; } } public static void main ( String [ ] args ) { int [ ] a = { 40 , 12 , 62 } ; int n = a . length ; find_array ( a , n ) ; } }

def find_array ( a , n ) : NEW_LINE INDENT x = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] += x ; NEW_LINE print ( a [ i ] , end = ' ▁ ' ) ; NEW_LINE x = max ( x , a [ i ] ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 40 , 12 , 62 ] ; NEW_LINE n = len ( a ) ; NEW_LINE find_array ( a , n ) ; NEW_LINE DEDENT


class GFG { static int MAX = 100005 ; static boolean [ ] prime = new boolean [ MAX ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < MAX ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } } static int countPrimes ( int n ) { SieveOfEratosthenes ( ) ; int cnt = 0 ; for ( int i = 2 ; i < n ; i ++ ) { if ( prime [ i ] && prime [ i - 2 ] ) cnt ++ ; } return cnt ; } public static void main ( String [ ] args ) { int n = 11 ; System . out . print ( countPrimes ( n ) ) ; } }

MAX = 100005 NEW_LINE prime = [ True for i in range ( MAX ) ] NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE for p in range ( MAX ) : NEW_LINE INDENT if ( p * p > MAX ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( 2 * p , MAX , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def countPrimes ( n ) : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE cnt = 0 NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( prime [ i ] and prime [ i - 2 ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT n = 11 NEW_LINE print ( countPrimes ( n ) ) NEW_LINE


import java . util . * ; class GFG { static void reverseColumns ( int arr [ ] [ ] ) { for ( int i = 0 ; i < arr [ 0 ] . length ; i ++ ) for ( int j = 0 , k = arr [ 0 ] . length - 1 ; j < k ; j ++ , k -- ) { int temp = arr [ j ] [ i ] ; arr [ j ] [ i ] = arr [ k ] [ i ] ; arr [ k ] [ i ] = temp ; } } static void transpose ( int arr [ ] [ ] ) { for ( int i = 0 ; i < arr . length ; i ++ ) for ( int j = i ; j < arr [ 0 ] . length ; j ++ ) { int temp = arr [ j ] [ i ] ; arr [ j ] [ i ] = arr [ i ] [ j ] ; arr [ i ] [ j ] = temp ; } } static void printMatrix ( int arr [ ] [ ] ) { for ( int i = 0 ; i < arr . length ; i ++ ) { for ( int j = 0 ; j < arr [ 0 ] . length ; j ++ ) System . out . print ( arr [ i ] [ j ] + " ▁ " ) ; System . out . println ( " " ) ; } } static void rotate90 ( int arr [ ] [ ] ) { transpose ( arr ) ; reverseColumns ( arr ) ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; rotate90 ( arr ) ; printMatrix ( arr ) ; } }

R = 4 NEW_LINE C = 4 NEW_LINE def reverseColumns ( arr ) : NEW_LINE INDENT for i in range ( C ) : NEW_LINE INDENT j = 0 NEW_LINE k = C - 1 NEW_LINE while j < k : NEW_LINE INDENT t = arr [ j ] [ i ] NEW_LINE arr [ j ] [ i ] = arr [ k ] [ i ] NEW_LINE arr [ k ] [ i ] = t NEW_LINE j += 1 NEW_LINE k -= 1 NEW_LINE DEDENT DEDENT DEDENT def transpose ( arr ) : NEW_LINE INDENT for i in range ( R ) : NEW_LINE INDENT for j in range ( i , C ) : NEW_LINE INDENT t = arr [ i ] [ j ] NEW_LINE arr [ i ] [ j ] = arr [ j ] [ i ] NEW_LINE arr [ j ] [ i ] = t NEW_LINE DEDENT DEDENT DEDENT def printMatrix ( arr ) : NEW_LINE INDENT for i in range ( R ) : NEW_LINE INDENT for j in range ( C ) : NEW_LINE INDENT print ( str ( arr [ i ] [ j ] ) , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT def rotate90 ( arr ) : NEW_LINE INDENT transpose ( arr ) NEW_LINE reverseColumns ( arr ) NEW_LINE DEDENT arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ] ; NEW_LINE rotate90 ( arr ) NEW_LINE printMatrix ( arr ) NEW_LINE


import java . io . * ; class GFG { static int countWays ( int n , int m ) { int count [ ] = new int [ n + 1 ] ; count [ 0 ] = 0 ; int i ; for ( i = 1 ; i <= n ; i ++ ) { if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ; else if ( i < m ) count [ i ] = 1 ; else count [ i ] = 2 ; } return count [ n ] ; } public static void main ( String [ ] args ) { int n = 7 ; int m = 4 ; System . out . println ( " Number ▁ of ▁ ways ▁ = ▁ " + countWays ( n , m ) ) ; } }

def countWays ( n , m ) : NEW_LINE INDENT count = [ ] NEW_LINE for i in range ( n + 2 ) : NEW_LINE INDENT count . append ( 0 ) NEW_LINE DEDENT count [ 0 ] = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( i > m ) : NEW_LINE INDENT count [ i ] = count [ i - 1 ] + count [ i - m ] NEW_LINE DEDENT elif ( i < m ) : NEW_LINE INDENT count [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT count [ i ] = 2 NEW_LINE DEDENT DEDENT return count [ n ] NEW_LINE DEDENT n = 7 NEW_LINE m = 4 NEW_LINE print ( " Number ▁ of ▁ ways ▁ = ▁ " , countWays ( n , m ) ) NEW_LINE


class GFG { static int minLength ( int n ) { int ans = n / 26 ; if ( n % 26 != 0 ) ans ++ ; return ans ; } static String minString ( int n ) { int ans = n / 26 ; String res = " " ; while ( ans -- != 0 ) { res = res + " z " ; } if ( n % 26 != 0 ) { res = res + ( char ) ( ( n % 26 ) + 96 ) ; } return res ; } public static void main ( String [ ] args ) { int n = 50 ; System . out . println ( minLength ( n ) ) ; System . out . println ( minString ( n ) ) ; } }

def minLength ( n ) : NEW_LINE INDENT ans = n // 26 NEW_LINE if ( n % 26 != 0 ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT def minString ( n ) : NEW_LINE INDENT ans = n // 26 NEW_LINE res = " " NEW_LINE while ( ans ) : NEW_LINE INDENT res = res + " z " NEW_LINE ans -= 1 NEW_LINE DEDENT if ( n % 26 != 0 ) : NEW_LINE INDENT res = res + chr ( ( n % 26 ) + 96 ) NEW_LINE DEDENT return res NEW_LINE DEDENT n = 50 ; NEW_LINE print ( minLength ( n ) ) NEW_LINE print ( minString ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int Largestpower ( int n , int p ) { int ans = 0 ; while ( n > 0 ) { n /= p ; ans += n ; } return ans ; } public static void main ( String [ ] args ) { int n = 10 ; int p = 3 ; System . out . println ( " ▁ The ▁ largest ▁ power ▁ of ▁ " + p + " ▁ that ▁ divides ▁ " + n + " ! ▁ is ▁ " + Largestpower ( n , p ) ) ; } }

def largestPower ( n , p ) : NEW_LINE INDENT x = 0 NEW_LINE while n : NEW_LINE INDENT n /= p NEW_LINE x += n NEW_LINE DEDENT return x NEW_LINE DEDENT n = 10 ; p = 3 NEW_LINE print ( " The ▁ largest ▁ power ▁ of ▁ % d ▁ that ▁ divides ▁ % d ! ▁ is ▁ % d \n " % ( p , n , largestPower ( n , p ) ) ) NEW_LINE


class GFG { public static void main ( String [ ] args ) { int i , j , r , N , N1 ; N1 = 3 ; N = 0 ; r = 5 ; for ( i = 0 ; i < r ; i ++ ) { if ( i <= r / 2 ) { N = N1 ; for ( j = 0 ; j <= i ; j ++ ) { N ++ ; } N1 = N ; for ( j = 0 ; j <= i ; j ++ ) { N -- ; System . out . print ( N + " ▁ " ) ; } System . out . println ( ) ; } else { for ( j = i ; j < r ; j ++ ) { N -- ; System . out . print ( N + " ▁ " ) ; } System . out . println ( ) ; } } } } ;

if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N1 = 3 NEW_LINE N = 0 ; NEW_LINE r = 5 ; NEW_LINE for i in range ( r ) : NEW_LINE INDENT if i <= r // 2 : NEW_LINE INDENT N = N1 NEW_LINE for j in range ( i + 1 ) : NEW_LINE INDENT N += 1 NEW_LINE DEDENT N1 = N NEW_LINE for j in range ( i + 1 ) : NEW_LINE INDENT N -= 1 NEW_LINE print ( N , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT else : NEW_LINE INDENT for j in range ( i , r ) : NEW_LINE INDENT N -= 1 NEW_LINE print ( N , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT DEDENT


import java . io . * ; class GFG { static long findTriangularNumber ( int n ) { return ( n * ( n + 1 ) ) / 2 ; } static void printSeries ( int n ) { long prev = 0 ; long curr ; for ( int i = 1 ; i <= n ; i ++ ) { curr = findTriangularNumber ( i ) ; curr = curr + prev ; System . out . print ( curr + " ▁ " ) ; prev = curr ; } } public static void main ( String [ ] args ) { int n = 10 ; printSeries ( n ) ; } }

def findTriangularNumber ( n ) : NEW_LINE INDENT return ( n * ( n + 1 ) ) / 2 NEW_LINE DEDENT def printSeries ( n ) : NEW_LINE INDENT prev = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT curr = findTriangularNumber ( i ) NEW_LINE curr = int ( curr + prev ) NEW_LINE print ( curr , end = ' ▁ ' ) NEW_LINE prev = curr NEW_LINE DEDENT DEDENT n = 10 NEW_LINE printSeries ( n ) NEW_LINE


import java . io . * ; class GFG { static int getMin ( int arr [ ] , int n ) { int res = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) res = Math . min ( res , arr [ i ] ) ; return res ; } static int getMax ( int arr [ ] , int n ) { int res = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) res = Math . max ( res , arr [ i ] ) ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; System . out . println ( " Minimum ▁ element " + " ▁ of ▁ array : ▁ " + getMin ( arr , n ) ) ; System . out . println ( " Maximum ▁ element " + " ▁ of ▁ array : ▁ " + getMax ( arr , n ) ) ; } }

def getMin ( arr , n ) : NEW_LINE INDENT res = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT res = min ( res , arr [ i ] ) NEW_LINE DEDENT return res NEW_LINE DEDENT def getMax ( arr , n ) : NEW_LINE INDENT res = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT res = max ( res , arr [ i ] ) NEW_LINE DEDENT return res NEW_LINE DEDENT arr = [ 12 , 1234 , 45 , 67 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Minimum ▁ element ▁ of ▁ array : " , getMin ( arr , n ) ) NEW_LINE print ( " Maximum ▁ element ▁ of ▁ array : " , getMax ( arr , n ) ) NEW_LINE


static void printSeqRecur ( int num , int pos , int k , int n ) { if ( pos == k ) { System . out . print ( num + " ▁ " ) ; return ; } for ( int i = 1 ; i <= n ; i ++ ) { printSeqRecur ( num * 10 + i , pos + 1 , k , n ) ; } } static void printSequences ( int k , int n ) { printSeqRecur ( 0 , 0 , k , n ) ; }

def printSeqRecur ( num , n , k ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT print ( num ) NEW_LINE return NEW_LINE DEDENT for _ in range ( 1 , k + 1 ) : NEW_LINE INDENT printSeqRecur ( num * 10 + _ , n - 1 , k ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT k = 3 NEW_LINE n = 2 NEW_LINE printSeqRecur ( 0 , n , k ) NEW_LINE DEDENT


import java . io . * ; public class GFG { static float emi_calculator ( float p , float r , float t ) { float emi ; r = r / ( 12 * 100 ) ; t = t * 12 ; emi = ( p * r * ( float ) Math . pow ( 1 + r , t ) ) / ( float ) ( Math . pow ( 1 + r , t ) - 1 ) ; return ( emi ) ; } static public void main ( String [ ] args ) { float principal , rate , time , emi ; principal = 10000 ; rate = 10 ; time = 2 ; emi = emi_calculator ( principal , rate , time ) ; System . out . println ( " Monthly ▁ EMI ▁ is ▁ = ▁ " + emi ) ; } }

def emi_calculator ( p , r , t ) : NEW_LINE INDENT r = r / ( 12 * 100 ) NEW_LINE t = t * 12 NEW_LINE emi = ( p * r * pow ( 1 + r , t ) ) / ( pow ( 1 + r , t ) - 1 ) NEW_LINE return emi NEW_LINE DEDENT principal = 10000 ; NEW_LINE rate = 10 ; NEW_LINE time = 2 ; NEW_LINE emi = emi_calculator ( principal , rate , time ) ; NEW_LINE print ( " Monthly ▁ EMI ▁ is = ▁ " , emi ) NEW_LINE


class GFG { static int minOperations ( int n , String a , String b , String c ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { char x = a . charAt ( i ) ; char y = b . charAt ( i ) ; char z = c . charAt ( i ) ; if ( x == y && y == z ) ; else if ( x == y || y == z || x == z ) { ans ++ ; } else { ans += 2 ; } } return ans ; } public static void main ( String [ ] args ) { String a = " place " ; String b = " abcde " ; String c = " plybe " ; int n = a . length ( ) ; System . out . print ( minOperations ( n , a , b , c ) ) ; } }

def minOperations ( n , a , b , c ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = a [ i ] NEW_LINE y = b [ i ] NEW_LINE z = c [ i ] NEW_LINE if ( x == y and y == z ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif ( x == y or y == z or x == z ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += 2 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = " place " NEW_LINE b = " abcde " NEW_LINE c = " plybe " NEW_LINE n = len ( a ) NEW_LINE print ( minOperations ( n , a , b , c ) ) NEW_LINE DEDENT


class GFG { static void findRealAndImag ( String s ) { int l = s . length ( ) ; int i ; if ( s . indexOf ( ' + ' ) != - 1 ) { i = s . indexOf ( ' + ' ) ; } else { i = s . indexOf ( ' - ' ) ; } String real = s . substring ( 0 , i ) ; String imaginary = s . substring ( i + 1 , l - 1 ) ; System . out . println ( " Real ▁ part : ▁ " + real ) ; System . out . println ( " Imaginary ▁ part : ▁ " + imaginary ) ; } public static void main ( String [ ] args ) { String s = "3 + 4i " ; findRealAndImag ( s ) ; } }

def findRealAndImag ( s ) : NEW_LINE INDENT l = len ( s ) NEW_LINE i = 0 NEW_LINE if ( s . find ( ' + ' ) != - 1 ) : NEW_LINE INDENT i = s . find ( ' + ' ) NEW_LINE DEDENT else : NEW_LINE INDENT i = s . find ( ' - ' ) ; NEW_LINE DEDENT real = s [ : i ] NEW_LINE imaginary = s [ i + 1 : l - 1 ] NEW_LINE print ( " Real ▁ part : " , real ) NEW_LINE print ( " Imaginary ▁ part : " , imaginary ) NEW_LINE DEDENT s = "3 + 4i " ; NEW_LINE findRealAndImag ( s ) ; NEW_LINE


class GFG { static void convert_str ( String str , int k ) { char [ ] s = str . toCharArray ( ) ; int l = s . length ; for ( int i = 0 ; i < l ; i ++ ) { int ascii = ( int ) s [ i ] ; if ( ascii >= ' a ' && ascii <= ' z ' && __gcd ( ascii , k ) == 1 ) { char c = ( char ) ( s [ i ] - 32 ) ; s [ i ] = c ; } } System . out . println ( String . valueOf ( s ) ) ; } static int __gcd ( int a , int b ) { if ( a == 0 ) { return b ; } if ( b == 0 ) { return a ; } if ( a == b ) { return a ; } if ( a > b ) { return __gcd ( a - b , b ) ; } return __gcd ( a , b - a ) ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; int k = 4 ; convert_str ( s , k ) ; } }

from math import gcd NEW_LINE def convert_str ( s , k ) : NEW_LINE INDENT modified_string = " " NEW_LINE for i in range ( 0 , len ( s ) ) : NEW_LINE INDENT ascii = ord ( s [ i ] ) NEW_LINE if ( ascii >= ord ( ' a ' ) and ascii <= ord ( ' z ' ) and gcd ( ascii , k ) == 1 ) : NEW_LINE INDENT modified_string += chr ( ascii - 32 ) NEW_LINE DEDENT else : NEW_LINE INDENT modified_string += s [ i ] NEW_LINE DEDENT DEDENT print ( modified_string ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " geeksforgeeks " NEW_LINE k = 4 NEW_LINE convert_str ( s , k ) NEW_LINE DEDENT


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

def power ( x , y ) : NEW_LINE INDENT res = 1 NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( ( y & 1 ) == 1 ) : NEW_LINE INDENT res = res * x NEW_LINE DEDENT y = y >> 1 NEW_LINE x = x * x NEW_LINE DEDENT return res NEW_LINE DEDENT x = 3 NEW_LINE y = 5 NEW_LINE print ( " Power ▁ is ▁ " , power ( x , y ) ) NEW_LINE


class GFG { static class Node { int data ; Node children [ ] ; Node ( int n , int data ) { children = new Node [ n ] ; this . data = data ; } } static void inorder ( Node node ) { if ( node == null ) return ; int total = node . children . length ; for ( int i = 0 ; i < total - 1 ; i ++ ) inorder ( node . children [ i ] ) ; System . out . print ( " " + node . data + " ▁ " ) ; inorder ( node . children [ total - 1 ] ) ; } public static void main ( String [ ] args ) { int n = 3 ; Node root = new Node ( n , 1 ) ; root . children [ 0 ] = new Node ( n , 2 ) ; root . children [ 1 ] = new Node ( n , 3 ) ; root . children [ 2 ] = new Node ( n , 4 ) ; root . children [ 0 ] . children [ 0 ] = new Node ( n , 5 ) ; root . children [ 0 ] . children [ 1 ] = new Node ( n , 6 ) ; root . children [ 0 ] . children [ 2 ] = new Node ( n , 7 ) ; inorder ( root ) ; } }

class GFG : NEW_LINE INDENT class Node : NEW_LINE INDENT def __init__ ( self , n , data ) : NEW_LINE INDENT self . children = [ None ] * n NEW_LINE self . data = data NEW_LINE DEDENT DEDENT def inorder ( self , node ) : NEW_LINE INDENT if node == None : NEW_LINE INDENT return NEW_LINE DEDENT total = len ( node . children ) NEW_LINE for i in range ( total - 1 ) : NEW_LINE INDENT self . inorder ( node . children [ i ] ) NEW_LINE DEDENT print ( node . data , end = " ▁ " ) NEW_LINE self . inorder ( node . children [ total - 1 ] ) NEW_LINE DEDENT def main ( self ) : NEW_LINE INDENT n = 3 NEW_LINE root = self . Node ( n , 1 ) NEW_LINE root . children [ 0 ] = self . Node ( n , 2 ) NEW_LINE root . children [ 1 ] = self . Node ( n , 3 ) NEW_LINE root . children [ 2 ] = self . Node ( n , 4 ) NEW_LINE root . children [ 0 ] . children [ 0 ] = self . Node ( n , 5 ) NEW_LINE root . children [ 0 ] . children [ 1 ] = self . Node ( n , 6 ) NEW_LINE root . children [ 0 ] . children [ 2 ] = self . Node ( n , 7 ) NEW_LINE self . inorder ( root ) NEW_LINE DEDENT DEDENT ob = GFG ( ) NEW_LINE ob . main ( ) NEW_LINE