class GFG { static int waysToArrange ( int N , int K , int [ ] k ) { int [ ] [ ] C = new int [ N + 1 ] [ N + 1 ] ; int i , j ; for ( i = 0 ; i <= N ; i ++ ) { for ( j = 0 ; j <= i ; j ++ ) { if ( j == 0 || j == i ) { C [ i ] [ j ] = 1 ; } else { C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) ; } } } int [ ] dp = new int [ K + 1 ] ; int count = 0 ; dp [ 0 ] = 1 ; for ( i = 0 ; i < K ; i ++ ) { dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) ; count += k [ i ] ; } return dp [ K ] ; } public static void main ( String [ ] args ) { int N = 4 ; int [ ] k = new int [ ] { 2 , 2 } ; int K = k . length ; System . out . println ( waysToArrange ( N , K , k ) ) ; } }

import numpy as np NEW_LINE def waysToArrange ( N , K , k ) : NEW_LINE INDENT C = np . zeros ( ( N + 1 , N + 1 ) ) NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT for j in range ( i + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT dp = np . zeros ( ( K + 1 ) ) NEW_LINE count = 0 NEW_LINE dp [ 0 ] = 1 NEW_LINE for i in range ( K ) : NEW_LINE INDENT dp [ i + 1 ] = ( dp [ i ] * C [ count + k [ i ] - 1 ] [ k [ i ] - 1 ] ) NEW_LINE count += k [ i ] NEW_LINE DEDENT return dp [ K ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 NEW_LINE k = [ 2 , 2 ] NEW_LINE K = len ( k ) NEW_LINE print ( int ( waysToArrange ( N , K , k ) ) ) NEW_LINE DEDENT


import java . util . * ; class solution { static int INF = 99999 ; static int size = 10 ; static int getSetBitsFromOneToN ( int N ) { int two = 2 , ans = 0 ; int n = N ; while ( n != 0 ) { ans += ( N / two ) * ( two >> 1 ) ; if ( ( N & ( two - 1 ) ) > ( two >> 1 ) - 1 ) ans += ( N & ( two - 1 ) ) - ( two >> 1 ) + 1 ; two <<= 1 ; n >>= 1 ; } return ans ; } static int findMinimum ( int x ) { int low = 0 , high = 100000 ; int ans = high ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( getSetBitsFromOneToN ( mid ) >= x ) { ans = Math . min ( ans , mid ) ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } public static void main ( String args [ ] ) { int x = 20 ; System . out . println ( findMinimum ( x ) ) ; } }

INF = 99999 NEW_LINE size = 10 NEW_LINE def getSetBitsFromOneToN ( N ) : NEW_LINE INDENT two , ans = 2 , 0 NEW_LINE n = N NEW_LINE while ( n > 0 ) : NEW_LINE INDENT ans += ( N // two ) * ( two >> 1 ) NEW_LINE if ( ( N & ( two - 1 ) ) > ( two >> 1 ) - 1 ) : NEW_LINE INDENT ans += ( N & ( two - 1 ) ) - ( two >> 1 ) + 1 NEW_LINE DEDENT two <<= 1 NEW_LINE n >>= 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT def findMinimum ( x ) : NEW_LINE INDENT low = 0 NEW_LINE high = 100000 NEW_LINE ans = high NEW_LINE while ( low <= high ) : NEW_LINE INDENT mid = ( low + high ) >> 1 NEW_LINE if ( getSetBitsFromOneToN ( mid ) >= x ) : NEW_LINE INDENT ans = min ( ans , mid ) NEW_LINE high = mid - 1 NEW_LINE DEDENT else : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT x = 20 NEW_LINE print ( findMinimum ( x ) ) NEW_LINE


import java . util . * ; class GFG { static int subgrids ( int N , int Z , int row [ ] , int col [ ] , int r , int d ) { Vector < Integer > conrow = new Vector < Integer > ( ) ; Vector < Integer > concol = new Vector < Integer > ( ) ; int K = ( int ) Math . sqrt ( Z ) ; conrow . add ( row [ 0 ] - 0 - 1 ) ; conrow . add ( N + 1 - row [ r - 1 ] - 1 ) ; for ( int i = 1 ; i < r ; i ++ ) { conrow . add ( row [ i ] - row [ i - 1 ] - 1 ) ; } concol . add ( col [ 0 ] - 0 - 1 ) ; concol . add ( N + 1 - col [ d - 1 ] - 1 ) ; for ( int i = 1 ; i < d ; i ++ ) { concol . add ( col [ i ] - col [ i - 1 ] - 1 ) ; } int row_size = conrow . size ( ) ; int col_size = concol . size ( ) ; int answer = 0 ; for ( int i = 0 ; i < row_size ; i ++ ) { for ( int j = 0 ; j < col_size ; j ++ ) { int total = ( concol . get ( j ) / K ) * ( conrow . get ( i ) / K ) ; answer += ( total ) ; } } return answer ; } public static void main ( String [ ] args ) { int N = 8 , Z = 4 ; int row [ ] = { 4 , 6 } ; int col [ ] = { 3 , 8 } ; int r = row . length ; int d = col . length ; System . out . print ( subgrids ( N , Z , row , col , r , d ) ) ; } }

from math import sqrt NEW_LINE def subgrids ( N , Z , row , col , r , d ) : NEW_LINE INDENT conrow = [ ] ; NEW_LINE concol = [ ] ; NEW_LINE K = int ( sqrt ( Z ) ) ; NEW_LINE conrow . append ( row [ 0 ] - 0 - 1 ) NEW_LINE conrow . append ( N + 1 - row [ r - 1 ] - 1 ) NEW_LINE for i in range ( 1 , r ) : NEW_LINE INDENT conrow . append ( row [ i ] - row [ i - 1 ] - 1 ) ; NEW_LINE DEDENT concol . append ( col [ 0 ] - 0 - 1 ) NEW_LINE concol . append ( N + 1 - col [ d - 1 ] - 1 ) NEW_LINE for i in range ( 1 , d ) : NEW_LINE INDENT concol . append ( col [ i ] - col [ i - 1 ] - 1 ) ; NEW_LINE DEDENT row_size = len ( conrow ) NEW_LINE col_size = len ( concol ) NEW_LINE answer = 0 NEW_LINE for i in range ( row_size ) : NEW_LINE INDENT for j in range ( col_size ) : NEW_LINE INDENT total = ( concol [ j ] // K ) *   \ NEW_LINE INDENT ( conrow [ i ] // K ) NEW_LINE DEDENT answer += ( total ) NEW_LINE DEDENT DEDENT return answer NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 8 ; Z = 4 NEW_LINE row = [ 4 , 6 ] NEW_LINE col = [ 3 , 8 ] NEW_LINE r = len ( row ) NEW_LINE d = len ( col ) NEW_LINE print ( subgrids ( N , Z , row , col , r , d ) ) NEW_LINE DEDENT


import java . util . HashMap ; import java . util . Map ; class GfG { static void solve ( int arr [ ] , int n , int k ) { HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! m . containsKey ( arr [ i ] ) ) m . put ( arr [ i ] , 0 ) ; m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } int max = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . get ( arr [ i ] ) == k && max == Integer . MIN_VALUE ) { max = arr [ i ] ; } else if ( m . get ( arr [ i ] ) == k && max < arr [ i ] ) { max = arr [ i ] ; } } if ( max == Integer . MIN_VALUE ) System . out . println ( " No ▁ such ▁ element " ) ; else System . out . println ( max ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 } ; int k = 4 ; int n = arr . length ; solve ( arr , n , k ) ; } }

import sys NEW_LINE def solve ( arr , n , k ) : NEW_LINE INDENT m = { } ; NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if ( arr [ i ] in m . keys ( ) ) : NEW_LINE INDENT m [ arr [ i ] ] += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT m [ arr [ i ] ] = 1 ; NEW_LINE DEDENT i += 1 ; NEW_LINE DEDENT max = sys . maxsize ; NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if ( m [ arr [ i ] ] == k and max == sys . maxsize ) : NEW_LINE INDENT max = arr [ i ] ; NEW_LINE DEDENT elif ( m [ arr [ i ] ] == k and max < arr [ i ] ) : NEW_LINE INDENT max = arr [ i ] ; NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if ( max == sys . maxsize ) : NEW_LINE INDENT print ( " No ▁ such ▁ element " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( max ) ; NEW_LINE DEDENT DEDENT arr = [ 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 ] NEW_LINE k = 4 ; NEW_LINE n = len ( arr ) NEW_LINE solve ( arr , n , k ) NEW_LINE


import java . util . * ; class GFG { static int MAX = 1000001 ; static int factor [ ] ; static void generatePrimeFactors ( ) { factor [ 1 ] = 1 ; for ( int i = 2 ; i < MAX ; i ++ ) factor [ i ] = i ; for ( int i = 4 ; i < MAX ; i += 2 ) factor [ i ] = 2 ; for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( factor [ i ] == i ) { for ( int j = i * i ; j < MAX ; j += i ) { if ( factor [ j ] == j ) factor [ j ] = i ; } } } } static int calculateNoOFactors ( int n ) { if ( n == 1 ) return 1 ; int ans = 1 ; int dup = factor [ n ] ; int c = 1 ; int j = n / factor [ n ] ; while ( j != 1 ) { if ( factor [ j ] == dup ) c += 1 ; else { dup = factor [ j ] ; ans = ans * ( c + 1 ) ; c = 1 ; } j = j / factor [ j ] ; } ans = ans * ( c + 1 ) ; return ans ; } public static void main ( String [ ] args ) { factor = new int [ MAX ] ; factor [ 0 ] = 0 ; generatePrimeFactors ( ) ; int a [ ] = { 10 , 30 , 100 , 450 , 987 } ; int q = a . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . print ( calculateNoOFactors ( a [ i ] ) + " ▁ " ) ; } }

MAX = 1000001 ; NEW_LINE factor = [ 0 ] * ( MAX + 1 ) ; NEW_LINE def generatePrimeFactors ( ) : NEW_LINE INDENT factor [ 1 ] = 1 ; NEW_LINE for i in range ( 2 , MAX ) : NEW_LINE INDENT factor [ i ] = i ; NEW_LINE DEDENT for i in range ( 4 , MAX , 2 ) : NEW_LINE INDENT factor [ i ] = 2 ; NEW_LINE DEDENT i = 3 ; NEW_LINE while ( i * i < MAX ) : NEW_LINE INDENT if ( factor [ i ] == i ) : NEW_LINE INDENT j = i * i ; NEW_LINE while ( j < MAX ) : NEW_LINE INDENT if ( factor [ j ] == j ) : NEW_LINE INDENT factor [ j ] = i ; NEW_LINE DEDENT j += i ; NEW_LINE DEDENT DEDENT i += 1 ; NEW_LINE DEDENT DEDENT def calculateNoOFactors ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT ans = 1 ; NEW_LINE dup = factor [ n ] ; NEW_LINE c = 1 ; NEW_LINE j = int ( n / factor [ n ] ) ; NEW_LINE while ( j > 1 ) : NEW_LINE INDENT if ( factor [ j ] == dup ) : NEW_LINE INDENT c += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT dup = factor [ j ] ; NEW_LINE ans = ans * ( c + 1 ) ; NEW_LINE c = 1 ; NEW_LINE DEDENT j = int ( j / factor [ j ] ) ; NEW_LINE DEDENT ans = ans * ( c + 1 ) ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT generatePrimeFactors ( ) NEW_LINE a = [ 10 , 30 , 100 , 450 , 987 ] NEW_LINE q = len ( a ) NEW_LINE for i in range ( 0 , q ) : NEW_LINE INDENT print ( calculateNoOFactors ( a [ i ] ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT


class GFG { static void rearrange ( int arr [ ] , int n ) { int temp ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( i % 2 == 0 && arr [ i ] > arr [ i + 1 ] ) { temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } if ( i % 2 != 0 && arr [ i ] < arr [ i + 1 ] ) { temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } } } static void printArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 4 , 2 , 1 , 8 , 3 } ; int n = arr . length ; System . out . print ( " Before ▁ rearranging : ▁ \n " ) ; printArray ( arr , n ) ; rearrange ( arr , n ) ; System . out . print ( " After ▁ rearranging : ▁ \n " ) ; printArray ( arr , n ) ; } }

def rearrange ( arr , n ) : NEW_LINE INDENT for i in range ( n - 1 ) : NEW_LINE INDENT if ( i % 2 == 0 and arr [ i ] > arr [ i + 1 ] ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE arr [ i ] = arr [ i + 1 ] NEW_LINE arr [ i + 1 ] = temp NEW_LINE DEDENT if ( i % 2 != 0 and arr [ i ] < arr [ i + 1 ] ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE arr [ i ] = arr [ i + 1 ] NEW_LINE arr [ i + 1 ] = temp NEW_LINE DEDENT DEDENT DEDENT def printArray ( arr , size ) : NEW_LINE INDENT for i in range ( size ) : NEW_LINE INDENT print ( arr [ i ] , " ▁ " , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT arr = [ 6 , 4 , 2 , 1 , 8 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Before ▁ rearranging : ▁ " ) NEW_LINE printArray ( arr , n ) NEW_LINE rearrange ( arr , n ) NEW_LINE print ( " After ▁ rearranging : " ) NEW_LINE printArray ( arr , n ) ; NEW_LINE


import java . io . * ; class GFG { static void possibleTripletInRange ( int L , int R ) { boolean flag = false ; int possibleA = 0 , possibleB = 0 , possibleC = 0 ; int numbersInRange = ( R - L + 1 ) ; if ( numbersInRange < 3 ) { flag = false ; } else if ( numbersInRange > 3 ) { flag = true ; if ( L % 2 > 0 ) { L ++ ; } possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { if ( ! ( L % 2 > 0 ) ) { flag = true ; possibleA = L ; possibleB = L + 1 ; possibleC = L + 2 ; } else { flag = false ; } } if ( flag == true ) { System . out . println ( " ( " + possibleA + " , ▁ " + possibleB + " , ▁ " + possibleC + " ) " + " ▁ is ▁ one ▁ such ▁ possible " + " ▁ triplet ▁ between ▁ " + L + " ▁ and ▁ " + R ) ; } else { System . out . println ( " No ▁ Such ▁ Triplet " + " ▁ exists ▁ between ▁ " + L + " ▁ and ▁ " + R ) ; } } public static void main ( String [ ] args ) { int L , R ; L = 2 ; R = 10 ; possibleTripletInRange ( L , R ) ; L = 23 ; R = 46 ; possibleTripletInRange ( L , R ) ; } }

def possibleTripletInRange ( L , R ) : NEW_LINE INDENT flag = False ; NEW_LINE possibleA = 0 ; NEW_LINE possibleB = 0 ; NEW_LINE possibleC = 0 ; NEW_LINE numbersInRange = ( R - L + 1 ) ; NEW_LINE if ( numbersInRange < 3 ) : NEW_LINE INDENT flag = False ; NEW_LINE DEDENT elif ( numbersInRange > 3 ) : NEW_LINE INDENT flag = True ; NEW_LINE if ( ( L % 2 ) > 0 ) : NEW_LINE INDENT L += 1 ; NEW_LINE DEDENT possibleA = L ; NEW_LINE possibleB = L + 1 ; NEW_LINE possibleC = L + 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( ( L % 2 ) == 0 ) : NEW_LINE INDENT flag = True ; NEW_LINE possibleA = L ; NEW_LINE possibleB = L + 1 ; NEW_LINE possibleC = L + 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT flag = False ; NEW_LINE DEDENT DEDENT if ( flag == True ) : NEW_LINE INDENT print ( " ( " , possibleA , " , " , possibleB , " , " , possibleC , " ) ▁ is ▁ one ▁ such " , " possible ▁ triplet ▁ between " , L , " and " , R ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No ▁ Such ▁ Triplet ▁ exists ▁ between " , L , " and " , R ) ; NEW_LINE DEDENT DEDENT L = 2 ; NEW_LINE R = 10 ; NEW_LINE possibleTripletInRange ( L , R ) ; NEW_LINE L = 23 ; NEW_LINE R = 46 ; NEW_LINE possibleTripletInRange ( L , R ) ; NEW_LINE


import java . util . * ; class solution { static void circle_equation ( double x1 , double y1 , double r ) { double a = - 2 * x1 ; double b = - 2 * y1 ; double c = ( r * r ) - ( x1 * x1 ) - ( y1 * y1 ) ; System . out . print ( " x ^ 2 ▁ + ▁ ( " + a + " ▁ x ) ▁ + ▁ " ) ; System . out . print ( " y ^ 2 ▁ + ▁ ( " + b + " ▁ y ) ▁ = ▁ " ) ; System . out . println ( c + " . " ) ; } public static void main ( String arr [ ] ) { double x1 = 2 , y1 = - 3 , r = 8 ; circle_equation ( x1 , y1 , r ) ; } }

def circle_equation ( x1 , y1 , r ) : NEW_LINE INDENT a = - 2 * x1 ; NEW_LINE b = - 2 * y1 ; NEW_LINE c = ( r * r ) - ( x1 * x1 ) - ( y1 * y1 ) ; NEW_LINE print ( " x ^ 2 ▁ + ▁ ( " , a , " x ) ▁ + ▁ " , end = " " ) ; NEW_LINE print ( " y ^ 2 ▁ + ▁ ( " , b , " y ) ▁ = ▁ " , end = " " ) ; NEW_LINE print ( c , " . " ) ; NEW_LINE DEDENT x1 = 2 ; NEW_LINE y1 = - 3 ; NEW_LINE r = 8 ; NEW_LINE circle_equation ( x1 , y1 , r ) ; NEW_LINE


import java . io . * ; class GFG { static int frequency ( int a [ ] , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] == x ) count ++ ; return count ; } public static void main ( String [ ] args ) { int a [ ] = { 0 , 5 , 5 , 5 , 4 } ; int x = 5 ; int n = a . length ; System . out . println ( frequency ( a , n , x ) ) ; } }

def frequency ( a , x ) : NEW_LINE INDENT count = 0 NEW_LINE for i in a : NEW_LINE INDENT if i == x : count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT a = [ 0 , 5 , 5 , 5 , 4 ] NEW_LINE x = 5 NEW_LINE print ( frequency ( a , x ) ) NEW_LINE


import java . util . * ; class GFG { static long MOD = ( long ) ( 1e9 + 7 ) ; static long powerLL ( long x , long n ) { long result = 1 ; while ( n > 0 ) { if ( n % 2 == 1 ) { result = result * x % MOD ; } n = n / 2 ; x = x * x % MOD ; } return result ; } static long powerStrings ( String sa , String sb ) { long a = 0 , b = 0 ; for ( int i = 0 ; i < sa . length ( ) ; i ++ ) { a = ( a * 10 + ( sa . charAt ( i ) - '0' ) ) % MOD ; } for ( int i = 0 ; i < sb . length ( ) ; i ++ ) { b = ( b * 10 + ( sb . charAt ( i ) - '0' ) ) % ( MOD - 1 ) ; } return powerLL ( a , b ) ; } public static void main ( String [ ] args ) { String sa = "2" , sb = "3" ; System . out . println ( powerStrings ( sa , sb ) ) ; } }

MOD = 1000000007 ; NEW_LINE def powerLL ( x , n ) : NEW_LINE INDENT result = 1 ; NEW_LINE while ( n ) : NEW_LINE INDENT if ( n & 1 ) : NEW_LINE INDENT result = result * x % MOD ; NEW_LINE DEDENT n = int ( n / 2 ) ; NEW_LINE x = x * x % MOD ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT def powerStrings ( sa , sb ) : NEW_LINE INDENT a = 0 ; NEW_LINE b = 0 ; NEW_LINE for i in range ( len ( sa ) ) : NEW_LINE INDENT a = ( a * 10 + ( ord ( sa [ i ] ) - ord ( '0' ) ) ) % MOD ; NEW_LINE DEDENT for i in range ( len ( sb ) ) : NEW_LINE INDENT b = ( b * 10 + ( ord ( sb [ i ] ) - ord ( '0' ) ) ) % ( MOD - 1 ) ; NEW_LINE DEDENT return powerLL ( a , b ) ; NEW_LINE DEDENT sa = "2" ; NEW_LINE sb = "3" ; NEW_LINE print ( powerStrings ( sa , sb ) ) ; NEW_LINE


class PrimeAndFib { Boolean isSquare ( int n ) { int sr = ( int ) Math . sqrt ( n ) ; return ( sr * sr == n ) ; } static void printPrimeAndFib ( int n ) { Boolean [ ] prime = new Boolean [ n + 1 ] ; for ( int p = 0 ; p <= n ; p ++ ) prime [ p ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int i = 2 ; i <= n ; i ++ ) { double sqrt = Math . sqrt ( 5 * i * i + 4 ) ; double sqrt1 = Math . sqrt ( 5 * i * i - 4 ) ; int x = ( int ) sqrt ; int y = ( int ) sqrt1 ; if ( prime [ i ] == true && ( Math . pow ( sqrt , 2 ) == Math . pow ( x , 2 ) || Math . pow ( sqrt1 , 2 ) == Math . pow ( y , 2 ) ) ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String s [ ] ) { int n = 30 ; printPrimeAndFib ( n ) ; } }

import math NEW_LINE def isSquare ( n ) : NEW_LINE INDENT sr = ( int ) ( math . sqrt ( n ) ) NEW_LINE return ( sr * sr == n ) NEW_LINE DEDENT def printPrimeAndFib ( n ) : NEW_LINE INDENT prime = [ True ] * ( n + 1 ) NEW_LINE p = 2 NEW_LINE while ( p * p <= n ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT for i in range ( p * 2 , n + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT p = p + 1 NEW_LINE DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( prime [ i ] and ( isSquare ( 5 * i * i + 4 ) > 0 or isSquare ( 5 * i * i - 4 ) > 0 ) ) : NEW_LINE INDENT print ( i , " ▁ " , end = " " ) NEW_LINE DEDENT DEDENT DEDENT n = 30 NEW_LINE printPrimeAndFib ( n ) ; NEW_LINE


class Sol { static class Node { int data ; Node left , right ; } ; static boolean isBST ( Node root , Node l , Node r ) { if ( root == null ) return true ; if ( l != null && root . data <= l . data ) return false ; if ( r != null && root . data >= r . data ) return false ; return isBST ( root . left , l , root ) && isBST ( root . right , root , r ) ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } public static void main ( String args [ ] ) { Node root = newNode ( 3 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 4 ) ; if ( isBST ( root , null , null ) ) System . out . print ( " Is ▁ BST " ) ; else System . out . print ( " Not ▁ a ▁ BST " ) ; } }

class newNode : NEW_LINE INDENT def __init__ ( self , key ) : NEW_LINE INDENT self . data = key NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def isBST ( root , l = None , r = None ) : NEW_LINE INDENT if ( root == None ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( l != None and root . data <= l . data ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( r != None and root . data >= r . data ) : NEW_LINE INDENT return False NEW_LINE DEDENT return isBST ( root . left , l , root ) and   \ NEW_LINE INDENT isBST ( root . right , root , r ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = newNode ( 3 ) NEW_LINE root . left = newNode ( 2 ) NEW_LINE root . right = newNode ( 5 ) NEW_LINE root . right . left = newNode ( 1 ) NEW_LINE root . right . right = newNode ( 4 ) NEW_LINE if ( isBST ( root , None , None ) ) : NEW_LINE INDENT print ( " Is ▁ BST " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ a ▁ BST " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int squareSum ( int n ) { return 2 * n * ( n + 1 ) * ( 2 * n + 1 ) / 3 ; } public static void main ( String args [ ] ) throws IOException { System . out . println ( squareSum ( 8 ) ) ; } }

def squareSum ( n ) : NEW_LINE INDENT return int ( 2 * n * ( n + 1 ) * ( 2 * n + 1 ) / 3 ) NEW_LINE DEDENT ans = squareSum ( 8 ) NEW_LINE print ( ans ) NEW_LINE


import java . io . * ; class GFG { static int minSum ( int arr [ ] , int n ) { int sum = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { int j = i ; while ( j < n && arr [ j ] <= arr [ j - 1 ] ) { arr [ j ] = arr [ j ] + 1 ; j ++ ; } } sum = sum + arr [ i ] ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 5 , 6 } ; int n = arr . length ; System . out . println ( minSum ( arr , n ) ) ; } }

def minSum ( arr , n ) : NEW_LINE INDENT sm = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if arr [ i ] == arr [ i - 1 ] : NEW_LINE INDENT j = i NEW_LINE while j < n and arr [ j ] <= arr [ j - 1 ] : NEW_LINE INDENT arr [ j ] = arr [ j ] + 1 NEW_LINE j += 1 NEW_LINE DEDENT DEDENT sm = sm + arr [ i ] NEW_LINE DEDENT return sm NEW_LINE DEDENT arr = [ 2 , 2 , 3 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minSum ( arr , n ) ) NEW_LINE


import java . io . * ; class GFG { static int countPairs ( int N ) { int count = 0 ; for ( int i = 1 ; i <= ( int ) Math . sqrt ( N ) ; i ++ ) { int sq = i * i ; int diff = N - sq ; int sqrtDiff = ( int ) Math . sqrt ( diff ) ; if ( sqrtDiff * sqrtDiff == diff ) count ++ ; } return count ; } public static void main ( String [ ] args ) { for ( int i = 1 ; i <= 10 ; i ++ ) System . out . println ( " For ▁ n ▁ = ▁ " + i + " , ▁ " + countPairs ( i ) + " ▁ pair ▁ exists \n " ) ; } }

from math import * NEW_LINE def countPairs ( N ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 1 , int ( sqrt ( N ) ) + 1 ) : NEW_LINE INDENT sq = i * i NEW_LINE diff = N - sq NEW_LINE sqrtDiff = int ( sqrt ( diff ) ) NEW_LINE if sqrtDiff * sqrtDiff == diff : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT for i in range ( 1 , 11 ) : NEW_LINE INDENT print ( " For ▁ n ▁ = " , i , " , ▁ " , countPairs ( i ) , " pair ▁ exists " ) NEW_LINE DEDENT DEDENT


class GFG { static void solve ( int A , int B ) { double p = B / 2.0 ; double M = Math . ceil ( 4 * p ) ; int N = 1 ; int O = - 2 * A ; double Q = Math . ceil ( A * A + 4 * p * p ) ; System . out . println ( M + " ▁ " + N + " ▁ " + O + " ▁ " + Q ) ; } public static void main ( String [ ] args ) { int a = 1 ; int b = 1 ; solve ( a , b ) ; } }

def solve ( A , B ) : NEW_LINE INDENT p = B / 2 NEW_LINE M = int ( 4 * p ) NEW_LINE N = 1 NEW_LINE O = - 2 * A NEW_LINE Q = int ( A * A + 4 * p * p ) NEW_LINE return [ M , N , O , Q ] NEW_LINE DEDENT a = 1 NEW_LINE b = 1 NEW_LINE print ( * solve ( a , b ) ) NEW_LINE


import java . io . * ; class GFG { static void newvol ( double x ) { System . out . print ( " percentage ▁ increase ▁ in ▁ the " + " ▁ volume ▁ of ▁ the ▁ sphere ▁ is ▁ " + ( Math . pow ( x , 3 ) / 10000 + 3 * x + ( 3 * Math . pow ( x , 2 ) ) / 100 ) + " % " ) ; } public static void main ( String [ ] args ) { double x = 10 ; newvol ( x ) ; } }

def newvol ( x ) : NEW_LINE INDENT print ( " percentage ▁ increase ▁ in ▁ the " , pow ( x , 3 ) / 10000 + 3 * x + ( 3 * pow ( x , 2 ) ) / 100 , " % " ) DEDENT x = 10.0 NEW_LINE newvol ( x ) NEW_LINE


class GFG { static int N = 3 ; static int MaxTraceSub ( int mat [ ] [ ] ) { int max_trace = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int r = i , s = j , trace = 0 ; while ( r < N && s < N ) { trace += mat [ r ] [ s ] ; r ++ ; s ++ ; max_trace = Math . max ( trace , max_trace ) ; } } } return max_trace ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 10 , 2 , 5 } , { 6 , 10 , 4 } , { 2 , 7 , - 10 } } ; System . out . println ( MaxTraceSub ( mat ) ) ; } }

N = 3 NEW_LINE def MaxTraceSub ( mat ) : NEW_LINE INDENT max_trace = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT r = i NEW_LINE s = j NEW_LINE trace = 0 NEW_LINE while ( r < N and s < N ) : NEW_LINE INDENT trace += mat [ r ] NEW_LINE r += 1 NEW_LINE s += 1 NEW_LINE max_trace = max ( trace , max_trace ) NEW_LINE DEDENT DEDENT DEDENT return max_trace NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT mat = [ [ 10 , 2 , 5 ] , [ 6 , 10 , 4 ] , [ 2 , 7 , - 10 ] ] NEW_LINE print ( MaxTraceSub ( mat ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static Map < String , Integer > dp = new HashMap < > ( ) ; static Integer solve ( char [ ] s , char c ) { if ( s . length == 1 ) return 0 ; if ( s . length == 2 ) { if ( s [ 0 ] == s [ 1 ] && s [ 0 ] == c ) return 1 ; else return 0 ; } if ( dp . containsKey ( String . valueOf ( s ) + " ▁ " + c ) ) return dp . get ( String . valueOf ( s ) + " ▁ " + c ) ; Integer ans = 0 ; if ( s [ 0 ] == s [ s . length - 1 ] && s [ 0 ] == c ) { for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) if ( c1 != c ) ans = Math . max ( ans , 1 + solve ( Arrays . copyOfRange ( s , 1 , s . length - 1 ) , c1 ) ) ; } else { for ( Integer i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == c ) { for ( Integer j = s . length - 1 ; j > i ; j -- ) if ( s [ j ] == c ) { if ( j == i ) break ; ans = solve ( Arrays . copyOfRange ( s , i , j + 1 ) , c ) ; break ; } break ; } } } dp . put ( String . valueOf ( s ) + " ▁ " + c , ans ) ; return dp . get ( String . valueOf ( s ) + " ▁ " + c ) ; } public static void main ( String [ ] args ) { String s = " abscrcdba " ; Integer ma = 0 ; for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) ma = Math . max ( ma , solve ( s . toCharArray ( ) , c1 ) * 2 ) ; System . out . print ( ma + " \n " ) ; } }

dp = { } ; NEW_LINE def solve ( s , c ) : NEW_LINE INDENT if ( len ( s ) == 1 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( len ( s ) == 2 ) : NEW_LINE INDENT if ( s [ 0 ] == s [ 1 ] and s [ 0 ] == c ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT if ( s + " ▁ " + c ) in dp : NEW_LINE INDENT return dp [ s + " ▁ " + c ] ; NEW_LINE DEDENT ans = 0 ; NEW_LINE if ( s [ 0 ] == s [ len ( s ) - 1 ] and s [ 0 ] == c ) : NEW_LINE INDENT for c1 in range ( 97 , 123 ) : NEW_LINE INDENT if ( chr ( c1 ) != c ) : NEW_LINE INDENT ans = max ( ans , 1 + solve ( s [ 1 : len ( s ) - 1 ] , chr ( c1 ) ) ) ; NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] == c ) : NEW_LINE INDENT for j in range ( len ( s ) - 1 , i , - 1 ) : NEW_LINE INDENT if ( s [ j ] == c ) : NEW_LINE INDENT if ( j == i ) : NEW_LINE INDENT break ; NEW_LINE DEDENT ans = solve ( s [ i : j - i + 2 ] , c ) ; NEW_LINE break ; NEW_LINE DEDENT DEDENT break ; NEW_LINE DEDENT DEDENT DEDENT dp [ s + " ▁ " + c ] = ans ; NEW_LINE return dp [ s + " ▁ " + c ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " abscrcdba " ; NEW_LINE ma = 0 ; NEW_LINE for c1 in range ( 97 , 123 ) : NEW_LINE INDENT ma = max ( ma , solve ( s , chr ( c1 ) ) * 2 ) ; NEW_LINE DEDENT print ( ma ) ; NEW_LINE DEDENT


class Test { static int countDigit ( int n ) { int temp = n , count = 0 ; while ( temp != 0 ) { int d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 ) count ++ ; } return count ; } public static void main ( String args [ ] ) { int n = 1012 ; System . out . println ( countDigit ( n ) ) ; } }

def countDigit ( n ) : NEW_LINE INDENT temp = n NEW_LINE count = 0 NEW_LINE while temp != 0 : NEW_LINE INDENT d = temp % 10 NEW_LINE temp /= 10 NEW_LINE if d > 0 and n % d == 0 : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT n = 1012 NEW_LINE print ( countDigit ( n ) ) NEW_LINE


import java . util . * ; class GFG { static int getMod ( String str , int n , int k ) { int pwrTwo [ ] = new int [ n ] ; pwrTwo [ 0 ] = 1 % k ; for ( int i = 1 ; i < n ; i ++ ) { pwrTwo [ i ] = pwrTwo [ i - 1 ] * ( 2 % k ) ; pwrTwo [ i ] %= k ; } int res = 0 ; int i = 0 , j = n - 1 ; while ( i < n ) { if ( str . charAt ( j ) == '1' ) { res += ( pwrTwo [ i ] ) ; res %= k ; } i ++ ; j -- ; } return res ; } public static void main ( String [ ] args ) { String str = "1101" ; int n = str . length ( ) ; int k = 45 ; System . out . print ( getMod ( str , n , k ) ) ; } }

def getMod ( _str , n , k ) : NEW_LINE INDENT pwrTwo = [ 0 ] * n NEW_LINE pwrTwo [ 0 ] = 1 % k NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT pwrTwo [ i ] = pwrTwo [ i - 1 ] * ( 2 % k ) NEW_LINE pwrTwo [ i ] %= k NEW_LINE DEDENT res = 0 NEW_LINE i = 0 NEW_LINE j = n - 1 NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( _str [ j ] == '1' ) : NEW_LINE INDENT res += ( pwrTwo [ i ] ) NEW_LINE res %= k NEW_LINE DEDENT i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT return res NEW_LINE DEDENT _str = "1101" NEW_LINE n = len ( _str ) NEW_LINE k = 45 NEW_LINE print ( getMod ( _str , n , k ) ) NEW_LINE


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

def getChicks ( n ) : NEW_LINE INDENT chicks = pow ( 3 , n - 1 ) NEW_LINE return chicks NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 NEW_LINE print ( getChicks ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int solve ( int health [ ] , int n ) { int currentgcd = gcd ( health [ 0 ] , health [ 1 ] ) ; for ( int i = 2 ; i < n ; ++ i ) { currentgcd = gcd ( currentgcd , health [ i ] ) ; } return currentgcd ; } public static void main ( String args [ ] ) { int health [ ] = { 4 , 6 , 8 , 12 } ; int n = health . length ; System . out . println ( solve ( health , n ) ) ; } }

def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def solve ( health , n ) : NEW_LINE INDENT currentgcd = gcd ( health [ 0 ] , health [ 1 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT currentgcd = gcd ( currentgcd , health [ i ] ) NEW_LINE DEDENT return currentgcd NEW_LINE DEDENT health = [ 4 , 6 , 8 , 12 ] NEW_LINE n = len ( health ) NEW_LINE print ( solve ( health , n ) ) NEW_LINE


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

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


import java . util . Set ; import java . util . HashSet ; class GfG { static int countChanges ( int arr [ ] , int n ) { Set < Integer > s = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( ! s . contains ( i ) ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 55 , 22 , 1 , 3 , 22 , 4 , 5 } ; int n = arr . length ; System . out . println ( countChanges ( arr , n ) ) ; } }

def countChanges ( arr , n ) : NEW_LINE INDENT s = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT s . append ( arr [ i ] ) NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if i not in s : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 8 , 55 , 22 , 1 , 3 , 22 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countChanges ( arr , n ) ) NEW_LINE DEDENT


class GFG { static final int INT_MAX = Integer . MAX_VALUE ; static int findLength ( String s , int k ) { int ans = INT_MAX ; int l = 0 ; int r = 0 ; int cnt_zero = 0 , cnt_one = 0 ; while ( l < s . length ( ) && r <= s . length ( ) ) { if ( cnt_zero >= k && cnt_one >= 1 ) { ans = Math . min ( ans , r - l ) ; l ++ ; if ( s . charAt ( l - 1 ) == '0' ) cnt_zero -- ; else cnt_one -- ; } else { if ( r == s . length ( ) ) break ; if ( s . charAt ( r ) == '0' ) cnt_zero ++ ; else cnt_one ++ ; r ++ ; } } if ( ans == INT_MAX ) return - 1 ; return ans ; } public static void main ( String [ ] args ) { String s = "100" ; int k = 2 ; System . out . println ( findLength ( s , k ) ) ; } }

def findLength ( s , k ) : NEW_LINE INDENT ans = 10 ** 9 NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE cnt_zero = 0 NEW_LINE cnt_one = 0 NEW_LINE while ( l < len ( s ) and r <= len ( s ) ) : NEW_LINE INDENT if ( cnt_zero >= k and cnt_one >= 1 ) : NEW_LINE INDENT ans = min ( ans , r - l ) NEW_LINE l += 1 NEW_LINE if ( s [ l - 1 ] == '0' ) : NEW_LINE INDENT cnt_zero -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt_one -= 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( r == len ( s ) ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( s [ r ] == '0' ) : NEW_LINE INDENT cnt_zero += 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt_one += 1 NEW_LINE DEDENT r += 1 NEW_LINE DEDENT DEDENT if ( ans == 10 ** 9 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return ans NEW_LINE DEDENT s = "100" NEW_LINE k = 2 NEW_LINE print ( findLength ( s , k ) ) NEW_LINE


import java . io . * ; class GFG { static int sum_odd ( int n ) { int sum = 0 , pos = 1 ; while ( n > 0 ) { if ( pos % 2 == 1 ) sum += n % 10 ; n = n / 10 ; pos ++ ; } return sum ; } static boolean check_prime ( 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 ; } public static void main ( String [ ] args ) { int n = 223 ; int sum = sum_odd ( n ) ; if ( check_prime ( sum ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

def sum_odd ( n ) : NEW_LINE INDENT sums = 0 NEW_LINE pos = 1 NEW_LINE while ( n != 0 ) : NEW_LINE INDENT if ( pos % 2 == 1 ) : NEW_LINE INDENT sums += n % 10 NEW_LINE DEDENT n = n // 10 NEW_LINE pos += 1 NEW_LINE DEDENT return sums NEW_LINE DEDENT def check_prime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 5 , n , 6 ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT n = 223 NEW_LINE sums = sum_odd ( n ) NEW_LINE if ( check_prime ( sums ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int N = 100005 ; static boolean prime [ ] = new boolean [ N ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < N ; i ++ ) prime [ i ] = true ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < N ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i < N ; i += p ) prime [ i ] = false ; } } } static int almostPrimes ( int n ) { int ans = 0 ; for ( int i = 6 ; i <= n ; i ++ ) { int c = 0 ; for ( int j = 2 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( j * j == i ) { if ( prime [ j ] ) c ++ ; } else { if ( prime [ j ] ) c ++ ; if ( prime [ i / j ] ) c ++ ; } } } if ( c == 2 ) ans ++ ; } return ans ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int n = 21 ; System . out . println ( almostPrimes ( n ) ) ; } }

from math import * NEW_LINE N = 100005 NEW_LINE prime = [ True ] * N NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime [ 1 ] = False NEW_LINE for p in range ( 2 , int ( sqrt ( N ) ) ) : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT for i in range ( 2 * p , N , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def almostPrimes ( n ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 6 , n + 1 ) : NEW_LINE INDENT c = 0 NEW_LINE for j in range ( 2 , int ( sqrt ( i ) ) + 1 ) : NEW_LINE INDENT if i % j == 0 : NEW_LINE INDENT if j * j == i : NEW_LINE INDENT if prime [ j ] : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if prime [ j ] : NEW_LINE INDENT c += 1 NEW_LINE DEDENT if prime [ i // j ] : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT if c == 2 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE n = 21 NEW_LINE print ( almostPrimes ( n ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { public static void PrintNumber ( int N , int Original , int K , boolean flag ) { System . out . print ( N + " ▁ " ) ; if ( N <= 0 ) flag = ! flag ; if ( N == Original && ! flag ) return ; if ( flag == true ) { PrintNumber ( N - K , Original , K , flag ) ; return ; } if ( ! flag ) { PrintNumber ( N + K , Original , K , flag ) ; return ; } } public static void main ( String [ ] args ) { int N = 20 , K = 6 ; PrintNumber ( N , N , K , true ) ; } }

def PrintNumber ( N , Original , K , flag ) : NEW_LINE INDENT print ( N , end = " ▁ " ) NEW_LINE if ( N <= 0 ) : NEW_LINE INDENT if ( flag == 0 ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT else : NEW_LINE INDENT flag = 0 NEW_LINE DEDENT DEDENT if ( N == Original and ( not ( flag ) ) ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( flag == True ) : NEW_LINE INDENT PrintNumber ( N - K , Original , K , flag ) NEW_LINE return NEW_LINE DEDENT if ( not ( flag ) ) : NEW_LINE INDENT PrintNumber ( N + K , Original , K , flag ) ; NEW_LINE return NEW_LINE DEDENT DEDENT N = 20 NEW_LINE K = 6 NEW_LINE PrintNumber ( N , N , K , True ) NEW_LINE


class GfG { static int minOperations ( int n , int m ) { if ( m % n != 0 ) return - 1 ; int minOperations = 0 ; int q = m / n ; while ( q % 2 == 0 ) { q = q / 2 ; minOperations ++ ; } while ( q % 3 == 0 ) { q = q / 3 ; minOperations ++ ; } if ( q == 1 ) return minOperations ; return - 1 ; } public static void main ( String [ ] args ) { int n = 120 , m = 51840 ; System . out . println ( minOperations ( n , m ) ) ; } }

def minOperations ( n , m ) : NEW_LINE INDENT if ( m % n != 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT minOperations = 0 NEW_LINE q = int ( m / n ) NEW_LINE while ( q % 2 == 0 ) : NEW_LINE INDENT q = int ( q / 2 ) NEW_LINE minOperations += 1 NEW_LINE DEDENT while ( q % 3 == 0 ) : NEW_LINE INDENT q = int ( q / 3 ) NEW_LINE minOperations += 1 NEW_LINE DEDENT if ( q == 1 ) : NEW_LINE INDENT return minOperations NEW_LINE DEDENT return - 1 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 120 NEW_LINE m = 51840 NEW_LINE print ( minOperations ( n , m ) ) NEW_LINE DEDENT


class GFG { static int MAX = 26 ; static int maxLength ( String str , int len ) { int res = 0 ; int lastPos [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { lastPos [ i ] = - 1 ; } for ( int i = 0 ; i < len ; i ++ ) { int C = str . charAt ( i ) - ' a ' ; if ( lastPos [ C ] != - 1 ) { res = Math . max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ; } lastPos [ C ] = i ; } return res ; } public static void main ( String args [ ] ) { String str = " geeksforgeeks " ; int len = str . length ( ) ; System . out . println ( maxLength ( str , len ) ) ; } }

MAX = 26 ; NEW_LINE def maxLength ( str , len ) : NEW_LINE INDENT res = 0 ; NEW_LINE lastPos = [ 0 ] * MAX ; NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT lastPos [ i ] = - 1 ; NEW_LINE DEDENT for i in range ( len ) : NEW_LINE INDENT C = ord ( str [ i ] ) - ord ( ' a ' ) ; NEW_LINE if ( lastPos [ C ] != - 1 ) : NEW_LINE INDENT res = max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ; NEW_LINE DEDENT lastPos [ C ] = i ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " geeksforgeeks " ; NEW_LINE len = len ( str ) ; NEW_LINE print ( maxLength ( str , len ) ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int maxProduct ( int arr [ ] , int n ) { int minVal = arr [ 0 ] ; int maxVal = arr [ 0 ] ; int maxProduct = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < 0 ) { int temp = maxVal ; maxVal = minVal ; minVal = temp ; } maxVal = Math . max ( arr [ i ] , maxVal * arr [ i ] ) ; minVal = Math . min ( arr [ i ] , minVal * arr [ i ] ) ; maxProduct = Math . max ( maxProduct , maxVal ) ; } return maxProduct ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , - 3 , - 10 , 0 , 60 } ; int n = arr . length ; System . out . println ( " Maximum ▁ Subarray ▁ product ▁ is ▁ " + maxProduct ( arr , n ) ) ; } }

def maxProduct ( arr , n ) : NEW_LINE INDENT minVal = arr [ 0 ] NEW_LINE maxVal = arr [ 0 ] NEW_LINE maxProduct = arr [ 0 ] NEW_LINE for i in range ( 1 , n , 1 ) : NEW_LINE INDENT if ( arr [ i ] < 0 ) : NEW_LINE INDENT temp = maxVal NEW_LINE maxVal = minVal NEW_LINE minVal = temp NEW_LINE DEDENT maxVal = max ( arr [ i ] , maxVal * arr [ i ] ) NEW_LINE minVal = min ( arr [ i ] , minVal * arr [ i ] ) NEW_LINE maxProduct = max ( maxProduct , maxVal ) NEW_LINE DEDENT return maxProduct NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 1 , - 3 , - 10 , 0 , 60 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ Subarray ▁ product ▁ is " , maxProduct ( arr , n ) ) NEW_LINE DEDENT


import java . io . IOException ; public class Test { static String getMinNumberForPattern ( String seq ) { int n = seq . length ( ) ; if ( n >= 9 ) return " - 1" ; char result [ ] = new char [ n + 1 ] ; int count = 1 ; for ( int i = 0 ; i <= n ; i ++ ) { if ( i == n || seq . charAt ( i ) == ' I ' ) { for ( int j = i - 1 ; j >= - 1 ; j -- ) { result [ j + 1 ] = ( char ) ( ( int ) '0' + count ++ ) ; if ( j >= 0 && seq . charAt ( j ) == ' I ' ) break ; } } } return new String ( result ) ; } public static void main ( String [ ] args ) throws IOException { String inputs [ ] = { " IDID " , " I " , " DD " , " II " , " DIDI " , " IIDDD " , " DDIDDIID " } ; for ( String input : inputs ) { System . out . println ( getMinNumberForPattern ( input ) ) ; } } }

def getMinNumberForPattern ( seq ) : NEW_LINE INDENT n = len ( seq ) NEW_LINE if ( n >= 9 ) : NEW_LINE INDENT return " - 1" NEW_LINE DEDENT result = [ None ] * ( n + 1 ) NEW_LINE count = 1 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT if ( i == n or seq [ i ] == ' I ' ) : NEW_LINE INDENT for j in range ( i - 1 , - 2 , - 1 ) : NEW_LINE INDENT result [ j + 1 ] = int ( '0' + str ( count ) ) NEW_LINE count += 1 NEW_LINE if ( j >= 0 and seq [ j ] == ' I ' ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT inputs = [ " IDID " , " I " , " DD " , " II " , " DIDI " , " IIDDD " , " DDIDDIID " ] NEW_LINE for Input in inputs : NEW_LINE INDENT print ( * ( getMinNumberForPattern ( Input ) ) ) NEW_LINE DEDENT DEDENT


class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) { res = ( res * x ) % p ; } y = y >> 1 ; x = ( x * x ) % p ; } return res ; } public static void main ( String [ ] args ) { int L = 2 ; int P = ( int ) Math . pow ( 10 , 9 ) ; int ans = power ( 325 , L , P ) ; System . out . println ( ans ) ; } }

def power ( x , y , p ) : NEW_LINE INDENT res = 1 ; NEW_LINE x = x % p ; NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y % 2 == 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 L = 2 ; P = pow ( 10 , 9 ) ; NEW_LINE ans = power ( 325 , L , P ) ; NEW_LINE print ( ans ) ; NEW_LINE


class GFG { static class Date { int d , m , y ; public Date ( int d , int m , int y ) { this . d = d ; this . m = m ; this . y = y ; } } ; static int monthDays [ ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; static int countLeapYears ( Date d ) { int years = d . y ; if ( d . m <= 2 ) { years -- ; } return years / 4 - years / 100 + years / 400 ; } static int getDifference ( Date dt1 , Date dt2 ) { int n1 = dt1 . y * 365 + dt1 . d ; for ( int i = 0 ; i < dt1 . m - 1 ; i ++ ) { n1 += monthDays [ i ] ; } n1 += countLeapYears ( dt1 ) ; int n2 = dt2 . y * 365 + dt2 . d ; for ( int i = 0 ; i < dt2 . m - 1 ; i ++ ) { n2 += monthDays [ i ] ; } n2 += countLeapYears ( dt2 ) ; return ( n2 - n1 ) ; } public static void main ( String [ ] args ) { Date dt1 = new Date ( 1 , 2 , 2000 ) ; Date dt2 = new Date ( 1 , 2 , 2004 ) ; System . out . println ( " Difference ▁ between ▁ two ▁ dates ▁ is ▁ " + getDifference ( dt1 , dt2 ) ) ; } }

class Date : NEW_LINE INDENT def __init__ ( self , d , m , y ) : NEW_LINE INDENT self . d = d NEW_LINE self . m = m NEW_LINE self . y = y NEW_LINE DEDENT DEDENT monthDays = [ 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 ] NEW_LINE def countLeapYears ( d ) : NEW_LINE INDENT years = d . y NEW_LINE if ( d . m <= 2 ) : NEW_LINE INDENT years -= 1 NEW_LINE DEDENT return int ( years / 4 - years / 100 + years / 400 ) NEW_LINE DEDENT def getDifference ( dt1 , dt2 ) : NEW_LINE INDENT n1 = dt1 . y * 365 + dt1 . d NEW_LINE for i in range ( 0 , dt1 . m - 1 ) : NEW_LINE INDENT n1 += monthDays [ i ] NEW_LINE DEDENT n1 += countLeapYears ( dt1 ) NEW_LINE n2 = dt2 . y * 365 + dt2 . d NEW_LINE for i in range ( 0 , dt2 . m - 1 ) : NEW_LINE INDENT n2 += monthDays [ i ] NEW_LINE DEDENT n2 += countLeapYears ( dt2 ) NEW_LINE return ( n2 - n1 ) NEW_LINE DEDENT dt1 = Date ( 1 , 2 , 2000 ) NEW_LINE dt2 = Date ( 1 , 2 , 2004 ) NEW_LINE print ( " Difference ▁ between ▁ two ▁ dates ▁ is " , getDifference ( dt1 , dt2 ) ) NEW_LINE


import java . util . * ; class GFG { static void isPossible ( int [ ] A , int n , int k ) { int countOfTwo = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] % 2 == 0 ) { countOfTwo ++ ; } } if ( k == 0 && countOfTwo == n ) System . out . print ( " NO " ) ; else if ( countOfTwo >= k ) { System . out . print ( " YES " ) ; } else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 5 } ; int K = 2 ; int n = arr . length ; isPossible ( arr , n , K ) ; } }

def isPossible ( A , n , k ) : NEW_LINE INDENT countOfTwo = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( A [ i ] % 2 == 0 ) : NEW_LINE INDENT countOfTwo += 1 NEW_LINE DEDENT DEDENT if ( k == 0 and countOfTwo == n ) : NEW_LINE INDENT print ( " NO \n " ) NEW_LINE DEDENT elif ( countOfTwo >= k ) : NEW_LINE INDENT print ( " Yes \n " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No \n " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 4 , 5 ] NEW_LINE K = 2 NEW_LINE N = len ( arr ) NEW_LINE isPossible ( arr , N , K ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void maxSum ( int [ ] a , int n ) { Vector < Integer > l = new Vector < Integer > ( ) ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s += Math . abs ( a [ i ] ) ; if ( a [ i ] >= 0 ) continue ; if ( i == 0 ) l . add ( i + 1 ) ; else { l . add ( i + 1 ) ; l . add ( i ) ; } } System . out . println ( s ) ; for ( int i = 0 ; i < l . size ( ) ; i ++ ) System . out . print ( l . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 4 ; int a [ ] = { 1 , - 2 , - 3 , 4 } ; maxSum ( a , n ) ; } }

def maxSum ( arr , n ) : NEW_LINE INDENT s = 0 NEW_LINE l = [ ] NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT s += abs ( a [ i ] ) NEW_LINE if ( a [ i ] >= 0 ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( i == 0 ) : NEW_LINE INDENT l . append ( i + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT l . append ( i + 1 ) NEW_LINE l . append ( i ) NEW_LINE DEDENT DEDENT print ( s ) NEW_LINE print ( * l ) NEW_LINE DEDENT n = 4 NEW_LINE a = [ 1 , - 2 , - 3 , 4 ] NEW_LINE maxSum ( a , n ) NEW_LINE


class GFG { static boolean isPossible ( int n ) { int fac [ ] = new int [ 10 ] ; fac [ 0 ] = fac [ 1 ] = 1 ; for ( int i = 2 ; i < 10 ; i ++ ) fac [ i ] = fac [ i - 1 ] * i ; int sum = 0 ; int x = n ; while ( x != 0 ) { sum += fac [ x % 10 ] ; x /= 10 ; } if ( sum % n == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 19 ; if ( isPossible ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isPossible ( n ) : NEW_LINE INDENT fac = [ 0 for i in range ( 10 ) ] NEW_LINE fac [ 0 ] = 1 NEW_LINE fac [ 1 ] = 1 NEW_LINE for i in range ( 2 , 10 , 1 ) : NEW_LINE INDENT fac [ i ] = fac [ i - 1 ] * i NEW_LINE DEDENT sum = 0 NEW_LINE x = n NEW_LINE while ( x ) : NEW_LINE INDENT sum += fac [ x % 10 ] NEW_LINE x = int ( x / 10 ) NEW_LINE DEDENT if ( sum % n == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 19 NEW_LINE if ( isPossible ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int minSum ( int arr [ ] , int n ) { int sum = arr [ 0 ] , prev = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= prev ) { prev = prev + 1 ; sum = sum + prev ; } else { sum = sum + arr [ i ] ; prev = arr [ i ] ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 5 , 6 } ; int n = arr . length ; System . out . println ( minSum ( arr , n ) ) ; } }

def minSum ( arr , n ) : NEW_LINE INDENT sum = arr [ 0 ] ; prev = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if arr [ i ] <= prev : NEW_LINE INDENT prev = prev + 1 NEW_LINE sum = sum + prev NEW_LINE DEDENT else : NEW_LINE INDENT sum = sum + arr [ i ] NEW_LINE prev = arr [ i ] NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT arr = [ 2 , 2 , 3 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minSum ( arr , n ) ) NEW_LINE


import java . util . * ; class GFG { static int sticks [ ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; static int countSticks ( String str , int n ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { cnt += ( sticks [ str . charAt ( i ) - '0' ] ) ; } return cnt ; } public static void main ( String [ ] args ) { String str = "56" ; int n = str . length ( ) ; System . out . println ( countSticks ( str , n ) ) ; } }

sticks = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ] ; NEW_LINE def countSticks ( string , n ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT cnt += ( sticks [ ord ( string [ i ] ) - ord ( '0' ) ] ) ; NEW_LINE DEDENT return cnt ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = "56" ; NEW_LINE n = len ( string ) ; NEW_LINE print ( countSticks ( string , n ) ) ; NEW_LINE DEDENT


import java . util . Arrays ; class GFG { static int largestGCDSubsequence ( int arr [ ] , int n ) { int ans = 0 ; int maxele = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; ; for ( int i = 2 ; i <= maxele ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( arr [ j ] % i == 0 ) ++ count ; } ans = Math . max ( ans , count ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 2 , 5 , 4 } ; int size = arr . length ; System . out . println ( largestGCDSubsequence ( arr , size ) ) ; } }

def largestGCDSubsequence ( arr , n ) : NEW_LINE INDENT ans = 0 NEW_LINE maxele = max ( arr ) NEW_LINE for i in range ( 2 , maxele + 1 ) : NEW_LINE INDENT count = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( arr [ j ] % i == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT ans = max ( ans , count ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 6 , 2 , 5 , 4 ] NEW_LINE size = len ( arr ) NEW_LINE print ( largestGCDSubsequence ( arr , size ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int xorPairCount ( int arr [ ] , int n , int x ) { int result = 0 ; Map < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int curr_xor = x ^ arr [ i ] ; if ( m . containsKey ( curr_xor ) ) result += m . get ( curr_xor ) ; if ( m . containsKey ( arr [ i ] ) ) { m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . put ( arr [ i ] , 1 ) ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 2 } ; int n = arr . length ; int x = 0 ; System . out . println ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ XOR ▁ = ▁ " + xorPairCount ( arr , n , x ) ) ; } }

def xorPairCount ( arr , n , x ) : NEW_LINE INDENT result = 0 NEW_LINE m = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT curr_xor = x ^ arr [ i ] NEW_LINE if ( curr_xor in m . keys ( ) ) : NEW_LINE INDENT result += m [ curr_xor ] NEW_LINE DEDENT if arr [ i ] in m . keys ( ) : NEW_LINE INDENT m [ arr [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ arr [ i ] ] = 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ 2 , 5 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE x = 0 NEW_LINE print ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ XOR ▁ = ▁ " , xorPairCount ( arr , n , x ) ) NEW_LINE


import java . util . ArrayList ; import java . util . Collections ; class GFG { static boolean isUgly ( int n ) { while ( n % 2 == 0 ) n = n / 2 ; while ( n % 3 == 0 ) n = n / 3 ; while ( n % 5 == 0 ) n = n / 5 ; if ( n == 1 ) return true ; return false ; } static void sortUglyNumbers ( int arr [ ] , int n ) { ArrayList < Integer > list = new ArrayList < > ( ) ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( isUgly ( arr [ i ] ) ) { list . add ( arr [ i ] ) ; arr [ i ] = - 1 ; } } Collections . sort ( list ) ; int j = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == - 1 ) System . out . print ( list . get ( j ++ ) + " ▁ " ) ; else System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 7 , 12 , 10 } ; int n = arr . length ; sortUglyNumbers ( arr , n ) ; } }

def isUgly ( n ) : NEW_LINE INDENT while n % 2 == 0 : NEW_LINE INDENT n = n // 2 NEW_LINE DEDENT while n % 3 == 0 : NEW_LINE INDENT n = n // 3 NEW_LINE DEDENT while n % 5 == 0 : NEW_LINE INDENT n = n // 5 NEW_LINE DEDENT if n == 1 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def sortUglyNumbers ( arr , n ) : NEW_LINE INDENT list = [ ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if isUgly ( arr [ i ] ) : NEW_LINE INDENT list . append ( arr [ i ] ) NEW_LINE arr [ i ] = - 1 NEW_LINE DEDENT DEDENT list . sort ( ) NEW_LINE j = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if arr [ i ] == - 1 : NEW_LINE INDENT print ( list [ j ] , end = " ▁ " ) NEW_LINE j += 1 NEW_LINE DEDENT else : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 7 , 12 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE sortUglyNumbers ( arr , n ) NEW_LINE DEDENT


import java . lang . * ; import java . util . * ; class GFG { static double countNumbers ( int N ) { return ( Math . pow ( 10 , N ) - 1 ) - ( Math . pow ( 10 , N ) - Math . pow ( 8 , N ) ) / 2 ; } static public void main ( String args [ ] ) { int n = 2 ; System . out . println ( countNumbers ( n ) ) ; } }

def countNumber ( n ) : NEW_LINE INDENT return ( pow ( 10 , n ) - 1 ) - ( pow ( 10 , n ) - pow ( 8 , n ) ) // 2 NEW_LINE DEDENT n = 2 NEW_LINE print ( countNumber ( n ) ) NEW_LINE


import java . util . * ; class GFG { static int binomialCoeff ( int n , int k ) { int C [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } static int cntSubSeq ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int num = arr [ k - 1 ] ; int Y = 0 ; for ( int i = k - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == num ) Y ++ ; } int cntX = Y ; for ( int i = k ; i < n ; i ++ ) { if ( arr [ i ] == num ) cntX ++ ; } return binomialCoeff ( cntX , Y ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 2 ; System . out . println ( cntSubSeq ( arr , n , k ) ) ; } }

def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( k + 1 ) ] NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT for j in range ( 0 , min ( i , k ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] NEW_LINE DEDENT DEDENT DEDENT return C [ n ] [ k ] NEW_LINE DEDENT def cntSubSeq ( arr , n , k ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE num = arr [ k - 1 ] ; NEW_LINE Y = 0 ; NEW_LINE for i in range ( k - 1 , - 1 , 1 ) : NEW_LINE INDENT if ( arr [ i ] == num ) : NEW_LINE INDENT Y += 1 NEW_LINE DEDENT DEDENT cntX = Y ; NEW_LINE for i in range ( k , n ) : NEW_LINE INDENT if ( arr [ i ] == num ) : NEW_LINE INDENT cntX += 1 NEW_LINE DEDENT DEDENT return binomialCoeff ( cntX , Y ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE k = 2 NEW_LINE print ( cntSubSeq ( arr , n , k ) ) NEW_LINE


import java . util . * ; class GFG { static int largest_sum ( int arr [ ] , int n ) { int maximum = - 1 ; HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . containsKey ( arr [ i ] ) ) { m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . put ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( m . get ( arr [ i ] ) > 1 ) { if ( m . containsKey ( 2 * arr [ i ] ) ) { m . put ( 2 * arr [ i ] , m . get ( 2 * arr [ i ] ) + m . get ( arr [ i ] ) / 2 ) ; } else { m . put ( 2 * arr [ i ] , m . get ( arr [ i ] ) / 2 ) ; } if ( 2 * arr [ i ] > maximum ) maximum = 2 * arr [ i ] ; } } return maximum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 4 , 7 , 8 } ; int n = arr . length ; System . out . println ( largest_sum ( arr , n ) ) ; } }

def largest_sum ( arr , n ) : NEW_LINE INDENT maximum = - 1 NEW_LINE m = dict ( ) NEW_LINE for i in arr : NEW_LINE INDENT m [ i ] = m . get ( i , 0 ) + 1 NEW_LINE DEDENT for j in list ( m ) : NEW_LINE INDENT if ( ( j in m ) and m [ j ] > 1 ) : NEW_LINE INDENT x , y = 0 , 0 NEW_LINE if 2 * j in m : NEW_LINE INDENT m [ 2 * j ] = m [ 2 * j ] + m [ j ] // 2 NEW_LINE DEDENT else : NEW_LINE INDENT m [ 2 * j ] = m [ j ] // 2 NEW_LINE DEDENT if ( 2 * j > maximum ) : NEW_LINE INDENT maximum = 2 * j NEW_LINE DEDENT DEDENT DEDENT return maximum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 1 , 2 , 4 , 7 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( largest_sum ( arr , n ) ) NEW_LINE DEDENT


class GFG { static int highestPowerof2 ( int n ) { int res = 0 ; for ( int i = n ; i >= 1 ; i -- ) { if ( ( i & ( i - 1 ) ) == 0 ) { res = i ; break ; } } return res ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( highestPowerof2 ( n ) ) ; } }

def highestPowerof2 ( n ) : NEW_LINE INDENT res = 0 ; NEW_LINE for i in range ( n , 0 , - 1 ) : NEW_LINE INDENT if ( ( i & ( i - 1 ) ) == 0 ) : NEW_LINE INDENT res = i ; NEW_LINE break ; NEW_LINE DEDENT DEDENT return res ; NEW_LINE DEDENT n = 10 ; NEW_LINE print ( highestPowerof2 ( n ) ) ; NEW_LINE


class GFG { public static int computeCost ( int arr [ ] , int N , int X ) { int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) cost += Math . abs ( arr [ i ] - X ) ; return cost ; } public static int minCostToMakeElementEqual ( int arr [ ] , int N ) { int low , high ; low = high = arr [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( low > arr [ i ] ) low = arr [ i ] ; if ( high < arr [ i ] ) high = arr [ i ] ; } while ( ( high - low ) > 2 ) { int mid1 = low + ( high - low ) / 3 ; int mid2 = high - ( high - low ) / 3 ; int cost1 = computeCost ( arr , N , mid1 ) ; int cost2 = computeCost ( arr , N , mid2 ) ; if ( cost1 < cost2 ) high = mid2 ; else low = mid1 ; } return computeCost ( arr , N , ( low + high ) / 2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 100 , 101 } ; int N = arr . length ; System . out . println ( minCostToMakeElementEqual ( arr , N ) ) ; } }

def computeCost ( arr , N , X ) : NEW_LINE INDENT cost = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT cost += abs ( arr [ i ] - X ) NEW_LINE DEDENT return cost NEW_LINE DEDENT def minCostToMakeElementEqual ( arr , N ) : NEW_LINE INDENT low = high = arr [ 0 ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( low > arr [ i ] ) : low = arr [ i ] NEW_LINE if ( high < arr [ i ] ) : high = arr [ i ] NEW_LINE DEDENT while ( ( high - low ) > 2 ) : NEW_LINE INDENT mid1 = low + ( high - low ) // 3 NEW_LINE mid2 = high - ( high - low ) // 3 NEW_LINE cost1 = computeCost ( arr , N , mid1 ) NEW_LINE cost2 = computeCost ( arr , N , mid2 ) NEW_LINE if ( cost1 < cost2 ) : NEW_LINE INDENT high = mid2 NEW_LINE DEDENT else : NEW_LINE INDENT low = mid1 NEW_LINE DEDENT DEDENT return computeCost ( arr , N , ( low + high ) // 2 ) NEW_LINE DEDENT arr = [ 1 , 100 , 101 ] NEW_LINE N = len ( arr ) NEW_LINE print ( minCostToMakeElementEqual ( arr , N ) ) NEW_LINE


import java . util . * ; class GFG { static void printMaxSum ( int arr [ ] , int n ) { int dp [ ] = new int [ n ] ; Arrays . fill ( dp , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i ] = arr [ i ] ; int maxi = 0 ; for ( int j = 1 ; j <= Math . sqrt ( i + 1 ) ; j ++ ) { if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) { if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ; if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ; } } dp [ i ] += maxi ; } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( dp [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 4 , 6 , 5 } ; int n = arr . length ; printMaxSum ( arr , n ) ; } }

def printMaxSum ( arr , n ) : NEW_LINE INDENT dp = [ 0 for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT dp [ i ] = arr [ i ] NEW_LINE maxi = 0 NEW_LINE for j in range ( 1 , int ( ( i + 1 ) ** 0.5 ) + 1 ) : NEW_LINE INDENT if ( ( i + 1 ) % j == 0 and ( i + 1 ) != j ) : NEW_LINE INDENT if ( dp [ j - 1 ] > maxi ) : NEW_LINE INDENT maxi = dp [ j - 1 ] NEW_LINE DEDENT if ( dp [ ( i + 1 ) // j - 1 ] > maxi and j != 1 ) : NEW_LINE INDENT maxi = dp [ ( i + 1 ) // j - 1 ] NEW_LINE DEDENT DEDENT DEDENT dp [ i ] += maxi NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT print ( dp [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT arr = [ 2 , 3 , 1 , 4 , 6 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE printMaxSum ( arr , n ) NEW_LINE


class GFG { static int setKthBit ( int n , int k ) { return ( ( 1 << k ) | n ) ; } public static void main ( String arg [ ] ) { int n = 10 , k = 2 ; System . out . print ( " Kth ▁ bit ▁ set ▁ number ▁ = ▁ " + setKthBit ( n , k ) ) ; } }

def setKthBit ( n , k ) : NEW_LINE INDENT return ( ( 1 << k ) | n ) NEW_LINE DEDENT n = 10 NEW_LINE k = 2 NEW_LINE print ( " Kth ▁ bit ▁ set ▁ number ▁ = ▁ " , setKthBit ( n , k ) ) NEW_LINE


import java . util . * ; public class GFG { static int m [ ] , a [ ] [ ] , x [ ] ; static ArrayList < Integer > g [ ] ; static int ans = 0 ; static void dfs ( int u , int p ) { for ( int v : g [ u ] ) { if ( v != p ) { dfs ( v , u ) ; for ( int i = 0 ; i < 22 ; i ++ ) a [ u ] [ i ] += a [ v ] [ i ] ; } } int pp = 0 ; for ( int i = 0 ; i < 22 ; i ++ ) { if ( ! ( ( a [ u ] [ i ] > 0 && x [ i ] - a [ u ] [ i ] > 0 ) || ( a [ u ] [ i ] == 0 && x [ i ] == 0 ) ) ) { pp = 1 ; break ; } } if ( pp == 0 ) ans ++ ; } public static void main ( String args [ ] ) { int n = 4 ; g = new ArrayList [ n + 1 ] ; m = new int [ n + 1 ] ; m [ 1 ] = 1 ; m [ 2 ] = 3 ; m [ 3 ] = 2 ; m [ 4 ] = 3 ; a = new int [ n + 1 ] [ 22 ] ; x = new int [ 22 ] ; for ( int i = 1 ; i <= n ; i ++ ) { g [ i ] = new ArrayList < > ( ) ; int y = m [ i ] ; int k = 0 ; while ( y != 0 ) { int p = y % 2 ; if ( p == 1 ) { x [ k ] ++ ; a [ i ] [ k ] ++ ; } y = y / 2 ; k ++ ; } } g [ 1 ] . add ( 2 ) ; g [ 2 ] . add ( 1 ) ; g [ 1 ] . add ( 3 ) ; g [ 3 ] . add ( 1 ) ; g [ 1 ] . add ( 4 ) ; g [ 4 ] . add ( 1 ) ; dfs ( 1 , 0 ) ; System . out . println ( ans ) ; } }

m , x = [ 0 ] * 1000 , [ 0 ] * 22 NEW_LINE a = [ [ 0 for i in range ( 22 ) ] for j in range ( 1000 ) ] NEW_LINE ans = 0 NEW_LINE def dfs ( u , p ) : NEW_LINE INDENT global ans NEW_LINE for i in range ( 0 , len ( g [ u ] ) ) : NEW_LINE INDENT v = g [ u ] [ i ] NEW_LINE if v != p : NEW_LINE INDENT dfs ( v , u ) NEW_LINE for i in range ( 0 , 22 ) : NEW_LINE INDENT a [ u ] [ i ] += a [ v ] [ i ] NEW_LINE DEDENT DEDENT DEDENT pp = 0 NEW_LINE for i in range ( 0 , 22 ) : NEW_LINE INDENT if ( not ( ( a [ u ] [ i ] > 0 and x [ i ] - a [ u ] [ i ] > 0 ) or ( a [ u ] [ i ] == 0 and x [ i ] == 0 ) ) ) : NEW_LINE INDENT pp = 1 NEW_LINE break NEW_LINE DEDENT DEDENT if pp == 0 : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 NEW_LINE g = [ [ ] for i in range ( n + 1 ) ] NEW_LINE m [ 1 ] = 1 NEW_LINE m [ 2 ] = 3 NEW_LINE m [ 3 ] = 2 NEW_LINE m [ 4 ] = 3 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT y , k = m [ i ] , 0 NEW_LINE while y != 0 : NEW_LINE INDENT p = y % 2 NEW_LINE if p == 1 : NEW_LINE INDENT x [ k ] += 1 NEW_LINE a [ i ] [ k ] += 1 NEW_LINE DEDENT y = y // 2 NEW_LINE k += 1 NEW_LINE DEDENT DEDENT g [ 1 ] . append ( 2 ) NEW_LINE g [ 2 ] . append ( 1 ) NEW_LINE g [ 1 ] . append ( 3 ) NEW_LINE g [ 3 ] . append ( 1 ) NEW_LINE g [ 1 ] . append ( 4 ) NEW_LINE g [ 4 ] . append ( 1 ) NEW_LINE dfs ( 1 , 0 ) NEW_LINE print ( ans ) NEW_LINE DEDENT


class GFG { static float squareRoot ( float n ) { float x = n ; float y = 1 ; double e = 0.000001 ; while ( x - y > e ) { x = ( x + y ) / 2 ; y = n / x ; } return x ; } public static void main ( String [ ] args ) { int n = 50 ; System . out . printf ( " Square ▁ root ▁ of ▁ " + n + " ▁ is ▁ " + squareRoot ( n ) ) ; } }

def squareRoot ( n ) : NEW_LINE INDENT x = n NEW_LINE y = 1 NEW_LINE e = 0.000001 NEW_LINE while ( x - y > e ) : NEW_LINE INDENT x = ( x + y ) / 2 NEW_LINE y = n / x NEW_LINE DEDENT return x NEW_LINE DEDENT n = 50 NEW_LINE print ( " Square ▁ root ▁ of " , n , " is " , round ( squareRoot ( n ) , 6 ) ) NEW_LINE


class GFG { static boolean checkArray ( int arr [ ] , int n ) { int zero = 0 , one = 0 , minusone = 0 , other = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) zero ++ ; else if ( arr [ i ] == 1 ) one ++ ; else if ( arr [ i ] == - 1 ) minusone ++ ; else other ++ ; } if ( other > 1 ) return false ; else if ( other != 0 && minusone != 0 ) return false ; else if ( minusone >= 1 && one == 0 ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 1 , 10 } ; int n = arr . length ; if ( checkArray ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def checkArray ( arr , n ) : NEW_LINE INDENT zero = 0 ; one = 0 ; NEW_LINE minusone = 0 ; other = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT zero += 1 NEW_LINE DEDENT elif ( arr [ i ] == 1 ) : NEW_LINE INDENT one += 1 NEW_LINE DEDENT elif ( arr [ i ] == - 1 ) : NEW_LINE INDENT minusone += 1 NEW_LINE DEDENT else : NEW_LINE INDENT other += 1 NEW_LINE DEDENT DEDENT if ( other > 1 ) : NEW_LINE INDENT return false NEW_LINE DEDENT elif ( other != 0 and minusone != 0 ) : NEW_LINE INDENT return false NEW_LINE DEDENT elif ( minusone >= 1 and one == 0 ) : NEW_LINE INDENT return false NEW_LINE DEDENT return True NEW_LINE DEDENT arr = [ 0 , 1 , 1 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE if ( checkArray ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


import java . lang . * ; import java . io . * ; import java . util . * ; class BinaryToString { static String printBinary ( double num ) { if ( num >= 1 || num <= 0 ) return " ERROR " ; StringBuilder binary = new StringBuilder ( ) ; double frac = 0.5 ; binary . append ( " . " ) ; while ( num > 0 ) { if ( binary . length ( ) >= 32 ) return " ERROR " ; if ( num >= frac ) { binary . append ( 1 ) ; num -= frac ; } else binary . append ( 0 ) ; frac /= 2 ; } return binary . toString ( ) ; } public static void main ( String [ ] args ) { double num1 = 0.625 ; String output = printBinary ( num1 ) ; System . out . println ( " ( 0" + output + " ) ▁ ▁ in ▁ base ▁ 2" ) ; double num2 = 0.72 ; output = printBinary ( num2 ) ; System . out . println ( " ( " + output + " ) ▁ " ) ; } }

def toBinary ( n ) : NEW_LINE INDENT if ( n >= 1 or n <= 0 ) : NEW_LINE INDENT return " ERROR " ; NEW_LINE DEDENT frac = 0.5 ; NEW_LINE answer = " . " ; NEW_LINE while ( n > 0 ) : NEW_LINE INDENT if ( len ( answer ) >= 32 ) : NEW_LINE INDENT return " ERROR " ; NEW_LINE DEDENT if ( n >= frac ) : NEW_LINE INDENT answer += "1" ; NEW_LINE n = n - frac ; NEW_LINE DEDENT else : NEW_LINE INDENT answer += "0" ; NEW_LINE DEDENT frac = ( frac / 2 ) ; NEW_LINE DEDENT return answer ; NEW_LINE DEDENT n = 0.625 ; NEW_LINE result = toBinary ( n ) ; NEW_LINE print ( " ( ▁ 0" , result , " ) ▁ in ▁ base ▁ 2" ) ; NEW_LINE m = 0.72 ; NEW_LINE result = toBinary ( m ) ; NEW_LINE print ( " ( " , result , " ) " ) ; NEW_LINE


import java . util . * ; class GFG { static boolean valid ( int [ ] cnt ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( cnt [ i ] >= 2 ) return false ; } return true ; } static String getGoodString ( String ss , int n ) { char [ ] s = ss . toCharArray ( ) ; if ( n < 26 ) return " - 1" ; int [ ] cnt = new int [ 27 ] ; for ( int i = 25 ; i < n ; i ++ ) { for ( int j = i ; j >= i - 25 ; j -- ) { if ( s [ j ] != ' ? ' ) cnt [ ( ( int ) s [ j ] - ( int ) ' a ' ) ] ++ ; } if ( valid ( cnt ) ) { int cur = 0 ; while ( cnt [ cur ] > 0 ) cur ++ ; for ( int j = i - 25 ; j <= i ; j ++ ) { if ( s [ j ] == ' ? ' ) { s [ j ] = ( char ) ( cur + ( int ) ( ' a ' ) ) ; cur ++ ; while ( cnt [ cur ] > 0 ) cur ++ ; } } return new String ( s ) ; } } return " - 1" ; } public static void main ( String [ ] args ) { String s = " abcdefghijkl ? nopqrstuvwxy ? " ; int n = s . length ( ) ; System . out . println ( getGoodString ( s , n ) ) ; } }

def valid ( cnt ) : NEW_LINE INDENT for i in range ( 0 , 26 ) : NEW_LINE INDENT if cnt [ i ] >= 2 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def getGoodString ( s , n ) : NEW_LINE INDENT if n < 26 : NEW_LINE INDENT return " - 1" NEW_LINE DEDENT for i in range ( 25 , n ) : NEW_LINE INDENT cnt = [ 0 ] * 26 NEW_LINE for j in range ( i , i - 26 , - 1 ) : NEW_LINE INDENT if s [ j ] != ' ? ' : NEW_LINE INDENT cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT DEDENT if valid ( cnt ) : NEW_LINE INDENT cur = 0 NEW_LINE while cur < 26 and cnt [ cur ] > 0 : NEW_LINE INDENT cur += 1 NEW_LINE DEDENT for j in range ( i - 25 , i + 1 ) : NEW_LINE INDENT if s [ j ] == ' ? ' : NEW_LINE INDENT s [ j ] = chr ( cur + ord ( ' a ' ) ) NEW_LINE cur += 1 NEW_LINE while cur < 26 and cnt [ cur ] > 0 : NEW_LINE INDENT cur += 1 NEW_LINE DEDENT DEDENT DEDENT return ' ' . join ( s ) NEW_LINE DEDENT DEDENT return " - 1" NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " abcdefghijkl ? nopqrstuvwxy ? " NEW_LINE n = len ( s ) NEW_LINE print ( getGoodString ( list ( s ) , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { public static void main ( String [ ] args ) { int side = 4 ; System . out . print ( " Volume ▁ of ▁ dodecahedron ▁ = ▁ " ) ; System . out . println ( vol_of_dodecahedron ( side ) ) ; } static double vol_of_dodecahedron ( int side ) { return ( ( ( 15 + ( 7 * ( Math . sqrt ( 5 ) ) ) ) / 4 ) * ( Math . pow ( side , 3 ) ) ) ; } }

import math NEW_LINE def vol_of_dodecahedron ( side ) : NEW_LINE INDENT return ( ( ( 15 + ( 7 * ( math . sqrt ( 5 ) ) ) ) / 4 ) * ( math . pow ( side , 3 ) ) ) NEW_LINE DEDENT side = 4 NEW_LINE print ( " Volume ▁ of ▁ dodecahedron ▁ = " , round ( vol_of_dodecahedron ( side ) , 2 ) ) NEW_LINE


class GFG { static int sum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } sum = sum * ( int ) Math . pow ( 2 , n - 1 ) ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 5 , 6 } ; int n = arr . length ; System . out . println ( sum ( arr , n ) ) ; } }

def sum ( arr , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in arr : NEW_LINE INDENT sum += i NEW_LINE DEDENT sum = sum * pow ( 2 , n - 1 ) NEW_LINE return sum NEW_LINE DEDENT arr = [ 2 , 1 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( sum ( arr , n ) ) NEW_LINE


class GFG { static void myCopy ( char s1 [ ] , char s2 [ ] , int index ) { s2 [ index ] = s1 [ index ] ; if ( index == s1 . length - 1 ) { return ; } myCopy ( s1 , s2 , index + 1 ) ; } public static void main ( String [ ] args ) { char s1 [ ] = " GEEKSFORGEEKS " . toCharArray ( ) ; char s2 [ ] = new char [ s1 . length ] ; int index = 0 ; myCopy ( s1 , s2 , index ) ; System . out . println ( String . valueOf ( s2 ) ) ; } }

def myCopy ( s1 , s2 , index ) : NEW_LINE INDENT s2 [ index ] = s1 [ index ] ; NEW_LINE if ( index == len ( s1 ) - 1 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT myCopy ( s1 , s2 , index + 1 ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s1 = " GEEKSFORGEEKS " ; NEW_LINE s2 = [ 0 ] * ( len ( s1 ) ) ; NEW_LINE index = 0 ; NEW_LINE myCopy ( s1 , s2 , index ) ; NEW_LINE print ( " " . join ( s2 ) ) ; NEW_LINE DEDENT


import java . io . * ; import java . util . * ; public class GFG { static void countDigits ( double val , long [ ] arr ) { while ( ( long ) val > 0 ) { long digit = ( long ) val % 10 ; arr [ ( int ) digit ] ++ ; val = ( long ) val / 10 ; } return ; } static void countFrequency ( int x , int n ) { long [ ] freq_count = new long [ 10 ] ; for ( int i = 1 ; i <= n ; i ++ ) { double val = Math . pow ( ( double ) x , ( double ) i ) ; countDigits ( val , freq_count ) ; } for ( int i = 0 ; i <= 9 ; i ++ ) { System . out . print ( freq_count [ i ] + " ▁ " ) ; } } public static void main ( String args [ ] ) { int x = 15 , n = 3 ; countFrequency ( x , n ) ; } }

import math NEW_LINE def countDigits ( val , arr ) : NEW_LINE INDENT while ( val > 0 ) : NEW_LINE INDENT digit = val % 10 NEW_LINE arr [ int ( digit ) ] += 1 NEW_LINE val = val // 10 NEW_LINE DEDENT return ; NEW_LINE DEDENT def countFrequency ( x , n ) : NEW_LINE INDENT freq_count = [ 0 ] * 10 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT val = math . pow ( x , i ) NEW_LINE countDigits ( val , freq_count ) NEW_LINE DEDENT for i in range ( 10 ) : NEW_LINE INDENT print ( freq_count [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 15 NEW_LINE n = 3 NEW_LINE countFrequency ( x , n ) NEW_LINE DEDENT


class GFG { static boolean isValidNesbitt ( double a , double b , double c ) { double A = a / ( b + c ) ; double B = b / ( a + c ) ; double C = c / ( a + b ) ; double inequality = A + B + C ; return ( inequality >= 1.5 ) ; } public static void main ( String args [ ] ) { double a = 1.0 , b = 2.0 , c = 3.0 ; if ( isValidNesbitt ( a , b , c ) == true ) { System . out . print ( " Nesbitt ' s ▁ inequality " + " ▁ satisfied . " ) ; System . out . println ( " for ▁ real ▁ numbers ▁ " + a + " , ▁ " + b + " , ▁ " + c ) ; } else System . out . println ( " Nesbitts ▁ inequality " + " ▁ not ▁ satisfied " ) ; } }

def isValidNesbitt ( a , b , c ) : NEW_LINE INDENT A = a / ( b + c ) ; NEW_LINE B = b / ( a + c ) ; NEW_LINE C = c / ( a + b ) ; NEW_LINE inequality = A + B + C ; NEW_LINE return ( inequality >= 1.5 ) ; NEW_LINE DEDENT a = 1.0 ; NEW_LINE b = 2.0 ; NEW_LINE c = 3.0 ; NEW_LINE if ( isValidNesbitt ( a , b , c ) ) : NEW_LINE INDENT print ( " Nesbitt ' s ▁ inequality ▁ satisfied . " , " ▁ for ▁ real ▁ numbers ▁ " , a , " , ▁ " , b , " , ▁ " , c ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ satisfied " ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int coin ( int totalRupees , int X , int Y , int Z ) { float one = 0 , fifty = 0 , twentyfive = 0 , result = 0 , total = 0 ; one = X * 1 ; fifty = ( ( Y * 1 ) / 2 ) ; twentyfive = ( ( Z * 1 ) / 4 ) ; total = one + fifty + twentyfive ; result = ( ( totalRupees ) / total ) ; return ( int ) result ; } public static void main ( String [ ] args ) { int totalRupees = 1800 ; int X = 1 , Y = 2 , Z = 4 ; int Rupees = coin ( totalRupees , X , Y , Z ) ; System . out . println ( "1 ▁ rupess ▁ coins ▁ = ▁ " + Rupees * 1 ) ; System . out . println ( "50 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 2 ) ; System . out . println ( "25 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 4 ) ; } }

def coin ( totalRupees , X , Y , Z ) : NEW_LINE INDENT one = X * 1 NEW_LINE fifty = ( ( Y * 1 ) / 2.0 ) NEW_LINE twentyfive = ( ( Z * 1 ) / 4.0 ) NEW_LINE total = one + fifty + twentyfive NEW_LINE result = ( ( totalRupees ) / total ) NEW_LINE return int ( result ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT totalRupees = 1800 NEW_LINE X , Y , Z = 1 , 2 , 4 NEW_LINE Rupees = coin ( totalRupees , X , Y , Z ) NEW_LINE print ( "1 ▁ rupess ▁ coins ▁ = ▁ " , Rupees * 1 ) NEW_LINE print ( "50 ▁ paisa ▁ coins ▁ = ▁ " , Rupees * 2 ) NEW_LINE print ( "25 ▁ paisa ▁ coins ▁ = ▁ " , Rupees * 4 ) NEW_LINE DEDENT


class GFG { public static int nthTerm ( int N ) { int nth = 0 ; nth = ( N * N * ( N + 1 ) ) / 2 ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . println ( nthTerm ( N ) ) ; } }

def nthTerm ( N ) : NEW_LINE INDENT nth = 0 NEW_LINE nth = ( N * N * ( N + 1 ) ) // 2 NEW_LINE return nth NEW_LINE DEDENT N = 5 NEW_LINE print ( nthTerm ( N ) ) NEW_LINE


import java . util . * ; class GFG { static int doubleFactorial ( int n ) { int fact = 1 ; for ( int i = 1 ; i <= n ; i = i + 2 ) { fact = fact * i ; } return fact ; } static int hermiteNumber ( int n ) { if ( n % 2 == 1 ) return 0 ; else { int number = ( int ) ( Math . pow ( 2 , n / 2 ) ) * doubleFactorial ( n - 1 ) ; if ( ( n / 2 ) % 2 == 1 ) number = number * - 1 ; return number ; } } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( hermiteNumber ( n ) ) ; } }

from math import pow NEW_LINE def doubleFactorial ( n ) : NEW_LINE INDENT fact = 1 NEW_LINE for i in range ( 1 , n + 1 , 2 ) : NEW_LINE INDENT fact = fact * i NEW_LINE DEDENT return fact NEW_LINE DEDENT def hermiteNumber ( n ) : NEW_LINE INDENT if ( n % 2 == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT number = ( ( pow ( 2 , n / 2 ) ) * doubleFactorial ( n - 1 ) ) NEW_LINE if ( ( n / 2 ) % 2 == 1 ) : NEW_LINE INDENT number = number * - 1 NEW_LINE DEDENT return number NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE print ( int ( hermiteNumber ( n ) ) ) NEW_LINE DEDENT


import java . util . HashMap ; class GFG { public static int minReplace ( int a [ ] , int n ) { int i ; HashMap < Integer , Integer > te = new HashMap < > ( ) ; HashMap < Integer , Integer > to = new HashMap < > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( te . containsKey ( a [ i ] ) ) te . put ( a [ i ] , te . get ( a [ i ] ) + 1 ) ; else te . put ( a [ i ] , 1 ) ; } else { if ( to . containsKey ( a [ i ] ) ) to . put ( a [ i ] , to . get ( a [ i ] ) + 1 ) ; else to . put ( a [ i ] , 1 ) ; } } int me = - 1 ; int mo = - 1 ; int ce = - 1 ; int co = - 1 ; for ( Integer It : te . keySet ( ) ) { if ( te . get ( It ) > ce ) { ce = te . get ( It ) ; me = It ; } } for ( Integer It : to . keySet ( ) ) { if ( to . get ( It ) > co ) { co = to . get ( It ) ; mo = It ; } } int res = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { if ( a [ i ] != me ) res ++ ; } else { if ( a [ i ] != mo ) res ++ ; } } return res ; } public static void main ( String [ ] args ) { int n ; n = 4 ; int a [ ] = { 3 , 1 , 3 , 2 } ; System . out . println ( minReplace ( a , n ) ) ; } }

def minReplace ( a : list , n ) -> int : NEW_LINE INDENT te = dict ( ) NEW_LINE to = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT if a [ i ] not in te : NEW_LINE INDENT te [ a [ i ] ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT te [ a [ i ] ] += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if a [ i ] not in to : NEW_LINE INDENT to [ a [ i ] ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT to [ a [ i ] ] += 1 NEW_LINE DEDENT DEDENT DEDENT me = - 1 NEW_LINE mo = - 1 NEW_LINE ce = - 1 NEW_LINE co = - 1 NEW_LINE for it in te : NEW_LINE INDENT if te [ it ] > ce : NEW_LINE INDENT ce = te [ it ] NEW_LINE me = it NEW_LINE DEDENT DEDENT for it in to : NEW_LINE INDENT if to [ it ] > co : NEW_LINE INDENT co = to [ it ] NEW_LINE mo = it NEW_LINE DEDENT DEDENT res = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT if a [ i ] != me : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if a [ i ] != mo : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 4 NEW_LINE a = [ 3 , 1 , 3 , 2 ] NEW_LINE print ( minReplace ( a , n ) ) NEW_LINE DEDENT


class GFG { static int missingNumber ( int arr1 [ ] , int arr2 [ ] , int n ) { int mnum = 0 ; for ( int i = 0 ; i < n ; i ++ ) mnum = mnum ^ arr1 [ i ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) mnum = mnum ^ arr2 [ i ] ; return mnum ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 4 , 8 , 1 , 3 , 7 } ; int arr2 [ ] = { 7 , 4 , 3 , 1 } ; int n = arr1 . length ; System . out . println ( " Missing ▁ number ▁ = ▁ " + missingNumber ( arr1 , arr2 , n ) ) ; } }

def missingNumber ( arr1 , arr2 , n ) : NEW_LINE INDENT mnum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT mnum = mnum ^ arr1 [ i ] NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT mnum = mnum ^ arr2 [ i ] NEW_LINE DEDENT return mnum NEW_LINE DEDENT arr1 = [ 4 , 8 , 1 , 3 , 7 ] NEW_LINE arr2 = [ 7 , 4 , 3 , 1 ] NEW_LINE n = len ( arr1 ) NEW_LINE print ( " Missing ▁ number ▁ = ▁ " , missingNumber ( arr1 , arr2 , n ) ) NEW_LINE


class GFG { static int countChars ( String str , int n ) { int i = 0 , cnt = 0 ; while ( i < n ) { if ( str . charAt ( i ) == '0' ) i += 1 ; else i += 2 ; cnt += 1 ; } return cnt ; } public static void main ( String [ ] args ) { String str = "11010" ; int n = str . length ( ) ; System . out . println ( countChars ( str , n ) ) ; } }

def countChars ( string , n ) : NEW_LINE INDENT i = 0 ; cnt = 0 ; NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( string [ i ] == '0' ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT i += 2 ; NEW_LINE DEDENT cnt += 1 ; NEW_LINE DEDENT return cnt ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = "11010" ; NEW_LINE n = len ( string ) ; NEW_LINE print ( countChars ( string , n ) ) ; NEW_LINE DEDENT


class GFG { static int addOne ( int x ) { return ( - ( ~ x ) ) ; } public static void main ( String [ ] args ) { System . out . printf ( " % d " , addOne ( 13 ) ) ; } }

def addOne ( x ) : NEW_LINE INDENT return ( - ( ~ x ) ) ; NEW_LINE DEDENT print ( addOne ( 13 ) ) NEW_LINE


class Solution { static int smallestEven ( int n ) { if ( n == 1 ) return 0 ; return Math . pow ( 10 , n - 1 ) ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( smallestEven ( n ) ) ; } }

def smallestEven ( n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return pow ( 10 , n - 1 ) NEW_LINE DEDENT n = 4 NEW_LINE print ( smallestEven ( n ) ) NEW_LINE


class GFG { static int N = 10000 ; static int MOD = 1000000007 ; static int [ ] F = new int [ N ] ; static void precompute ( ) { F [ 1 ] = 2 ; F [ 2 ] = 3 ; F [ 3 ] = 4 ; for ( int i = 4 ; i < N ; i ++ ) F [ i ] = ( F [ i - 1 ] + F [ i - 2 ] ) % MOD ; } public static void main ( String [ ] args ) { int n = 8 ; precompute ( ) ; System . out . println ( F [ n ] ) ; } }

N = 10000 ; NEW_LINE MOD = 1000000007 ; NEW_LINE F = [ 0 ] * N ; NEW_LINE def precompute ( ) : NEW_LINE INDENT F [ 1 ] = 2 ; NEW_LINE F [ 2 ] = 3 ; NEW_LINE F [ 3 ] = 4 ; NEW_LINE for i in range ( 4 , N ) : NEW_LINE INDENT F [ i ] = ( F [ i - 1 ] + F [ i - 2 ] ) % MOD ; NEW_LINE DEDENT DEDENT n = 8 ; NEW_LINE precompute ( ) ; NEW_LINE print ( F [ n ] ) ; NEW_LINE


import java . util . * ; class GFG { static int N = 1000005 ; static long MAX = ( long ) 1e18 ; static Vector < Long > powers = new Vector < > ( ) ; static TreeSet < Long > squares = new TreeSet < > ( ) ; static TreeSet < Long > s = new TreeSet < > ( ) ; static void powersPrecomputation ( ) { for ( long i = 2 ; i < N ; i ++ ) { squares . add ( i * i ) ; if ( squares . contains ( i ) ) continue ; long temp = i ; while ( i * i <= MAX / temp ) { temp *= ( i * i ) ; s . add ( temp ) ; } } for ( long x : s ) powers . add ( x ) ; } static long calculateAnswer ( long L , long R ) { powersPrecomputation ( ) ; long perfectSquares = ( long ) ( Math . floor ( Math . sqrt ( R ) ) - Math . floor ( Math . sqrt ( L - 1 ) ) ) ; long high = Collections . binarySearch ( powers , R ) ; long low = Collections . binarySearch ( powers , L ) ; long perfectPowers = perfectSquares + ( high - low ) ; long ans = ( R - L + 1 ) - perfectPowers ; return ans ; } public static void main ( String [ ] args ) { long L = 13 , R = 20 ; System . out . println ( calculateAnswer ( L , R ) ) ; } }

from bisect import bisect as upper_bound NEW_LINE from bisect import bisect_left as lower_bound NEW_LINE from math import floor NEW_LINE N = 1000005 NEW_LINE MAX = 10 ** 18 NEW_LINE powers = [ ] NEW_LINE squares = dict ( ) NEW_LINE s = dict ( ) NEW_LINE def powersPrecomputation ( ) : NEW_LINE INDENT for i in range ( 2 , N ) : NEW_LINE INDENT squares [ i * i ] = 1 NEW_LINE if ( i not in squares . keys ( ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT temp = i NEW_LINE while ( i * i <= ( MAX // temp ) ) : NEW_LINE INDENT temp *= ( i * i ) NEW_LINE s [ temp ] = 1 NEW_LINE DEDENT DEDENT for x in s : NEW_LINE INDENT powers . append ( x ) NEW_LINE DEDENT DEDENT def calculateAnswer ( L , R ) : NEW_LINE INDENT powersPrecomputation ( ) NEW_LINE perfectSquares = floor ( ( R ) ** ( .5 ) ) - floor ( ( L - 1 ) ** ( .5 ) ) NEW_LINE high = upper_bound ( powers , R ) NEW_LINE low = lower_bound ( powers , L ) NEW_LINE perfectPowers = perfectSquares + ( high - low ) NEW_LINE ans = ( R - L + 1 ) - perfectPowers NEW_LINE return ans NEW_LINE DEDENT L = 13 NEW_LINE R = 20 NEW_LINE print ( calculateAnswer ( L , R ) ) NEW_LINE


import java . util . * ; class GFG { public static int lenOfLongIncSubArr ( int arr [ ] , int n ) { int max = 1 , len = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) len ++ ; else { if ( max < len ) max = len ; len = 1 ; } } if ( max < len ) max = len ; return max ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 6 , 3 , 5 , 7 , 8 , 9 , 1 , 2 } ; int n = arr . length ; System . out . println ( " Length ▁ = ▁ " + lenOfLongIncSubArr ( arr , n ) ) ; } }

def lenOfLongIncSubArr ( arr , n ) : NEW_LINE INDENT m = 1 NEW_LINE l = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] > arr [ i - 1 ] ) : NEW_LINE INDENT l = l + 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( m < l ) : NEW_LINE INDENT m = l NEW_LINE DEDENT l = 1 NEW_LINE DEDENT DEDENT if ( m < l ) : NEW_LINE INDENT m = l NEW_LINE DEDENT return m NEW_LINE DEDENT arr = [ 5 , 6 , 3 , 5 , 7 , 8 , 9 , 1 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Length ▁ = ▁ " , lenOfLongIncSubArr ( arr , n ) ) NEW_LINE


class GFG { static int cmp ( int a , int b ) { if ( a > b ) return 1 ; else if ( a == b ) return 0 ; else return - 1 ; } static int maxSubarraySize ( int [ ] arr , int n ) { int ans = 1 ; int anchor = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int c = cmp ( arr [ i - 1 ] , arr [ i ] ) ; if ( c == 0 ) anchor = i ; else if ( i == n - 1 || c * cmp ( arr [ i ] , arr [ i + 1 ] ) != - 1 ) { ans = Math . max ( ans , i - anchor + 1 ) ; anchor = i ; } } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 } ; int n = arr . length ; System . out . println ( maxSubarraySize ( arr , n ) ) ; } }

def cmp ( a , b ) : NEW_LINE INDENT return ( a > b ) - ( a < b ) NEW_LINE DEDENT def maxSubarraySize ( arr ) : NEW_LINE INDENT N = len ( arr ) NEW_LINE ans = 1 NEW_LINE anchor = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT c = cmp ( arr [ i - 1 ] , arr [ i ] ) NEW_LINE if c == 0 : NEW_LINE INDENT anchor = i NEW_LINE DEDENT elif i == N - 1 or c * cmp ( arr [ i ] , arr [ i + 1 ] ) != - 1 : NEW_LINE INDENT ans = max ( ans , i - anchor + 1 ) NEW_LINE anchor = i NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 9 , 4 , 2 , 10 , 7 , 8 , 8 , 1 , 9 ] NEW_LINE print ( maxSubarraySize ( arr ) ) NEW_LINE


public class GFG { static int count ( int N ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += 7 * Math . pow ( 8 , i - 1 ) ; } return sum ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( count ( N ) ) ; } }

def count ( N ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT sum += 7 * ( 8 ** ( i - 1 ) ) ; NEW_LINE DEDENT return int ( sum ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 ; NEW_LINE print ( count ( N ) ) ; NEW_LINE DEDENT


class GFG { static boolean isDivisible ( long n ) { while ( n / 100 != 0 ) { int d = ( int ) ( n % 10 ) ; n /= 10 ; n -= d * 4 ; } return ( n % 41 == 0 ) ; } public static void main ( String [ ] args ) { long n = 104413920565933L ; if ( isDivisible ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

def isDivisible ( n ) : NEW_LINE INDENT while n // 100 : NEW_LINE INDENT d = n % 10 NEW_LINE n //= 10 NEW_LINE n -= d * 4 NEW_LINE DEDENT return n % 41 == 0 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 104413920565933 NEW_LINE if isDivisible ( n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


class GfG { static boolean checkIfUnequal ( int n , int q ) { String s1 = Integer . toString ( n ) ; int a [ ] = new int [ 26 ] ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) a [ s1 . charAt ( i ) - '0' ] ++ ; int prod = n * q ; String s2 = Integer . toString ( prod ) ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) if ( a [ s2 . charAt ( i ) - '0' ] == 1 ) return false ; return true ; } static int countInRange ( int l , int r , int q ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( checkIfUnequal ( i , q ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int l = 10 , r = 12 , q = 2 ; System . out . println ( countInRange ( l , r , q ) ) ; } }

def checkIfUnequal ( n , q ) : NEW_LINE INDENT s1 = str ( n ) NEW_LINE a = [ 0 for i in range ( 26 ) ] NEW_LINE for i in range ( 0 , len ( s1 ) , 1 ) : NEW_LINE INDENT a [ ord ( s1 [ i ] ) - ord ( '0' ) ] += 1 NEW_LINE DEDENT prod = n * q NEW_LINE s2 = str ( prod ) NEW_LINE for i in range ( 0 , len ( s2 ) , 1 ) : NEW_LINE INDENT if ( a [ ord ( s2 [ i ] ) - ord ( '0' ) ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def countInRange ( l , r , q ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( l , r + 1 , 1 ) : NEW_LINE INDENT if ( checkIfUnequal ( i , q ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT l = 10 NEW_LINE r = 12 NEW_LINE q = 2 NEW_LINE print ( countInRange ( l , r , q ) ) NEW_LINE DEDENT


import java . util . Arrays ; class GFG { static boolean checkIsAP ( int arr [ ] , int n ) { if ( n == 1 ) return true ; Arrays . sort ( arr ) ; int d = arr [ 1 ] - arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 20 , 15 , 5 , 0 , 10 } ; int n = arr . length ; if ( checkIsAP ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def checkIsAP ( arr , n ) : NEW_LINE INDENT if ( n == 1 ) : return True NEW_LINE arr . sort ( ) NEW_LINE d = arr [ 1 ] - arr [ 0 ] NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i - 1 ] != d ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT arr = [ 20 , 15 , 5 , 0 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Yes " ) if ( checkIsAP ( arr , n ) ) else print ( " No " ) NEW_LINE


import java . io . * ; class GFG { static int COST = 3 ; static int maxItems ( int x , int y , int z ) { int type1 = x / COST ; x %= COST ; int type2 = y / COST ; y %= COST ; int type3 = z / COST ; z %= COST ; int type4 = Math . min ( x , Math . min ( y , z ) ) ; int maxItems = type1 + type2 + type3 + type4 ; return maxItems ; } public static void main ( String [ ] args ) { int x = 4 , y = 5 , z = 6 ; System . out . println ( maxItems ( x , y , z ) ) ; } }

COST = 3 ; NEW_LINE def maxItems ( x , y , z ) : NEW_LINE INDENT type1 = x // COST ; NEW_LINE x %= COST ; NEW_LINE type2 = y // COST ; NEW_LINE y %= COST ; NEW_LINE type3 = z // COST ; NEW_LINE z %= COST ; NEW_LINE type4 = min ( x , min ( y , z ) ) ; NEW_LINE maxItems = type1 + type2 + type3 + type4 ; NEW_LINE return maxItems ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 4 ; y = 5 ; z = 6 ; NEW_LINE print ( maxItems ( x , y , z ) ) ; NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; public class GeeksforGeeks { public static void pattern ( int n ) { for ( int i = 1 ; i <= n * 2 ; i ++ ) System . out . print ( " ▁ " ) ; System . out . print ( 0 + " \n " ) ; for ( int i = 1 ; i <= ( n * 2 ) - 1 ; i ++ ) { if ( i < n ) { for ( int j = 1 ; j <= ( n - i ) * 2 ; j ++ ) System . out . print ( " ▁ " ) ; } else { for ( int j = 1 ; j <= ( i % n ) * 2 ; j ++ ) System . out . print ( " ▁ " ) ; } if ( i < n ) { for ( int j = 0 ; j <= i % n ; j ++ ) System . out . print ( j + " ▁ " ) ; for ( int j = ( i % n ) - 1 ; j > 0 ; j -- ) System . out . print ( j + " ▁ " ) ; System . out . print ( 0 ) ; } else if ( i > n ) { for ( int j = 0 ; j <= n - ( i - n ) ; j ++ ) System . out . print ( j + " ▁ " ) ; for ( int j = ( n - ( i - n ) ) - 1 ; j > 0 ; j -- ) System . out . print ( j + " ▁ " ) ; System . out . print ( 0 ) ; } else { for ( int j = 0 ; j <= n ; j ++ ) System . out . print ( j + " ▁ " ) ; for ( int j = n - 1 ; j > 0 ; j -- ) System . out . print ( j + " ▁ " ) ; System . out . print ( 0 ) ; } System . out . print ( " \n " ) ; } for ( int i = 1 ; i <= n * 2 ; i ++ ) System . out . print ( " ▁ " ) ; System . out . print ( 0 ) ; } public static void main ( String argc [ ] ) { int n = 4 ; pattern ( n ) ; } }

def pattern ( n ) : NEW_LINE INDENT for i in range ( 1 , n * 2 + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT print ( "0" ) NEW_LINE for i in range ( 1 , n * 2 ) : NEW_LINE INDENT if ( i < n ) : NEW_LINE INDENT for j in range ( 1 , ( n - i ) * 2 + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for j in range ( 1 , ( i % n ) * 2 + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT DEDENT if ( i < n ) : NEW_LINE INDENT for j in range ( i % n + 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT for j in range ( i % n - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT DEDENT elif ( i > n ) : NEW_LINE INDENT for j in range ( n - ( i - n ) + 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT for j in range ( ( n - ( i - n ) ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for j in range ( n + 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT for j in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT for i in range ( 1 , n * 2 + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT print ( "0" , end = " " ) NEW_LINE DEDENT n = 4 ; NEW_LINE pattern ( n ) ; NEW_LINE


import java . io . * ; import java . util . * ; class stem { public static String findstem ( String arr [ ] ) { int n = arr . length ; String s = arr [ 0 ] ; int len = s . length ( ) ; String res = " " ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j <= len ; j ++ ) { String stem = s . substring ( i , j ) ; int k = 1 ; for ( k = 1 ; k < n ; k ++ ) if ( ! arr [ k ] . contains ( stem ) ) break ; if ( k == n && res . length ( ) < stem . length ( ) ) res = stem ; } } return res ; } public static void main ( String args [ ] ) { String arr [ ] = { " grace " , " graceful " , " disgraceful " , " gracefully " } ; String stems = findstem ( arr ) ; System . out . println ( stems ) ; } }

def findstem ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE s = arr [ 0 ] NEW_LINE l = len ( s ) NEW_LINE res = " " NEW_LINE for i in range ( l ) : NEW_LINE INDENT for j in range ( i + 1 , l + 1 ) : NEW_LINE INDENT stem = s [ i : j ] NEW_LINE k = 1 NEW_LINE for k in range ( 1 , n ) : NEW_LINE INDENT if stem not in arr [ k ] : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( k + 1 == n and len ( res ) < len ( stem ) ) : NEW_LINE INDENT res = stem NEW_LINE DEDENT DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ " grace " , " graceful " , " disgraceful " , " gracefully " ] NEW_LINE stems = findstem ( arr ) NEW_LINE print ( stems ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static void printDistSum ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; boolean [ ] [ ] dp = new boolean [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= n ; i ++ ) { dp [ i ] [ arr [ i - 1 ] ] = true ; for ( int j = 1 ; j <= sum ; j ++ ) { if ( dp [ i - 1 ] [ j ] == true ) { dp [ i ] [ j ] = true ; dp [ i ] [ j + arr [ i - 1 ] ] = true ; } } } for ( int j = 0 ; j <= sum ; j ++ ) if ( dp [ n ] [ j ] == true ) System . out . print ( j + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int n = arr . length ; printDistSum ( arr , n ) ; } }

def printDistSum ( arr , n ) : NEW_LINE INDENT Sum = sum ( arr ) NEW_LINE dp = [ [ False for i in range ( Sum + 1 ) ] for i in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = True NEW_LINE DEDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT dp [ i ] [ arr [ i - 1 ] ] = True NEW_LINE for j in range ( 1 , Sum + 1 ) : NEW_LINE INDENT if ( dp [ i - 1 ] [ j ] == True ) : NEW_LINE INDENT dp [ i ] [ j ] = True NEW_LINE dp [ i ] [ j + arr [ i - 1 ] ] = True NEW_LINE DEDENT DEDENT DEDENT for j in range ( Sum + 1 ) : NEW_LINE INDENT if ( dp [ n ] [ j ] == True ) : NEW_LINE INDENT print ( j , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE printDistSum ( arr , n ) NEW_LINE