import java . io . * ; class GFG { static int N = 4 ; static boolean isDiagonalMatrix ( int mat [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( ( i != j ) && ( mat [ i ] [ j ] != 0 ) ) return false ; return true ; } public static void main ( String args [ ] ) { int mat [ ] [ ] = { { 4 , 0 , 0 , 0 } , { 0 , 7 , 0 , 0 } , { 0 , 0 , 5 , 0 } , { 0 , 0 , 0 , 1 } } ; if ( isDiagonalMatrix ( mat ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

N = 4 NEW_LINE def isDiagonalMatrix ( mat ) : NEW_LINE INDENT for i in range ( 0 , N ) : NEW_LINE INDENT for j in range ( 0 , N ) : NEW_LINE INDENT if ( ( i != j ) and ( mat [ i ] [ j ] != 0 ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT mat = [ [ 4 , 0 , 0 , 0 ] , [ 0 , 7 , 0 , 0 ] , [ 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 1 ] ] NEW_LINE if ( isDiagonalMatrix ( mat ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


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

def summPairs ( arr , n ) : NEW_LINE INDENT summ = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT summ += ( arr [ i ] + arr [ j ] ) NEW_LINE DEDENT DEDENT return summ NEW_LINE DEDENT arr = [ 1 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( summPairs ( arr , n ) ) NEW_LINE


N = 4 NEW_LINE def add ( A , B , C ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ] NEW_LINE DEDENT DEDENT DEDENT A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] NEW_LINE B = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ] NEW_LINE C = A [ : ] [ : ] NEW_LINE add ( A , B , C ) NEW_LINE print ( " Result ▁ matrix ▁ is " ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT print ( C [ i ] [ j ] , " ▁ " , end = ' ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT


class GFG { static int modInverse ( int a , int m ) { int m0 = m ; int y = 0 , x = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { int q = a / m ; int t = m ; m = a % m ; a = t ; t = y ; y = x - q * y ; x = t ; } if ( x < 0 ) x += m0 ; return x ; } public static void main ( String args [ ] ) { int a = 3 , m = 11 ; System . out . println ( " Modular ▁ multiplicative ▁ " + " inverse ▁ is ▁ " + modInverse ( a , m ) ) ; } }

def modInverse ( a , m ) : NEW_LINE INDENT m0 = m NEW_LINE y = 0 NEW_LINE x = 1 NEW_LINE if ( m == 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT while ( a > 1 ) : NEW_LINE INDENT q = a // m NEW_LINE t = m NEW_LINE m = a % m NEW_LINE a = t NEW_LINE t = y NEW_LINE y = x - q * y NEW_LINE x = t NEW_LINE DEDENT if ( x < 0 ) : NEW_LINE INDENT x = x + m0 NEW_LINE DEDENT return x NEW_LINE DEDENT a = 3 NEW_LINE m = 11 NEW_LINE print ( " Modular ▁ multiplicative ▁ inverse ▁ is " , modInverse ( a , m ) ) NEW_LINE


import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static void findNthTerm ( int n ) { if ( n % 2 == 0 ) { n = n / 2 ; System . out . print ( Math . pow ( 3 , n - 1 ) + " \n " ) ; } else { n = ( n / 2 ) + 1 ; System . out . print ( Math . pow ( 2 , n - 1 ) + " \n " ) ; } } public static void main ( String [ ] args ) { int N = 4 ; findNthTerm ( N ) ; N = 11 ; findNthTerm ( N ) ; } }

def findNthTerm ( n ) : NEW_LINE INDENT if n % 2 == 0 : NEW_LINE INDENT n //= 2 NEW_LINE print ( 3 ** ( n - 1 ) ) NEW_LINE DEDENT else : NEW_LINE INDENT n = ( n // 2 ) + 1 NEW_LINE print ( 2 ** ( n - 1 ) ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 4 NEW_LINE findNthTerm ( N ) NEW_LINE N = 11 NEW_LINE findNthTerm ( N ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean topsyTurvy ( char [ ] str ) { for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == '2' || str [ i ] == '4' || str [ i ] == '5' || str [ i ] == '6' || str [ i ] == '7' || str [ i ] == '9' ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str = "1234" ; if ( topsyTurvy ( str . toCharArray ( ) ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def topsyTurvy ( string ) : NEW_LINE INDENT for i in range ( len ( string ) ) : NEW_LINE INDENT if ( string [ i ] == '2' or string [ i ] == '4' or string [ i ] == '5' or string [ i ] == '6' or string [ i ] == '7' or string [ i ] == '9' ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = "1234" ; NEW_LINE if ( topsyTurvy ( string ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT


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

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


class GFG { static boolean isPower ( int n ) { for ( int x = 2 ; x <= ( int ) Math . sqrt ( n ) ; x ++ ) { float f = ( float ) Math . log ( n ) / ( float ) Math . log ( x ) ; if ( ( f - ( int ) f ) == 0.0 ) return true ; } return false ; } public static void main ( String args [ ] ) { for ( int i = 2 ; i < 100 ; i ++ ) if ( isPower ( i ) ) System . out . print ( i + " ▁ " ) ; } }

import math NEW_LINE def isPower ( n ) : NEW_LINE INDENT for x in range ( 2 , int ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT f = math . log ( n ) / math . log ( x ) ; NEW_LINE if ( ( f - int ( f ) ) == 0.0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT for i in range ( 2 , 100 ) : NEW_LINE INDENT if ( isPower ( i ) ) : NEW_LINE INDENT print ( i , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT


class GFG { static int max_sum ( int a [ ] , int n ) { int [ ] dp = new int [ n ] ; if ( n == 1 ) { dp [ 0 ] = Math . max ( 0 , a [ 0 ] ) ; } else if ( n == 2 ) { dp [ 0 ] = Math . max ( 0 , a [ 0 ] ) ; dp [ 1 ] = Math . max ( a [ 1 ] , dp [ 0 ] ) ; } else if ( n >= 3 ) { dp [ 0 ] = Math . max ( 0 , a [ 0 ] ) ; dp [ 1 ] = Math . max ( a [ 1 ] , Math . max ( 0 , a [ 0 ] ) ) ; dp [ 2 ] = Math . max ( a [ 2 ] , Math . max ( a [ 1 ] , Math . max ( 0 , a [ 0 ] ) ) ) ; int i = 3 ; while ( i < n ) { dp [ i ] = Math . max ( dp [ i - 1 ] , a [ i ] + dp [ i - 3 ] ) ; i ++ ; } } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , - 2 , 4 , 3 } ; int n = arr . length ; System . out . println ( max_sum ( arr , n ) ) ; } }

def max_sum ( a , n ) : NEW_LINE INDENT dp = [ 0 ] * n ; NEW_LINE if ( n == 1 ) : NEW_LINE INDENT dp [ 0 ] = max ( 0 , a [ 0 ] ) ; NEW_LINE DEDENT elif ( n == 2 ) : NEW_LINE INDENT dp [ 0 ] = max ( 0 , a [ 0 ] ) ; NEW_LINE dp [ 1 ] = max ( a [ 1 ] , dp [ 0 ] ) ; NEW_LINE DEDENT elif ( n >= 3 ) : NEW_LINE INDENT dp [ 0 ] = max ( 0 , a [ 0 ] ) ; NEW_LINE dp [ 1 ] = max ( a [ 1 ] , max ( 0 , a [ 0 ] ) ) ; NEW_LINE dp [ 2 ] = max ( a [ 2 ] , max ( a [ 1 ] , max ( 0 , a [ 0 ] ) ) ) ; NEW_LINE i = 3 ; NEW_LINE while ( i < n ) : NEW_LINE INDENT dp [ i ] = max ( dp [ i - 1 ] , a [ i ] + dp [ i - 3 ] ) ; NEW_LINE i += 1 ; NEW_LINE DEDENT DEDENT return dp [ n - 1 ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , - 2 , 4 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( max_sum ( arr , n ) ) ; NEW_LINE DEDENT


class GFG { static int minOperations ( int N ) { double x = Math . log ( N ) / Math . log ( 2 ) ; int ans = ( int ) ( Math . ceil ( x ) ) ; return ans ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . println ( minOperations ( N ) ) ; } }

from math import log2 , ceil NEW_LINE def minOperations ( N ) : NEW_LINE INDENT x = log2 ( N ) NEW_LINE ans = ceil ( x ) NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 10 NEW_LINE print ( minOperations ( N ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int maxArea ( float perimeter ) { int length = ( int ) Math . ceil ( perimeter / 4 ) ; int breadth = ( int ) Math . floor ( perimeter / 4 ) ; return length * breadth ; } public static void main ( String [ ] args ) { float n = 38 ; System . out . println ( " Maximum ▁ Area ▁ = ▁ " + maxArea ( n ) ) ; } }

from math import ceil , floor NEW_LINE def maxArea ( perimeter ) : NEW_LINE INDENT length = int ( ceil ( perimeter / 4 ) ) NEW_LINE breadth = int ( floor ( perimeter / 4 ) ) NEW_LINE return length * breadth NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 38 NEW_LINE print ( " Maximum ▁ Area ▁ = " , maxArea ( n ) ) NEW_LINE DEDENT


public class GFG { static boolean checkEquality ( String s ) { return ( s . charAt ( 0 ) == s . charAt ( s . length ( ) - 1 ) ) ; } static int countSubstringWithEqualEnds ( String s ) { int result = 0 ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int len = 1 ; len <= n - i ; len ++ ) if ( checkEquality ( s . substring ( i , i + len ) ) ) result ++ ; return result ; } public static void main ( String args [ ] ) { String s = " abcab " ; System . out . println ( countSubstringWithEqualEnds ( s ) ) ; } }

def checkEquality ( s ) : NEW_LINE INDENT return ( ord ( s [ 0 ] ) == ord ( s [ len ( s ) - 1 ] ) ) ; NEW_LINE DEDENT def countSubstringWithEqualEnds ( s ) : NEW_LINE INDENT result = 0 ; NEW_LINE n = len ( s ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( 1 , n - i + 1 ) : NEW_LINE INDENT if ( checkEquality ( s [ i : i + j ] ) ) : NEW_LINE INDENT result += 1 ; NEW_LINE DEDENT DEDENT DEDENT return result ; NEW_LINE DEDENT s = " abcab " ; NEW_LINE print ( countSubstringWithEqualEnds ( s ) ) ; NEW_LINE


import java . util . * ; class GFG { static boolean isPalindrome ( String str , int low , int high ) { while ( low < high ) { if ( str . charAt ( low ) != str . charAt ( high ) ) return false ; low ++ ; high -- ; } return true ; } static int possiblePalinByRemovingOneChar ( String str ) { int low = 0 , high = str . length ( ) - 1 ; while ( low < high ) { if ( str . charAt ( low ) == str . charAt ( high ) ) { low ++ ; high -- ; } else { if ( isPalindrome ( str , low + 1 , high ) ) return low ; if ( isPalindrome ( str , low , high - 1 ) ) return high ; return - 1 ; } } return - 2 ; } public static void main ( String [ ] args ) { String str = " abecbea " ; int idx = possiblePalinByRemovingOneChar ( str ) ; if ( idx == - 1 ) System . out . println ( " Not ▁ Possible " ) ; else if ( idx == - 2 ) System . out . println ( " Possible ▁ without ▁ " + " removing ▁ any ▁ character " ) ; else System . out . println ( " Possible ▁ by ▁ removing " + " ▁ character ▁ at ▁ index ▁ " + idx ) ; } }

def isPalindrome ( string : str , low : int , high : int ) -> bool : NEW_LINE INDENT while low < high : NEW_LINE INDENT if string [ low ] != string [ high ] : NEW_LINE INDENT return False NEW_LINE DEDENT low += 1 NEW_LINE high -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def possiblepalinByRemovingOneChar ( string : str ) -> int : NEW_LINE INDENT low = 0 NEW_LINE high = len ( string ) - 1 NEW_LINE while low < high : NEW_LINE INDENT if string [ low ] == string [ high ] : NEW_LINE INDENT low += 1 NEW_LINE high -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT if isPalindrome ( string , low + 1 , high ) : NEW_LINE INDENT return low NEW_LINE DEDENT if isPalindrome ( string , low , high - 1 ) : NEW_LINE INDENT return high NEW_LINE DEDENT return - 1 NEW_LINE DEDENT DEDENT return - 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " abecbea " NEW_LINE idx = possiblepalinByRemovingOneChar ( string ) NEW_LINE if idx == - 1 : NEW_LINE INDENT print ( " Not ▁ possible " ) NEW_LINE DEDENT elif idx == - 2 : NEW_LINE INDENT print ( " Possible ▁ without ▁ removig ▁ any ▁ character " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Possible ▁ by ▁ removing ▁ character ▁ at ▁ index " , idx ) NEW_LINE DEDENT DEDENT


class Node { int data ; Node left , right ; public Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; int getLevelUtil ( Node node , int data , int level ) { if ( node == null ) return 0 ; if ( node . data == data ) return level ; int downlevel = getLevelUtil ( node . left , data , level + 1 ) ; if ( downlevel != 0 ) return downlevel ; downlevel = getLevelUtil ( node . right , data , level + 1 ) ; return downlevel ; } int getLevel ( Node node , int data ) { return getLevelUtil ( node , data , 1 ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 3 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 5 ) ; tree . root . left . left = new Node ( 1 ) ; tree . root . left . right = new Node ( 4 ) ; for ( int x = 1 ; x <= 5 ; x ++ ) { int level = tree . getLevel ( tree . root , x ) ; if ( level != 0 ) System . out . println ( " Level ▁ of ▁ " + x + " ▁ is ▁ " + tree . getLevel ( tree . root , x ) ) ; else System . out . println ( x + " ▁ is ▁ not ▁ present ▁ in ▁ tree " ) ; } } }

class newNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def getLevelUtil ( node , data , level ) : NEW_LINE INDENT if ( node == None ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( node . data == data ) : NEW_LINE INDENT return level NEW_LINE DEDENT downlevel = getLevelUtil ( node . left , data , level + 1 ) NEW_LINE if ( downlevel != 0 ) : NEW_LINE INDENT return downlevel NEW_LINE DEDENT downlevel = getLevelUtil ( node . right , data , level + 1 ) NEW_LINE return downlevel NEW_LINE DEDENT def getLevel ( node , data ) : NEW_LINE INDENT return getLevelUtil ( node , data , 1 ) NEW_LINE 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 . left . left = newNode ( 1 ) NEW_LINE root . left . right = newNode ( 4 ) NEW_LINE for x in range ( 1 , 6 ) : NEW_LINE INDENT level = getLevel ( root , x ) NEW_LINE if ( level ) : NEW_LINE INDENT print ( " Level ▁ of " , x , " is " , getLevel ( root , x ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( x , " is ▁ not ▁ present ▁ in ▁ tree " ) NEW_LINE DEDENT DEDENT DEDENT


import java . io . * ; class GFG { static int __gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return __gcd ( a - b , b ) ; return __gcd ( a , b - a ) ; } static int MinSum ( int [ ] a , int n ) { int gcd = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) gcd = __gcd ( a [ i ] , gcd ) ; return n * gcd ; } public static void main ( String [ ] args ) { int a [ ] = { 20 , 14 , 6 , 8 , 15 } ; int n = a . length ; System . out . println ( MinSum ( a , n ) ) ; } }

import math NEW_LINE def MinSum ( a , n ) : NEW_LINE INDENT gcd = a [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT gcd = math . gcd ( a [ i ] , gcd ) NEW_LINE DEDENT return n * gcd NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 20 , 14 , 6 , 8 , 15 ] NEW_LINE n = len ( a ) NEW_LINE print ( MinSum ( a , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void findMajority ( int arr [ ] , int n ) { int maxCount = 0 ; int index = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ i ] == arr [ j ] ) count ++ ; } if ( count > maxCount ) { maxCount = count ; index = i ; } } if ( maxCount > n / 2 ) System . out . println ( arr [ index ] ) ; else System . out . println ( " No ▁ Majority ▁ Element " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 1 , 3 , 5 , 1 } ; int n = arr . length ; findMajority ( arr , n ) ; } }

def findMajority ( arr , n ) : NEW_LINE INDENT maxCount = 0 ; NEW_LINE index = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( arr [ i ] == arr [ j ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT if ( count > maxCount ) : NEW_LINE INDENT maxCount = count NEW_LINE index = i NEW_LINE DEDENT DEDENT if ( maxCount > n // 2 ) : NEW_LINE INDENT print ( arr [ index ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No ▁ Majority ▁ Element " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE findMajority ( arr , n ) NEW_LINE DEDENT


import java . util . * ; public class obstacle { static int avoidObstacles ( int [ ] obs ) { HashSet < Integer > hs = new HashSet < Integer > ( ) ; int max = obs [ 0 ] ; for ( int i = 0 ; i < obs . length ; i ++ ) { hs . add ( obs [ i ] ) ; max = Math . max ( max , obs [ i ] ) ; } for ( int i = 1 ; i <= max ; i ++ ) { int j ; for ( j = i ; j <= max ; j = j + i ) { if ( hs . contains ( j ) ) break ; } if ( j > max ) return i ; } return max + 1 ; } public static void main ( String [ ] args ) { int a [ ] = new int [ ] { 5 , 3 , 6 , 7 , 9 } ; int b = avoidObstacles ( a ) ; System . out . println ( b ) ; } }

def avoidObstacles ( obs ) : NEW_LINE INDENT obs = sorted ( obs ) NEW_LINE jump_dist = 1 NEW_LINE obstacle_hit = True NEW_LINE while ( obstacle_hit ) : NEW_LINE INDENT obstacle_hit = False NEW_LINE jump_dist += 1 NEW_LINE for i in range ( 0 , len ( obs ) ) : NEW_LINE INDENT if obs [ i ] % jump_dist == 0 : NEW_LINE INDENT obstacle_hit = True NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT return jump_dist NEW_LINE DEDENT a = [ 5 , 3 , 6 , 7 , 9 ] NEW_LINE b = avoidObstacles ( a ) NEW_LINE print ( b ) NEW_LINE


import java . util . * ; class GFG { static void overflow ( int H , int r , int h , int N , int R ) { double tank_cap = 3.14 * r * r * H ; double water_vol = 3.14 * r * r * h ; double balls_vol = N * ( 4 / 3 ) * 3.14 * R * R * R ; double vol = water_vol + balls_vol ; if ( vol > tank_cap ) { System . out . println ( " Overflow " ) ; } else { System . out . println ( " Not ▁ in ▁ overflow ▁ state " ) ; } } public static void main ( String [ ] args ) { int H = 10 , r = 5 , h = 5 , N = 2 , R = 2 ; overflow ( H , r , h , N , R ) ; } }

def overflow ( H , r , h , N , R ) : NEW_LINE INDENT tank_cap = 3.14 * r * r * H NEW_LINE water_vol = 3.14 * r * r * h NEW_LINE balls_vol = N * ( 4 / 3 ) * 3.14 * R * R * R NEW_LINE vol = water_vol + balls_vol NEW_LINE if vol > tank_cap : NEW_LINE INDENT print ( " Overflow " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ in ▁ overflow ▁ state " ) NEW_LINE DEDENT DEDENT H = 10 NEW_LINE r = 5 NEW_LINE h = 5 NEW_LINE N = 2 NEW_LINE R = 2 NEW_LINE overflow ( H , r , h , N , R ) NEW_LINE


import java . util . * ; import java . io . * ; class GFG { static int minJumps ( int arr [ ] , int l , int h ) { if ( h == l ) return 0 ; if ( arr [ l ] == 0 ) return Integer . MAX_VALUE ; int min = Integer . MAX_VALUE ; for ( int i = l + 1 ; i <= h && i <= l + arr [ l ] ; i ++ ) { int jumps = minJumps ( arr , i , h ) ; if ( jumps != Integer . MAX_VALUE && jumps + 1 < min ) min = jumps + 1 ; } return min ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 } ; int n = arr . length ; System . out . print ( " Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach ▁ end ▁ is ▁ " + minJumps ( arr , 0 , n - 1 ) ) ; } }

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


class GFG { static int sum ( int k , int n ) { int sum = ( int ) ( Math . pow ( k , n + 1 ) - Math . pow ( k - 1 , n + 1 ) ) ; return sum ; } public static void main ( String args [ ] ) { int n = 3 ; int K = 3 ; System . out . print ( sum ( K , n ) ) ; } }

def sum ( k , n ) : NEW_LINE INDENT sum = ( pow ( k , n + 1 ) - pow ( k - 1 , n + 1 ) ) ; NEW_LINE return sum ; NEW_LINE DEDENT n = 3 ; NEW_LINE K = 3 ; NEW_LINE print ( sum ( K , n ) ) ; NEW_LINE


import java . util . * ; class GFG { static SortedSet < Integer > t = new TreeSet < Integer > ( ) ; static void performQueryOne ( int num ) { t . add ( num ) ; } static void performQueryTwo ( int num ) { t . remove ( num ) ; } static int performQueryThree ( ) { int mini = t . first ( ) ; int maxi = t . last ( ) ; return maxi - mini ; } public static void main ( String [ ] args ) { int num = 3 ; performQueryOne ( num ) ; num = 5 ; performQueryOne ( num ) ; num = 6 ; performQueryOne ( num ) ; num = 5 ; performQueryTwo ( num ) ; num = 2 ; performQueryOne ( num ) ; System . out . println ( performQueryThree ( ) ) ; } }

def performQueryOne ( num ) : NEW_LINE INDENT s . add ( num ) NEW_LINE DEDENT def performQueryTwo ( num ) : NEW_LINE INDENT s . remove ( num ) NEW_LINE DEDENT def performQueryThree ( ) : NEW_LINE INDENT mini = min ( s ) NEW_LINE maxi = max ( s ) NEW_LINE return maxi - mini NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = set ( ) NEW_LINE num = 3 NEW_LINE performQueryOne ( num ) NEW_LINE num = 5 NEW_LINE performQueryOne ( num ) NEW_LINE num = 6 NEW_LINE performQueryOne ( num ) NEW_LINE num = 5 NEW_LINE performQueryTwo ( num ) NEW_LINE num = 2 NEW_LINE performQueryOne ( num ) NEW_LINE print ( performQueryThree ( ) ) NEW_LINE DEDENT


import java . util . * ; class Even_odd { public static String check_last ( int arr [ ] , int n , int p ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; if ( p == 1 ) { if ( sum % 2 == 0 ) return " ODD " ; else return " EVEN " ; } return " EVEN " ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 7 , 10 } , p = 1 ; int n = 3 ; System . out . print ( check_last ( arr , n , p ) ) ; } }

def check_last ( arr , n , p ) : NEW_LINE INDENT _sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT _sum = _sum + arr [ i ] NEW_LINE DEDENT if p == 1 : NEW_LINE INDENT if _sum % 2 == 0 : NEW_LINE INDENT return " ODD " NEW_LINE DEDENT else : NEW_LINE INDENT return " EVEN " NEW_LINE DEDENT DEDENT return " EVEN " NEW_LINE DEDENT arr = [ 5 , 7 , 10 ] NEW_LINE p = 1 NEW_LINE n = len ( arr ) NEW_LINE print ( check_last ( arr , n , p ) ) NEW_LINE


import java . util . * ; class GFG { static int findlargestAfterDel ( int arr [ ] , int m , int del [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . containsKey ( del [ i ] ) ) { mp . put ( del [ i ] , mp . get ( del [ i ] ) + 1 ) ; } else { mp . put ( del [ i ] , 1 ) ; } } int largestElement = Integer . MIN_VALUE ; for ( int i = 0 ; i < m ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) - 1 ) ; if ( mp . get ( arr [ i ] ) == 0 ) mp . remove ( arr [ i ] ) ; } else largestElement = Math . max ( largestElement , arr [ i ] ) ; } return largestElement ; } public static void main ( String [ ] args ) { int array [ ] = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = array . length ; int del [ ] = { 12 , 33 , 56 , 5 } ; int n = del . length ; System . out . println ( findlargestAfterDel ( array , m , del , n ) ) ; } }

import math as mt NEW_LINE def findlargestAfterDel ( arr , m , dell , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if dell [ i ] in mp . keys ( ) : NEW_LINE INDENT mp [ dell [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ dell [ i ] ] = 1 NEW_LINE DEDENT DEDENT largestElement = - 10 ** 9 NEW_LINE for i in range ( m ) : NEW_LINE INDENT if ( arr [ i ] in mp . keys ( ) ) : NEW_LINE INDENT mp [ arr [ i ] ] -= 1 NEW_LINE if ( mp [ arr [ i ] ] == 0 ) : NEW_LINE INDENT mp . pop ( arr [ i ] ) NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT largestElement = max ( largestElement , arr [ i ] ) NEW_LINE DEDENT DEDENT return largestElement NEW_LINE DEDENT array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ] NEW_LINE m = len ( array ) NEW_LINE dell = [ 12 , 33 , 56 , 5 ] NEW_LINE n = len ( dell ) NEW_LINE print ( findlargestAfterDel ( array , m , dell , n ) ) NEW_LINE


import static java . lang . Math . sqrt ; public class Primmefunc { public static void prime ( long n ) { int flag = 0 ; if ( ( n + 1 ) % 6 != 0 && ( n - 1 ) % 6 != 0 ) { System . out . println ( " Not ▁ Prime " ) ; } else { double s = sqrt ( n ) ; if ( ( s * s ) == n ) { System . out . println ( " Semi - Prime " ) ; } else { long f = ( long ) s ; long l = ( long ) ( ( f * f ) ) ; for ( long i = f + 1 ; i < l ; i ++ ) { long p = i - ( long ) ( sqrt ( ( i * i ) - ( n ) ) ) ; long q = n / p ; if ( p < 2 || q < 2 ) { break ; } if ( ( p * q ) == n ) { flag = 1 ; break ; } else { flag = 2 ; } } if ( flag == 1 ) { System . out . println ( " Semi - Prime " ) ; } else if ( flag == 2 ) { System . out . println ( " Prime " ) ; } } } } public static void main ( String [ ] args ) { prime ( 8179 ) ; prime ( 7894561 ) ; prime ( 90000000 ) ; prime ( 841 ) ; prime ( 22553 ) ; prime ( 1187 ) ; } }

def prime ( n ) : NEW_LINE INDENT flag = 0 ; NEW_LINE if ( ( n + 1 ) % 6 != 0 and ( n - 1 ) % 6 != 0 ) : NEW_LINE INDENT print ( " Not ▁ Prime " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT s = pow ( n , 1 / 2 ) ; NEW_LINE if ( ( s * s ) == n ) : NEW_LINE INDENT print ( " Semi - Prime " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT f = int ( s ) ; NEW_LINE l = int ( f * f ) ; NEW_LINE for i in range ( f + 1 , l ) : NEW_LINE INDENT p = i - ( pow ( ( ( i * i ) - ( n ) ) , 1 / 2 ) ) ; NEW_LINE q = n // p ; NEW_LINE if ( p < 2 or q < 2 ) : NEW_LINE INDENT break ; NEW_LINE DEDENT if ( ( p * q ) == n ) : NEW_LINE INDENT flag = 1 ; NEW_LINE break ; NEW_LINE DEDENT else : NEW_LINE INDENT flag = 2 ; NEW_LINE DEDENT DEDENT if ( flag == 1 ) : NEW_LINE INDENT print ( " Semi - Prime " ) ; NEW_LINE DEDENT elif ( flag == 2 ) : NEW_LINE INDENT print ( " Prime " ) ; NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT prime ( 8179 ) ; NEW_LINE prime ( 7894561 ) ; NEW_LINE prime ( 90000000 ) ; NEW_LINE prime ( 841 ) ; NEW_LINE prime ( 22553 ) ; NEW_LINE prime ( 1187 ) ; NEW_LINE DEDENT


class GFG { static final int N = 2 ; static Boolean isVowel ( char ch ) { return ( ch == ' a ' || ch == ' e ' || ch == ' i ' || ch == ' o ' || ch == ' u ' ) ; } static void performQueries ( String str , int len , int queries [ ] [ ] , int q ) { int [ ] pre = new int [ len ] ; if ( isVowel ( str . charAt ( 0 ) ) ) pre [ 0 ] = 1 ; else pre [ 0 ] = 0 ; for ( int i = 1 ; i < len ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) pre [ i ] = 1 + pre [ i - 1 ] ; else pre [ i ] = pre [ i - 1 ] ; } for ( int i = 0 ; i < q ; i ++ ) { if ( queries [ i ] [ 0 ] == 0 ) { System . out . println ( pre [ queries [ i ] [ 1 ] ] ) ; } else { System . out . println ( ( pre [ queries [ i ] [ 1 ] ] - pre [ queries [ i ] [ 0 ] - 1 ] ) ) ; } } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int len = str . length ( ) ; int queries [ ] [ ] = { { 1 , 3 } , { 2 , 4 } , { 1 , 9 } } ; int q = queries . length ; performQueries ( str , len , queries , q ) ; } }

N = 2 NEW_LINE def isVowel ( ch ) : NEW_LINE INDENT return ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) NEW_LINE DEDENT def performQueries ( str1 , len1 , queries , q ) : NEW_LINE INDENT pre = [ 0 for i in range ( len1 ) ] NEW_LINE if ( isVowel ( str1 [ 0 ] ) ) : NEW_LINE INDENT pre [ 0 ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT pre [ 0 ] = 0 NEW_LINE DEDENT for i in range ( 0 , len1 , 1 ) : NEW_LINE INDENT if ( isVowel ( str1 [ i ] ) ) : NEW_LINE INDENT pre [ i ] = 1 + pre [ i - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT pre [ i ] = pre [ i - 1 ] NEW_LINE DEDENT DEDENT for i in range ( q ) : NEW_LINE INDENT if ( queries [ i ] [ 0 ] == 0 ) : NEW_LINE INDENT print ( pre [ queries [ i ] [ 1 ] ] ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( pre [ queries [ i ] [ 1 ] ] - pre [ queries [ i ] [ 0 ] - 1 ] ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str1 = " geeksforgeeks " NEW_LINE len1 = len ( str1 ) NEW_LINE queries = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 1 , 9 ] ] NEW_LINE q = len ( queries ) NEW_LINE performQueries ( str1 , len1 , queries , q ) NEW_LINE DEDENT


class GFG { static int smallest ( int x , int y , int z ) { int c = 0 ; while ( x != 0 && y != 0 && z != 0 ) { x -- ; y -- ; z -- ; c ++ ; } return c ; } public static void main ( String [ ] args ) { int x = 12 , y = 15 , z = 5 ; System . out . printf ( " Minimum ▁ of ▁ 3" + " ▁ numbers ▁ is ▁ % d " , smallest ( x , y , z ) ) ; } }

def smallest ( x , y , z ) : NEW_LINE INDENT c = 0 NEW_LINE while ( x and y and z ) : NEW_LINE INDENT x = x - 1 NEW_LINE y = y - 1 NEW_LINE z = z - 1 NEW_LINE c = c + 1 NEW_LINE DEDENT return c NEW_LINE DEDENT x = 12 NEW_LINE y = 15 NEW_LINE z = 5 NEW_LINE print ( " Minimum ▁ of ▁ 3 ▁ numbers ▁ is " , smallest ( x , y , z ) ) NEW_LINE


import java . util . * ; class GFG { static void print_result ( int a [ ] , int n , int k , int m ) { Vector < Vector < Integer > > v = new Vector < Vector < Integer > > ( m ) ; for ( int i = 0 ; i < m ; i ++ ) v . add ( new Vector < Integer > ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { int rem = a [ i ] % m ; v . get ( rem ) . add ( a [ i ] ) ; if ( v . get ( rem ) . size ( ) == k ) { for ( int j = 0 ; j < k ; j ++ ) System . out . print ( v . get ( rem ) . get ( j ) + " ▁ " ) ; return ; } } System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 8 , 4 } ; int n = a . length ; print_result ( a , n , 2 , 3 ) ; } }

def print_result ( a , n , k , m ) : NEW_LINE INDENT v = [ [ ] for i in range ( m ) ] NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT rem = a [ i ] % m NEW_LINE v [ rem ] . append ( a [ i ] ) NEW_LINE if ( len ( v [ rem ] ) == k ) : NEW_LINE INDENT for j in range ( 0 , k ) : NEW_LINE INDENT print ( v [ rem ] [ j ] , end = " ▁ " ) NEW_LINE DEDENT return NEW_LINE DEDENT DEDENT print ( - 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 1 , 8 , 4 ] NEW_LINE n = len ( a ) NEW_LINE print_result ( a , n , 2 , 3 ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static void printMatrix ( float mat [ ] [ ] ) { for ( int i = 0 ; i < mat . length ; i ++ ) { for ( int j = 0 ; j < mat [ i ] . length ; j ++ ) System . out . print ( mat [ i ] [ j ] + " ▁ ▁ ▁ " ) ; System . out . println ( ) ; } } static void printDistribution ( float mat [ ] [ ] ) { int N = mat . length ; float [ ] [ ] tr = new float [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) tr [ i ] [ j ] = mat [ j ] [ i ] ; float [ ] [ ] symm = new float [ N ] [ N ] ; float [ ] [ ] skewsymm = new float [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { symm [ i ] [ j ] = ( mat [ i ] [ j ] + tr [ i ] [ j ] ) / 2 ; skewsymm [ i ] [ j ] = ( mat [ i ] [ j ] - tr [ i ] [ j ] ) / 2 ; } } System . out . println ( " Symmetric ▁ matrix - " ) ; printMatrix ( symm ) ; System . out . println ( " Skew ▁ Symmetric ▁ matrix - " ) ; printMatrix ( skewsymm ) ; } public static void main ( String [ ] args ) { float mat [ ] [ ] = { { 2 , - 2 , - 4 } , { - 1 , 3 , 4 } , { 1 , - 2 , - 3 } } ; printDistribution ( mat ) ; } }

N = 3 ; NEW_LINE def printMatrix ( mat ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT print ( mat [ i ] [ j ] , end = " ▁ " ) ; NEW_LINE DEDENT print ( " " ) ; NEW_LINE DEDENT DEDENT def printDistribution ( mat ) : NEW_LINE INDENT tr = [ [ 0 for x in range ( N ) ] for y in range ( N ) ] ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT tr [ i ] [ j ] = mat [ j ] [ i ] ; NEW_LINE DEDENT DEDENT symm = [ [ 0 for x in range ( N ) ] for y in range ( N ) ] ; NEW_LINE skewsymm = [ [ 0 for x in range ( N ) ] for y in range ( N ) ] ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT symm [ i ] [ j ] = ( mat [ i ] [ j ] + tr [ i ] [ j ] ) / 2 ; NEW_LINE skewsymm [ i ] [ j ] = ( mat [ i ] [ j ] - tr [ i ] [ j ] ) / 2 ; NEW_LINE DEDENT DEDENT print ( " Symmetric ▁ matrix - " ) ; NEW_LINE printMatrix ( symm ) ; NEW_LINE print ( " Skew ▁ Symmetric ▁ matrix " ) ; NEW_LINE printMatrix ( skewsymm ) ; NEW_LINE DEDENT mat = [ [ 2 , - 2 , - 4 ] , [ - 1 , 3 , 4 ] , [ 1 , - 2 , - 3 ] ] ; NEW_LINE printDistribution ( mat ) ; NEW_LINE


import java . util . * ; class GFG { static int firstNonRepeating ( int arr [ ] , int n ) { Map < Integer , Integer > m = new HashMap < > ( ) ; 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 ) return arr [ i ] ; return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 9 , 4 , 9 , 6 , 7 , 4 } ; int n = arr . length ; System . out . println ( firstNonRepeating ( arr , n ) ) ; } }

from collections import defaultdict NEW_LINE def firstNonRepeating ( arr , n ) : NEW_LINE INDENT mp = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if mp [ arr [ i ] ] == 1 : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT arr = [ 9 , 4 , 9 , 6 , 7 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( firstNonRepeating ( arr , n ) ) NEW_LINE


import java . util . * ; import java . lang . * ; class GFG { public static void main ( String args [ ] ) { float x1 = 1 , x2 = 3 , x3 = 6 ; float y1 = 2 , y2 = - 4 , y3 = - 7 ; float x = ( x1 + x2 + x3 ) / 3 ; float y = ( y1 + y2 + y3 ) / 3 ; System . out . println ( " Centroid ▁ = ▁ " + " ( " + x + " , ▁ " + y + " ) " ) ; } }

if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x1 , x2 , x3 = 1 , 3 , 6 NEW_LINE y1 , y2 , y3 = 2 , - 4 , - 7 NEW_LINE x = round ( ( x1 + x2 + x3 ) / 3 , 2 ) NEW_LINE y = round ( ( y1 + y2 + y3 ) / 3 , 2 ) NEW_LINE print ( " Centroid ▁ = " , " ( " , x , " , " , y , " ) " ) NEW_LINE DEDENT


import java . util . Arrays ; class GFG { static boolean check ( int n , int k , int [ ] a , int [ ] b ) { Arrays . sort ( a ) ; Arrays . sort ( b ) ; boolean fl = false ; int ind = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] ) { if ( fl == true ) { return false ; } fl = true ; ind = i ; } } if ( ind == - 1 | Math . abs ( a [ ind ] - b [ ind ] ) <= k ) { return true ; } return false ; } public static void main ( String [ ] args ) { int n = 2 , k = 4 ; int [ ] a = { 1 , 5 } ; int b [ ] = { 1 , 1 } ; if ( check ( n , k , a , b ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

def check ( n , k , a , b ) : NEW_LINE INDENT a . sort ( ) NEW_LINE b . sort ( ) NEW_LINE fl = False NEW_LINE ind = - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] != b [ i ] ) : NEW_LINE INDENT if ( fl == True ) : NEW_LINE INDENT return False NEW_LINE DEDENT fl = True NEW_LINE ind = i NEW_LINE DEDENT DEDENT if ( ind == - 1 or abs ( a [ ind ] - b [ ind ] ) <= k ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT n , k = 2 , 4 NEW_LINE a = [ 1 , 5 ] NEW_LINE b = [ 1 , 1 ] NEW_LINE if ( check ( n , k , a , b ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class GFG { static int power ( long x , int y , int mod ) { long res = 1 ; while ( y != 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; x = ( x * x ) % mod ; y = ( y >> 1 ) ; } return ( int ) ( res % mod ) ; } static int ncr ( int n , int r , int mod ) { long res = 1 ; for ( int i = 1 ; i <= r ; i += 1 ) { res = ( res * ( n - i + 1 ) ) % mod ; int inv = power ( i , mod - 2 , mod ) ; res = ( res * inv ) % mod ; } return ( int ) ( res % mod ) ; } static int NoOfChords ( int A ) { int mod = ( int ) ( 1e9 + 7 ) ; long ans = ncr ( 2 * A , A , mod ) ; int inv = power ( A + 1 , mod - 2 , mod ) ; ans = ( ans * inv ) % mod ; return ( int ) ( ans % mod ) ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . println ( NoOfChords ( N ) ) ; } }

def power ( x , y , mod ) : NEW_LINE INDENT res = 1 NEW_LINE while ( y ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % mod NEW_LINE DEDENT x = ( x * x ) % mod NEW_LINE y = ( y >> 1 ) NEW_LINE DEDENT return ( res % mod ) NEW_LINE DEDENT def ncr ( n , r , mod ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT res = ( res * ( n - i + 1 ) ) % mod NEW_LINE inv = power ( i , mod - 2 , mod ) NEW_LINE res = ( res * inv ) % mod NEW_LINE DEDENT return ( res % mod ) NEW_LINE DEDENT def NoOfChords ( A ) : NEW_LINE INDENT mod = 10 ** 9 + 7 NEW_LINE ans = ncr ( 2 * A , A , mod ) NEW_LINE inv = power ( A + 1 , mod - 2 , mod ) NEW_LINE ans = ( ans * inv ) % mod NEW_LINE return ( ans % mod ) NEW_LINE DEDENT N = 2 NEW_LINE print ( NoOfChords ( N ) ) NEW_LINE


class GfG { static double maxAvgSubArray ( int a [ ] , int n , int x , int y ) { int prefix [ ] = new int [ n ] ; prefix [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; double maximum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + x - 1 ; j < i + y && j < n ; j ++ ) { double sum = prefix [ j ] ; if ( i > 0 ) sum -= prefix [ i - 1 ] ; double current = sum / ( double ) ( j - i + 1 ) ; maximum = Math . max ( maximum , current ) ; } } return maximum ; } public static void main ( String [ ] args ) { int a [ ] = { 6 , 7 , 8 , 3 , 2 , 4 , 2 } ; int X = 2 , Y = 4 ; int n = a . length ; System . out . println ( maxAvgSubArray ( a , n , X , Y ) ) ; } }

def maxAvgSubArray ( a , n , x , y ) : NEW_LINE INDENT prefix = [ 0 ] * n ; NEW_LINE prefix [ 0 ] = a [ 0 ] ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; NEW_LINE DEDENT maximum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT j = i + x - 1 NEW_LINE while ( j < i + y and j < n ) : NEW_LINE INDENT sum = prefix [ j ] ; NEW_LINE if ( i > 0 ) : NEW_LINE INDENT sum -= prefix [ i - 1 ] ; NEW_LINE DEDENT current = sum / ( j - i + 1 ) ; NEW_LINE maximum = max ( maximum , current ) ; NEW_LINE j += 1 NEW_LINE DEDENT DEDENT return maximum ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 6 , 7 , 8 , 3 , 2 , 4 , 2 ] ; NEW_LINE X = 2 ; Y = 4 ; NEW_LINE n = len ( a ) ; NEW_LINE print ( maxAvgSubArray ( a , n , X , Y ) ) ; NEW_LINE DEDENT


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

def ReplaceElements ( arr , n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return NEW_LINE DEDENT prev = arr [ 0 ] NEW_LINE arr [ 0 ] = arr [ 0 ] + arr [ 1 ] NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT curr = arr [ i ] NEW_LINE arr [ i ] = prev + arr [ i + 1 ] NEW_LINE prev = curr NEW_LINE DEDENT arr [ n - 1 ] = prev + arr [ n - 1 ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE ReplaceElements ( arr , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int getSum ( int n ) { int sum ; for ( sum = 0 ; n > 0 ; sum += n % 10 , n /= 10 ) ; return sum ; } public static void main ( String [ ] args ) { int n = 687 ; System . out . println ( getSum ( n ) ) ; } }

def getSum ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT sum += int ( n % 10 ) NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 687 NEW_LINE print ( getSum ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int centereddecagonalnum ( int n ) { return ( 5 * n * n + 5 * n + 1 ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . print ( n + " th ▁ centered ▁ " + " decagonal ▁ number : ▁ " ) ; System . out . println ( centereddecagonalnum ( n ) ) ; n = 9 ; System . out . print ( n + " th ▁ centered ▁ " + " decagonal ▁ number : ▁ " ) ; System . out . println ( centereddecagonalnum ( n ) ) ; } }

def centereddecagonalnum ( n ) : NEW_LINE INDENT return ( 5 * n * n + 5 * n + 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE print ( n , " th ▁ centered ▁ decagonal ▁ " + " number ▁ : ▁ " , centereddecagonalnum ( n ) ) NEW_LINE n = 9 NEW_LINE print ( n , " th ▁ centered ▁ decagonal ▁ " + " number ▁ : ▁ " , centereddecagonalnum ( n ) ) NEW_LINE DEDENT


import java . util . * ; class Solution { static int sumOfElements ( int arr [ ] , int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; int i , j ; HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( m . get ( arr [ i ] ) == null ) m . put ( arr [ i ] , 1 ) ; else m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } int sum = 0 ; Iterator hmIterator = m . entrySet ( ) . iterator ( ) ; while ( hmIterator . hasNext ( ) ) { Map . Entry mapElement = ( Map . Entry ) hmIterator . next ( ) ; if ( ( ( int ) mapElement . getValue ( ) ) >= ( ( int ) mapElement . getKey ( ) ) ) { sum += ( ( int ) mapElement . getKey ( ) ) ; } } return sum ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 3 , 2 , 3 , 3 } ; int n = arr . length ; System . out . println ( sumOfElements ( arr , n ) ) ; } }

def sumOfElements ( arr , n ) : NEW_LINE INDENT m = dict . fromkeys ( arr , 0 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ arr [ i ] ] += 1 NEW_LINE DEDENT sum = 0 NEW_LINE for key , value in m . items ( ) : NEW_LINE INDENT if value >= key : NEW_LINE INDENT sum += key NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 3 , 2 , 3 , 2 , 3 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( sumOfElements ( arr , n ) ) NEW_LINE DEDENT


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

def power ( x , y ) : NEW_LINE INDENT if ( y == 0 ) : return 1 NEW_LINE elif ( int ( y % 2 ) == 0 ) : NEW_LINE INDENT return ( power ( x , int ( y / 2 ) ) * power ( x , int ( y / 2 ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( x * power ( x , int ( y / 2 ) ) * power ( x , int ( y / 2 ) ) ) NEW_LINE DEDENT DEDENT x = 2 ; y = 3 NEW_LINE print ( power ( x , y ) ) NEW_LINE


import java . util . Arrays ; class GFG { static class Pair implements Comparable < Pair > { int first , second ; Pair ( int f , int s ) { first = f ; second = s ; } @ Override public int compareTo ( Pair o ) { if ( this . second > o . second ) return 1 ; else if ( this . second == o . second ) return 0 ; return - 1 ; } } static int prime [ ] = new int [ 100002 ] ; static void SieveOfEratosthenes ( ) { Arrays . fill ( prime , 0 ) ; prime [ 0 ] = 0 ; prime [ 1 ] = 0 ; for ( int p = 2 ; p * p <= 100001 ; p ++ ) { if ( prime [ p ] == 0 ) { prime [ p ] ++ ; for ( int i = p * p ; i <= 100001 ; i += p ) prime [ i ] ++ ; } } } static void sortArr ( int arr [ ] , int n ) { Pair v [ ] = new Pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ i ] = new Pair ( arr [ i ] , prime [ arr [ i ] ] ) ; } Arrays . sort ( v ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( v [ i ] . first + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { SieveOfEratosthenes ( ) ; int arr [ ] = { 30 , 2 , 1024 , 210 , 3 , 6 } ; int n = arr . length ; sortArr ( arr , n ) ; } }

import functools as ft NEW_LINE prime = [ 0 for i in range ( 100001 ) ] NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime [ 0 ] = 0 NEW_LINE prime [ 1 ] = 0 NEW_LINE for p in range ( 2 , 100002 ) : NEW_LINE INDENT if p * p > 100001 : NEW_LINE INDENT break NEW_LINE DEDENT if ( prime [ p ] == 0 ) : NEW_LINE INDENT prime [ p ] += 1 NEW_LINE for i in range ( 2 * p , 100001 , p ) : NEW_LINE INDENT prime [ i ] += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT def sortArr ( arr , n ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT v . append ( [ arr [ i ] , prime [ arr [ i ] ] ] ) NEW_LINE DEDENT v . sort ( key = lambda x : x [ 1 ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( v [ i ] [ 0 ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT SieveOfEratosthenes ( ) NEW_LINE arr = [ 30 , 2 , 1024 , 210 , 3 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE sortArr ( arr , n ) NEW_LINE


import java . util . * ; class GFG { static void makePermutation ( int [ ] a , int n ) { HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( a [ i ] ) ) { count . put ( a [ i ] , count . get ( a [ i ] ) + 1 ) ; } else { count . put ( a [ i ] , 1 ) ; } } int next_missing = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( a [ i ] ) && count . get ( a [ i ] ) != 1 || a [ i ] > n || a [ i ] < 1 ) { count . put ( a [ i ] , count . get ( a [ i ] ) - 1 ) ; while ( count . containsKey ( next_missing ) ) next_missing ++ ; a [ i ] = next_missing ; count . put ( next_missing , 1 ) ; } } } public static void main ( String [ ] args ) { int A [ ] = { 2 , 2 , 3 , 3 } ; int n = A . length ; makePermutation ( A , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( A [ i ] + " ▁ " ) ; } }

def makePermutation ( a , n ) : NEW_LINE INDENT count = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if count . get ( a [ i ] ) : NEW_LINE INDENT count [ a [ i ] ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count [ a [ i ] ] = 1 ; NEW_LINE DEDENT DEDENT next_missing = 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if count [ a [ i ] ] != 1 or a [ i ] > n or a [ i ] < 1 : NEW_LINE INDENT count [ a [ i ] ] -= 1 NEW_LINE while count . get ( next_missing ) : NEW_LINE INDENT next_missing += 1 NEW_LINE DEDENT a [ i ] = next_missing NEW_LINE count [ next_missing ] = 1 NEW_LINE DEDENT DEDENT DEDENT A = [ 2 , 2 , 3 , 3 ] NEW_LINE n = len ( A ) NEW_LINE makePermutation ( A , n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( A [ i ] , end = " ▁ " ) NEW_LINE DEDENT


class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static int findPrime ( int n ) { int num = n + 1 ; while ( num > 0 ) { if ( isPrime ( num ) ) return num ; num = num + 1 ; } return 0 ; } static int minNumber ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( isPrime ( sum ) ) return 0 ; int num = findPrime ( sum ) ; return num - sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 8 , 12 } ; int n = arr . length ; System . out . println ( minNumber ( arr , n ) ) ; } }

def isPrime ( n ) : NEW_LINE INDENT if n <= 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , n ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def findPrime ( n ) : NEW_LINE INDENT num = n + 1 NEW_LINE while ( num ) : NEW_LINE INDENT if isPrime ( num ) : NEW_LINE INDENT return num NEW_LINE DEDENT num += 1 NEW_LINE DEDENT return 0 NEW_LINE DEDENT def minNumber ( arr ) : NEW_LINE INDENT s = 0 NEW_LINE for i in range ( 0 , len ( arr ) ) : NEW_LINE INDENT s += arr [ i ] NEW_LINE DEDENT if isPrime ( s ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT num = findPrime ( s ) NEW_LINE return num - s NEW_LINE DEDENT arr = [ 2 , 4 , 6 , 8 , 12 ] NEW_LINE print ( minNumber ( arr ) ) NEW_LINE


class GFG { boolean isValidSubString ( String r , int K , int p ) { int c = 0 ; for ( int i = 0 ; i < r . length ( ) ; i ++ ) { if ( ( int ) r . charAt ( i ) > p ) { c ++ ; } } if ( c == K ) { return true ; } else { return false ; } } void countSubStrings ( String s , int K , int p ) { int l = s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = K ; ( i + j ) <= l ; j ++ ) { String r = s . substring ( i , ( i + j ) ) ; if ( isValidSubString ( r , K , p ) ) { count ++ ; } } } System . out . println ( count ) ; } public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; String s = " abepztydba " ; int K = 4 ; int p = 110 ; g . countSubStrings ( s , K , p ) ; } }

def isValidSubString ( r , K , p ) : NEW_LINE INDENT c = 0 NEW_LINE for i in range ( 0 , len ( r ) ) : NEW_LINE INDENT if ord ( r [ i ] ) > p : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT if c == K : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def countSubStrings ( s , K , p ) : NEW_LINE INDENT l = len ( s ) NEW_LINE count = 0 NEW_LINE for i in range ( 0 , l ) : NEW_LINE INDENT for j in range ( K , l - i + 1 ) : NEW_LINE INDENT r = s [ i : i + j ] NEW_LINE if isValidSubString ( r , K , p ) == True : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT print ( count ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " abepztydba " NEW_LINE K , p = 4 , 110 NEW_LINE countSubStrings ( s , K , p ) NEW_LINE DEDENT


class GFG { static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } static void generateArr ( int arr [ ] , int n ) { if ( n == 0 ) return ; if ( n == 1 ) { System . out . print ( arr [ 0 ] ) ; return ; } int [ ] suffixMax = new int [ n ] ; suffixMax [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffixMax [ i ] = Math . max ( arr [ i ] , suffixMax [ i + 1 ] ) ; int minSoFar = arr [ 0 ] ; arr [ 0 ] = suffixMax [ 1 ] ; for ( int i = 1 ; i < n - 1 ; i ++ ) { int temp = arr [ i ] ; arr [ i ] = Math . abs ( suffixMax [ i + 1 ] - minSoFar ) ; minSoFar = Math . min ( minSoFar , temp ) ; } arr [ n - 1 ] = minSoFar ; printArray ( arr , n ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 2 , 4 , 3 } ; int n = arr . length ; generateArr ( arr , n ) ; } }

def printArray ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def generateArr ( arr , n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( n == 1 ) : NEW_LINE INDENT print ( arr [ 0 ] ) NEW_LINE return NEW_LINE DEDENT suffixMax = [ 0 ] * n NEW_LINE suffixMax [ n - 1 ] = arr [ n - 1 ] NEW_LINE for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT suffixMax [ i ] = max ( arr [ i ] , suffixMax [ i + 1 ] ) NEW_LINE DEDENT minSoFar = arr [ 0 ] NEW_LINE arr [ 0 ] = suffixMax [ 1 ] NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE arr [ i ] = abs ( suffixMax [ i + 1 ] - minSoFar ) NEW_LINE minSoFar = min ( minSoFar , temp ) NEW_LINE DEDENT arr [ n - 1 ] = minSoFar NEW_LINE printArray ( arr , n ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 5 , 2 , 4 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE generateArr ( arr , n ) NEW_LINE DEDENT


import java . util . * ; public class GFG { public static int getSum ( int arr [ ] , int n ) { int i , sum = 0 ; Set < Integer > hashSet = new HashSet < > ( ) ; for ( i = 0 ; i < n ; i ++ ) hashSet . add ( arr [ i ] ) ; for ( i = 0 ; i < n ; i ++ ) { double sqrtCurrent = Math . sqrt ( arr [ i ] ) ; if ( Math . floor ( sqrtCurrent ) != Math . ceil ( sqrtCurrent ) ) continue ; if ( hashSet . contains ( ( int ) sqrtCurrent ) ) { sum += ( sqrtCurrent * sqrtCurrent ) ; } } return sum ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 4 , 5 , 6 , 7 , 8 , 9 , 3 } ; int n = arr . length ; System . out . println ( getSum ( arr , n ) ) ; } }

import math NEW_LINE def getSum ( arr , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE hashSet = set ( ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT hashSet . add ( arr [ i ] ) ; NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT sqrtCurrent = math . sqrt ( arr [ i ] ) ; NEW_LINE if ( math . floor ( sqrtCurrent ) != math . ceil ( sqrtCurrent ) ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT if ( int ( sqrtCurrent ) in hashSet ) : NEW_LINE INDENT sum += int ( sqrtCurrent * sqrtCurrent ) ; NEW_LINE DEDENT DEDENT return sum ; NEW_LINE DEDENT arr = [ 2 , 4 , 5 , 6 , 7 , 8 , 9 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( getSum ( arr , n ) ) ; NEW_LINE


class GFG { static void Loss ( int SP , int P ) { float loss = 0 ; loss = ( float ) ( 2 * P * P * SP ) / ( 100 * 100 - P * P ) ; System . out . println ( " Loss ▁ = ▁ " + loss ) ; } public static void main ( String [ ] args ) { int SP = 2400 , P = 30 ; Loss ( SP , P ) ; } }

def Loss ( SP , P ) : NEW_LINE INDENT loss = 0 NEW_LINE loss = ( ( 2 * P * P * SP ) / ( 100 * 100 - P * P ) ) NEW_LINE print ( " Loss ▁ = " , round ( loss , 3 ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT SP , P = 2400 , 30 NEW_LINE Loss ( SP , P ) NEW_LINE DEDENT


class Test { static int countIterations ( int arr [ ] , int n ) { boolean oneFound = false ; int res = 0 ; for ( int i = 0 ; i < n ; ) { if ( arr [ i ] == 1 ) oneFound = true ; while ( i < n && arr [ i ] == 1 ) i ++ ; int count_zero = 0 ; while ( i < n && arr [ i ] == 0 ) { count_zero ++ ; i ++ ; } if ( oneFound == false && i == n ) return - 1 ; int curr_count ; if ( i < n && oneFound == true ) { if ( ( count_zero & 1 ) == 0 ) curr_count = count_zero / 2 ; else curr_count = ( count_zero + 1 ) / 2 ; count_zero = 0 ; } else { curr_count = count_zero ; count_zero = 0 ; } res = Math . max ( res , curr_count ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 } ; System . out . println ( countIterations ( arr , arr . length ) ) ; } }

def countIterations ( arr , n ) : NEW_LINE INDENT oneFound = False ; NEW_LINE res = 0 ; NEW_LINE i = 0 ; NEW_LINE while ( i < n ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE INDENT oneFound = True ; NEW_LINE DEDENT while ( i < n and arr [ i ] == 1 ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT count_zero = 0 ; NEW_LINE while ( i < n and arr [ i ] == 0 ) : NEW_LINE INDENT count_zero += 1 ; NEW_LINE i += 1 ; NEW_LINE DEDENT if ( oneFound == False and i == n ) : NEW_LINE INDENT return - 1 ; NEW_LINE DEDENT curr_count = 0 ; NEW_LINE if ( i < n and oneFound == True ) : NEW_LINE INDENT if ( ( count_zero & 1 ) == 0 ) : NEW_LINE INDENT curr_count = count_zero // 2 ; NEW_LINE DEDENT else : NEW_LINE INDENT curr_count = ( count_zero + 1 ) // 2 ; NEW_LINE DEDENT count_zero = 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT curr_count = count_zero ; NEW_LINE count_zero = 0 ; NEW_LINE DEDENT res = max ( res , curr_count ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT arr = [ 0 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( countIterations ( arr , n ) ) ; NEW_LINE


class GFG { static int power ( int a , int b , int mod ) { int aa = 1 ; while ( b > 0 ) { if ( b % 2 == 1 ) { aa = aa * a ; aa %= mod ; } a = a * a ; a %= mod ; b /= 2 ; } return aa ; } static int product ( int A [ ] , int n ) { int N = 100010 ; int mod = 1000000007 ; int [ ] prime = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { prime [ j ] = 1 ; } prime [ 0 ] = prime [ 1 ] = 0 ; int i = 2 ; while ( i * i < N ) { if ( prime [ i ] == 1 ) for ( int j = 2 * i ; j < N ; j += i ) prime [ j ] = 0 ; i += 1 ; } int t = power ( 2 , n - 1 , mod - 1 ) ; int ans = 1 ; for ( int j = 0 ; j < n ; j ++ ) { i = A [ j ] ; if ( prime [ i ] == 1 ) { ans *= power ( i , t , mod ) ; ans %= mod ; } } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 7 } ; int n = A . length ; System . out . printf ( " % d " , product ( A , n ) ) ; } }

def product ( A ) : NEW_LINE INDENT N = 100010 NEW_LINE mod = 1000000007 NEW_LINE prime = [ 1 ] * N NEW_LINE prime [ 0 ] = prime [ 1 ] = 0 NEW_LINE i = 2 NEW_LINE while i * i < N : NEW_LINE INDENT if prime [ i ] : NEW_LINE INDENT for j in range ( i * i , N , i ) : NEW_LINE INDENT prime [ j ] = 0 NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT n = len ( A ) NEW_LINE t = pow ( 2 , n - 1 , mod - 1 ) NEW_LINE ans = 1 NEW_LINE for i in A : NEW_LINE INDENT if prime [ i ] : NEW_LINE INDENT ans *= pow ( i , t , mod ) NEW_LINE ans %= mod NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT A = [ 3 , 7 ] NEW_LINE print ( product ( A ) ) NEW_LINE


import java . io . * ; class GFG { static boolean isPowerOfFour ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ; } public static void main ( String [ ] args ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) ) System . out . println ( test_no + " ▁ is ▁ a ▁ power ▁ of ▁ 4" ) ; else System . out . println ( test_no + " ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) ; } }

def isPowerOfFour ( n ) : NEW_LINE INDENT return ( n != 0 and ( ( n & ( n - 1 ) ) == 0 ) and not ( n & 0xAAAAAAAA ) ) ; NEW_LINE DEDENT test_no = 64 ; NEW_LINE if ( isPowerOfFour ( test_no ) ) : NEW_LINE INDENT print ( test_no , " is ▁ a ▁ power ▁ of ▁ 4" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( test_no , " is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) ; NEW_LINE DEDENT


class GFG { static int GCD ( int a , int b ) { return ( b != 0 ? GCD ( b , a % b ) : a ) ; } static void ratiotang ( int r1 , int r2 ) { System . out . println ( " The ▁ ratio ▁ is ▁ " + r1 / GCD ( r1 , r2 ) + " ▁ : ▁ " + r2 / GCD ( r1 , r2 ) ) ; } public static void main ( String args [ ] ) { int r1 = 4 , r2 = 6 ; ratiotang ( r1 , r2 ) ; } }

from math import gcd NEW_LINE def ratiotang ( r1 , r2 ) : NEW_LINE INDENT print ( " The ▁ ratio ▁ is " , int ( r1 / gcd ( r1 , r2 ) ) , " : " , int ( r2 / gcd ( r1 , r2 ) ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT r1 = 4 NEW_LINE r2 = 6 NEW_LINE ratiotang ( r1 , r2 ) NEW_LINE DEDENT


import java . io . * ; class GFG { static float Calculate_GST ( float org_cost , float N_price ) { return ( ( ( N_price - org_cost ) * 100 ) / org_cost ) ; } public static void main ( String [ ] args ) { float org_cost = 100 ; float N_price = 120 ; System . out . print ( " ▁ GST ▁ = ▁ " + Calculate_GST ( org_cost , N_price ) + " % " ) ; } }

def Calculate_GST ( org_cost , N_price ) : NEW_LINE INDENT return ( ( ( N_price - org_cost ) * 100 ) / org_cost ) ; NEW_LINE DEDENT org_cost = 100 NEW_LINE N_price = 120 NEW_LINE print ( " GST ▁ = ▁ " , end = ' ' ) NEW_LINE print ( round ( Calculate_GST ( org_cost , N_price ) ) , end = ' ' ) NEW_LINE print ( " % " ) NEW_LINE


import java . io . * ; class GFG { static void bonacciseries ( int n , int m ) { int [ ] a = new int [ m ] ; a [ n - 1 ] = 1 ; for ( int i = n ; i < m ; i ++ ) for ( int j = i - n ; j < i ; j ++ ) a [ i ] += a [ j ] ; for ( int i = 0 ; i < m ; i ++ ) System . out . print ( a [ i ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int N = 5 , M = 15 ; bonacciseries ( N , M ) ; } }

def bonacciseries ( n , m ) : NEW_LINE INDENT a = [ 0 ] * m NEW_LINE a [ n - 1 ] = 1 NEW_LINE for i in range ( n , m ) : NEW_LINE INDENT for j in range ( i - n , i ) : NEW_LINE INDENT a [ i ] = a [ i ] + a [ j ] NEW_LINE DEDENT DEDENT for i in range ( 0 , m ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT N = 5 NEW_LINE M = 15 NEW_LINE bonacciseries ( N , M ) NEW_LINE


class GFG { static int countOdd ( int L , int R ) { int N = ( R - L ) / 2 ; if ( R % 2 != 0 || L % 2 != 0 ) N ++ ; return N ; } public static void main ( String [ ] args ) { int L = 3 , R = 7 ; int odds = countOdd ( L , R ) ; int evens = ( R - L + 1 ) - odds ; System . out . println ( " Count ▁ of ▁ odd ▁ numbers ▁ is ▁ " + odds ) ; System . out . println ( " Count ▁ of ▁ even ▁ numbers ▁ is ▁ " + evens ) ; } }

def countOdd ( L , R ) : NEW_LINE INDENT N = ( R - L ) // 2 NEW_LINE if ( R % 2 != 0 or L % 2 != 0 ) : NEW_LINE INDENT N += 1 NEW_LINE DEDENT return N NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT L = 3 NEW_LINE R = 7 NEW_LINE odds = countOdd ( L , R ) NEW_LINE evens = ( R - L + 1 ) - odds NEW_LINE print ( " Count ▁ of ▁ odd ▁ numbers ▁ is " , odds ) NEW_LINE print ( " Count ▁ of ▁ even ▁ numbers ▁ is " , evens ) NEW_LINE DEDENT


public class GFG { static int maxSquare ( int b , int m ) { return ( b / m - 1 ) * ( b / m ) / 2 ; } public static void main ( String args [ ] ) { int b = 10 , m = 2 ; System . out . println ( maxSquare ( b , m ) ) ; } }

def maxSquare ( b , m ) : NEW_LINE INDENT return ( b / m - 1 ) * ( b / m ) / 2 NEW_LINE DEDENT b = 10 NEW_LINE m = 2 NEW_LINE print ( int ( maxSquare ( b , m ) ) ) NEW_LINE


public class GFG { static void diagonalsMinMax ( int [ ] [ ] mat ) { int n = mat . length ; if ( n == 0 ) return ; int principalMin = mat [ 0 ] [ 0 ] , principalMax = mat [ 0 ] [ 0 ] ; int secondaryMin = mat [ n - 1 ] [ 0 ] , secondaryMax = mat [ n - 1 ] [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { if ( i == j ) { if ( mat [ i ] [ j ] < principalMin ) { principalMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > principalMax ) { principalMax = mat [ i ] [ j ] ; } } if ( ( i + j ) == ( n - 1 ) ) { if ( mat [ i ] [ j ] < secondaryMin ) { secondaryMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > secondaryMax ) { secondaryMax = mat [ i ] [ j ] ; } } } } System . out . println ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ ▁ " + principalMin ) ; System . out . println ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " + principalMax ) ; System . out . println ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " + secondaryMin ) ; System . out . println ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " + secondaryMax ) ; } static public void main ( String [ ] args ) { int [ ] [ ] matrix = { { 1 , 2 , 3 , 4 , - 10 } , { 5 , 6 , 7 , 8 , 6 } , { 1 , 2 , 11 , 3 , 4 } , { 5 , 6 , 70 , 5 , 8 } , { 4 , 9 , 7 , 1 , - 5 } } ; diagonalsMinMax ( matrix ) ; } }

def diagonalsMinMax ( mat ) : NEW_LINE INDENT n = len ( mat ) NEW_LINE if ( n == 0 ) : NEW_LINE INDENT return NEW_LINE DEDENT principalMin = mat [ 0 ] [ 0 ] NEW_LINE principalMax = mat [ 0 ] [ 0 ] NEW_LINE secondaryMin = mat [ n - 1 ] [ 0 ] NEW_LINE secondaryMax = mat [ n - 1 ] [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( 1 , n ) : NEW_LINE INDENT if ( i == j ) : NEW_LINE INDENT if ( mat [ i ] [ j ] < principalMin ) : NEW_LINE INDENT principalMin = mat [ i ] [ j ] NEW_LINE DEDENT if ( mat [ i ] [ j ] > principalMax ) : NEW_LINE INDENT principalMax = mat [ i ] [ j ] NEW_LINE DEDENT DEDENT if ( ( i + j ) == ( n - 1 ) ) : NEW_LINE INDENT if ( mat [ i ] [ j ] < secondaryMin ) : NEW_LINE INDENT secondaryMin = mat [ i ] [ j ] NEW_LINE DEDENT if ( mat [ i ] [ j ] > secondaryMax ) : NEW_LINE INDENT secondaryMax = mat [ i ] [ j ] NEW_LINE DEDENT DEDENT DEDENT DEDENT print ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ " , principalMin ) NEW_LINE print ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " , principalMax ) NEW_LINE print ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " , secondaryMin ) NEW_LINE print ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " , secondaryMax ) NEW_LINE DEDENT matrix = [ [ 1 , 2 , 3 , 4 , - 10 ] , [ 5 , 6 , 7 , 8 , 6 ] , [ 1 , 2 , 11 , 3 , 4 ] , [ 5 , 6 , 70 , 5 , 8 ] , [ 4 , 9 , 7 , 1 , - 5 ] ] NEW_LINE diagonalsMinMax ( matrix ) NEW_LINE


import java . util . * ; class GFG { static int NthSmallest ( int K ) { Queue < Integer > Q = new LinkedList < > ( ) ; int x = 0 ; for ( int i = 1 ; i < 10 ; i ++ ) Q . add ( i ) ; for ( int i = 1 ; i <= K ; i ++ ) { x = Q . peek ( ) ; Q . remove ( ) ; if ( x % 10 != 0 ) { Q . add ( x * 10 + x % 10 - 1 ) ; } Q . add ( x * 10 + x % 10 ) ; if ( x % 10 != 9 ) { Q . add ( x * 10 + x % 10 + 1 ) ; } } return x ; } public static void main ( String [ ] args ) { int N = 16 ; System . out . print ( NthSmallest ( N ) ) ; } }

def NthSmallest ( K ) : NEW_LINE INDENT Q = [ ] NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT Q . append ( i ) NEW_LINE DEDENT for i in range ( 1 , K + 1 ) : NEW_LINE INDENT x = Q [ 0 ] NEW_LINE Q . remove ( Q [ 0 ] ) NEW_LINE if ( x % 10 != 0 ) : NEW_LINE INDENT Q . append ( x * 10 + x % 10 - 1 ) NEW_LINE DEDENT Q . append ( x * 10 + x % 10 ) NEW_LINE if ( x % 10 != 9 ) : NEW_LINE INDENT Q . append ( x * 10 + x % 10 + 1 ) NEW_LINE DEDENT DEDENT return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 16 NEW_LINE print ( NthSmallest ( N ) ) NEW_LINE DEDENT


class PellNumber { public static int pell ( int n ) { if ( n <= 2 ) return n ; int a = 1 ; int b = 2 ; int c ; for ( int i = 3 ; i <= n ; i ++ ) { c = 2 * b + a ; a = b ; b = c ; } return b ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( pell ( n ) ) ; } }

def pell ( n ) : NEW_LINE INDENT if ( n <= 2 ) : NEW_LINE INDENT return n NEW_LINE DEDENT a = 1 NEW_LINE b = 2 NEW_LINE for i in range ( 3 , n + 1 ) : NEW_LINE INDENT c = 2 * b + a NEW_LINE a = b NEW_LINE b = c NEW_LINE DEDENT return b NEW_LINE DEDENT n = 4 NEW_LINE print ( pell ( n ) ) NEW_LINE


class GFG { static class pair { double first , second ; public pair ( double first , double second ) { this . first = first ; this . second = second ; } } static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) { double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ; double x = temp * a + x1 ; double y = temp * b + y1 ; return new pair ( x , y ) ; } public static void main ( String [ ] args ) { double a = - 1.0 ; double b = 1.0 ; double c = 0.0 ; double x1 = 1.0 ; double y1 = 0.0 ; pair image = mirrorImage ( a , b , c , x1 , y1 ) ; System . out . print ( " Image ▁ of ▁ point ▁ ( " + x1 + " , ▁ " + y1 + " ) ▁ " ) ; System . out . print ( " by ▁ mirror ▁ ( " + a + " ) x ▁ + ▁ ( " + b + " ) y ▁ + ▁ ( " + c + " ) ▁ = ▁ 0 , ▁ is ▁ : " ) ; System . out . println ( " ( " + image . first + " , ▁ " + image . second + " ) " ) ; } }

def mirrorImage ( a , b , c , x1 , y1 ) : NEW_LINE INDENT temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) NEW_LINE x = temp * a + x1 NEW_LINE y = temp * b + y1 NEW_LINE return ( x , y ) NEW_LINE DEDENT a = - 1.0 NEW_LINE b = 1.0 NEW_LINE c = 0.0 NEW_LINE x1 = 1.0 NEW_LINE y1 = 0.0 NEW_LINE x , y = mirrorImage ( a , b , c , x1 , y1 ) ; NEW_LINE print ( " Image ▁ of ▁ point ▁ ( " + str ( x1 ) + " , ▁ " + str ( y1 ) + " ) ▁ " ) NEW_LINE print ( " by ▁ mirror ▁ ( " + str ( a ) + " ) x ▁ + ▁ ( " + str ( b ) + " ) y ▁ + ▁ ( " + str ( c ) + " ) ▁ = ▁ 0 , ▁ is ▁ : " ) NEW_LINE print ( " ( " + str ( x ) + " , ▁ " + str ( y ) + " ) " ) NEW_LINE


class GFG { static int minAbsDiff ( int n ) { int left = 1 << ( ( int ) Math . floor ( Math . log ( n ) / Math . log ( 2 ) ) ) ; int right = left * 2 ; return Math . min ( ( n - left ) , ( right - n ) ) ; } public static void main ( String [ ] args ) { int n = 15 ; System . out . println ( minAbsDiff ( n ) ) ; } }

import math NEW_LINE def minAbsDiff ( n ) : NEW_LINE INDENT left = 1 << ( int ) ( math . floor ( math . log2 ( n ) ) ) NEW_LINE right = left * 2 NEW_LINE return min ( ( n - left ) , ( right - n ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 15 NEW_LINE print ( minAbsDiff ( n ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static int maxValue ( int a [ ] , int n ) { HashMap < Integer , Integer > first = new HashMap < > ( ) ; HashMap < Integer , Integer > last = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { first . put ( a [ i ] , 0 ) ; last . put ( a [ i ] , 0 ) ; } int [ ] pr = new int [ n ] ; pr [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { pr [ i ] = pr [ i - 1 ] + a [ i ] ; if ( Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) == 0 ) first . put ( a [ i ] , i ) ; last . put ( a [ i ] , i ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int start = Integer . parseInt ( String . valueOf ( first . get ( a [ i ] ) ) ) ; int end = Integer . parseInt ( String . valueOf ( last . get ( a [ i ] ) ) ) ; if ( start != 0 ) ans = Math . max ( ans , pr [ end ] - pr [ start - 1 ] ) ; } return ans ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 3 , 5 , 2 , 4 , 18 , 2 , 3 } ; int n = arr . length ; System . out . print ( maxValue ( arr , n ) ) ; } }

from collections import defaultdict NEW_LINE def maxValue ( a , n ) : NEW_LINE INDENT first = defaultdict ( lambda : 0 ) NEW_LINE last = defaultdict ( lambda : 0 ) NEW_LINE pr = [ None ] * n NEW_LINE pr [ 0 ] = a [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT pr [ i ] = pr [ i - 1 ] + a [ i ] NEW_LINE if first [ a [ i ] ] == 0 : NEW_LINE INDENT first [ a [ i ] ] = i NEW_LINE DEDENT last [ a [ i ] ] = i NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT start = first [ a [ i ] ] NEW_LINE end = last [ a [ i ] ] NEW_LINE ans = max ( ans , pr [ end ] - pr [ start - 1 ] ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 3 , 5 , 2 , 4 , 18 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxValue ( arr , n ) ) NEW_LINE DEDENT


public class GFG { static int countNumbers ( int n ) { int c = 0 ; int limit = ( int ) Math . sqrt ( n ) ; int prime [ ] = new int [ limit + 1 ] ; for ( int i = 1 ; i <= limit ; i ++ ) { prime [ i ] = i ; } for ( int i = 2 ; i * i <= limit ; i ++ ) { if ( prime [ i ] == i ) { for ( int j = i * i ; j <= limit ; j += i ) { if ( prime [ j ] == j ) { prime [ j ] = i ; } } } } for ( int i = 2 ; i <= limit ; i ++ ) { int p = prime [ i ] ; int q = prime [ i / prime [ i ] ] ; if ( p * q == i && q != 1 && p != q ) { c += 1 ; } else if ( prime [ i ] == i ) { if ( Math . pow ( i , 8 ) <= n ) { c += 1 ; } } } return c ; } public static void main ( String [ ] args ) { int n = 1000 ; System . out . println ( countNumbers ( n ) ) ; } }

def countNumbers ( n ) : NEW_LINE INDENT c = 0 NEW_LINE limit = int ( n ** ( 0.5 ) ) NEW_LINE prime = [ i for i in range ( limit + 1 ) ] NEW_LINE i = 2 NEW_LINE while i * i <= limit : NEW_LINE INDENT if prime [ i ] == i : NEW_LINE INDENT for j in range ( i * i , limit + 1 , i ) : NEW_LINE INDENT if prime [ j ] == j : NEW_LINE INDENT prime [ j ] = i NEW_LINE DEDENT DEDENT DEDENT i += 1 NEW_LINE DEDENT for i in range ( 2 , limit + 1 ) : NEW_LINE INDENT p = prime [ i ] NEW_LINE q = prime [ i // prime [ i ] ] NEW_LINE if p * q == i and q != 1 and p != q : NEW_LINE INDENT c += 1 NEW_LINE DEDENT elif prime [ i ] == i : NEW_LINE INDENT if i ** 8 <= n : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT DEDENT return c NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1000 NEW_LINE print ( countNumbers ( n ) ) NEW_LINE DEDENT


import java . util . * ; class solution { static void alternate ( int a , int b , int x ) { x = a + b - x ; System . out . println ( " After ▁ change " + " \n " + " ▁ x ▁ is ▁ : ▁ " + x ) ; } public static void main ( String args [ ] ) { int a = - 10 ; int b = 15 ; int x = a ; System . out . println ( " x ▁ is ▁ : ▁ " + x ) ; alternate ( a , b , x ) ; } }

def alternate ( a , b , x ) : NEW_LINE INDENT x = a + b - x NEW_LINE print ( " After ▁ change ▁ x ▁ is : " , x ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = - 10 NEW_LINE b = 15 NEW_LINE x = a NEW_LINE print ( " x ▁ is : " , x ) NEW_LINE alternate ( a , b , x ) NEW_LINE DEDENT


import java . io . * ; import java . math . * ; class GFG { static int countDivisors ( int n ) { int cnt = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) cnt ++ ; else cnt = cnt + 2 ; } } return cnt ; } public static void main ( String args [ ] ) { System . out . println ( " Total ▁ distinct ▁ " + " divisors ▁ of ▁ 100 ▁ are ▁ : ▁ " + countDivisors ( 100 ) ) ; } }

import math NEW_LINE def countDivisors ( n ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( 1 , ( int ) ( math . sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n / i == i ) : NEW_LINE INDENT cnt = cnt + 1 NEW_LINE DEDENT else : NEW_LINE INDENT cnt = cnt + 2 NEW_LINE DEDENT DEDENT DEDENT return cnt NEW_LINE DEDENT print ( " Total ▁ distinct ▁ divisors ▁ of ▁ 100 ▁ are ▁ : ▁ " , countDivisors ( 100 ) ) NEW_LINE


class GFG { private static StringBuilder charBuffer = new StringBuilder ( ) ; public static String processWords ( String input ) { String s [ ] = input . split ( " ( \s ) + " ) ; for ( String values : s ) { charBuffer . append ( values . charAt ( 0 ) ) ; } return charBuffer . toString ( ) ; } public static void main ( String [ ] args ) { String input = " geeks ▁ for ▁ geeks " ; System . out . println ( processWords ( input ) ) ; } }

charBuffer = [ ] NEW_LINE def processWords ( input ) : NEW_LINE INDENT s = input . split ( " ▁ " ) NEW_LINE for values in s : NEW_LINE INDENT charBuffer . append ( values [ 0 ] ) NEW_LINE DEDENT return charBuffer NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT input = " geeks ▁ for ▁ geeks " NEW_LINE print ( * processWords ( input ) , sep = " " ) NEW_LINE DEDENT


class GFG { static boolean isPerfectCube ( int x ) { long cr = Math . round ( Math . cbrt ( x ) ) ; return ( cr * cr * cr == x ) ; } static void checkCube ( int a , int b ) { String s1 = Integer . toString ( a ) ; String s2 = Integer . toString ( b ) ; int c = Integer . parseInt ( s1 + s2 ) ; if ( isPerfectCube ( c ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int a = 6 ; int b = 4 ; checkCube ( a , b ) ; } }

def isPerfectCube ( x ) : NEW_LINE INDENT x = abs ( x ) NEW_LINE return int ( round ( x ** ( 1. / 3 ) ) ) ** 3 == x NEW_LINE DEDENT def checkCube ( a , b ) : NEW_LINE INDENT s1 = str ( a ) NEW_LINE s2 = str ( b ) NEW_LINE c = int ( s1 + s2 ) NEW_LINE if ( isPerfectCube ( c ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 6 NEW_LINE b = 4 NEW_LINE checkCube ( a , b ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void getnumbers ( int n ) { Vector < Integer > divisor = new Vector < Integer > ( ) ; for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { divisor . add ( i ) ; n /= i ; } } if ( n != 1 ) { divisor . add ( n ) ; } int a , b , c , size ; a = b = c = 1 ; size = divisor . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { if ( a == 1 ) { a = a * divisor . get ( i ) ; } else if ( b == 1 || b == a ) { b = b * divisor . get ( i ) ; } else { c = c * divisor . get ( i ) ; } } if ( a == 1 || b == 1 || c == 1 || a == b || b == c || a == c ) { System . out . print ( " - 1" + " \n " ) ; } else { System . out . print ( a + " ▁ " + b + " ▁ " + c + " \n " ) ; } } public static void main ( String [ ] args ) { int n = 64 ; getnumbers ( n ) ; } }

def getnumbers ( n ) : NEW_LINE INDENT divisor = [ ] NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT divisor . append ( i ) NEW_LINE n //= i NEW_LINE DEDENT DEDENT if ( n != 1 ) : NEW_LINE INDENT divisor . append ( n ) NEW_LINE DEDENT a , b , c , size = 0 , 0 , 0 , 0 NEW_LINE a = b = c = 1 NEW_LINE size = len ( divisor ) NEW_LINE for i in range ( size ) : NEW_LINE INDENT if ( a == 1 ) : NEW_LINE INDENT a = a * divisor [ i ] NEW_LINE DEDENT elif ( b == 1 or b == a ) : NEW_LINE INDENT b = b * divisor [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT c = c * divisor [ i ] NEW_LINE DEDENT DEDENT if ( a == 1 or b == 1 or c == 1 or a == b or b == c or a == c ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( a , b , c ) NEW_LINE DEDENT DEDENT n = 64 NEW_LINE getnumbers ( n ) NEW_LINE


import java . io . * ; class GFG { static int GCD ( int a , int b ) { if ( b == 0 ) return a ; return GCD ( b , a % b ) ; } static int findMaxSumUtil ( int arr [ ] , int n ) { int finalGCD = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) finalGCD = GCD ( arr [ i ] , finalGCD ) ; return finalGCD ; } static int findMaxSum ( int arr [ ] , int n ) { int maxElement = findMaxSumUtil ( arr , n ) ; return ( maxElement * n ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 20 , 12 , 36 } ; int n = arr . length ; System . out . println ( findMaxSum ( arr , n ) ) ; } }

def GCD ( a , b ) : NEW_LINE INDENT if ( b == 0 ) : return a NEW_LINE return GCD ( b , a % b ) NEW_LINE DEDENT def findMaxSumUtil ( arr , n ) : NEW_LINE INDENT finalGCD = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT finalGCD = GCD ( arr [ i ] , finalGCD ) NEW_LINE DEDENT return finalGCD NEW_LINE DEDENT def findMaxSum ( arr , n ) : NEW_LINE INDENT maxElement = findMaxSumUtil ( arr , n ) NEW_LINE return ( maxElement * n ) NEW_LINE DEDENT arr = [ 8 , 20 , 12 , 36 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findMaxSum ( arr , n ) ) NEW_LINE


public class GFG { public static final int MAX = 10 ; static int minSum ( int arr [ ] , int n ) { int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } int k = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < freq [ i ] ; j ++ ) { arr [ k ++ ] = i ; } } int num1 = 0 ; int num2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) num1 = num1 * MAX + arr [ i ] ; else num2 = num2 * MAX + arr [ i ] ; } return num1 + num2 ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 8 , 4 , 5 , 2 , 3 } ; int n = arr . length ; System . out . print ( minSum ( arr , n ) ) ; } }

def minSum ( arr , n ) : NEW_LINE INDENT MAX = 10 NEW_LINE freq = [ 0 ] * MAX NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ arr [ i ] ] += 1 NEW_LINE DEDENT k = 0 NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT for j in range ( 0 , freq [ i ] ) : NEW_LINE INDENT arr [ k ] = i NEW_LINE k += 1 NEW_LINE DEDENT DEDENT num1 = 0 NEW_LINE num2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT num1 = num1 * MAX + arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT num2 = num2 * MAX + arr [ i ] NEW_LINE DEDENT DEDENT return num1 + num2 NEW_LINE DEDENT arr = [ 6 , 8 , 4 , 5 , 2 , 3 ] NEW_LINE n = len ( arr ) ; NEW_LINE print ( minSum ( arr , n ) ) NEW_LINE


import java . util . * ; import java . lang . * ; class GFG { public static boolean judgeSquareSum ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { int count = 0 ; if ( n % i == 0 ) { while ( n % i == 0 ) { count ++ ; n /= i ; } if ( i % 4 == 3 && count % 2 != 0 ) return false ; } } return n % 4 != 3 ; } public static void main ( String argc [ ] ) { int n = 17 ; if ( judgeSquareSum ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def judgeSquareSum ( n ) : NEW_LINE INDENT i = 2 ; NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT count = 0 ; NEW_LINE if ( n % i == 0 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE n = int ( n / i ) ; NEW_LINE DEDENT if ( i % 4 == 3 and count % 2 != 0 ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT i += 1 ; NEW_LINE DEDENT return n % 4 != 3 ; NEW_LINE DEDENT n = 17 ; NEW_LINE if ( judgeSquareSum ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int MAX = 100000 ; static int bitscount = 32 ; static int [ ] [ ] prefix_count = new int [ bitscount ] [ MAX ] ; static void findPrefixCount ( int arr [ ] , int n ) { for ( int i = 0 ; i < bitscount ; i ++ ) { prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( int j = 1 ; j < n ; j ++ ) { prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ; } } } static int rangeAnd ( int l , int r ) { int ans = 0 ; for ( int i = 0 ; i < bitscount ; i ++ ) { int x ; if ( l == 0 ) x = prefix_count [ i ] [ r ] ; else x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ; if ( x == r - l + 1 ) ans = ( ans | ( 1 << i ) ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 5 , 3 , 5 , 2 , 3 } ; int n = arr . length ; findPrefixCount ( arr , n ) ; int queries [ ] [ ] = { { 1 , 3 } , { 4 , 5 } } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( rangeAnd ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ; } }

import numpy as np NEW_LINE MAX = 100000 NEW_LINE bitscount = 32 NEW_LINE prefix_count = np . zeros ( ( bitscount , MAX ) ) ; NEW_LINE def findPrefixCount ( arr , n ) : NEW_LINE INDENT for i in range ( 0 , bitscount ) : NEW_LINE INDENT prefix_count [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; NEW_LINE for j in range ( 1 , n ) : NEW_LINE INDENT prefix_count [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; NEW_LINE prefix_count [ i ] [ j ] += prefix_count [ i ] [ j - 1 ] ; NEW_LINE DEDENT DEDENT DEDENT def rangeOr ( l , r ) : NEW_LINE INDENT ans = 0 ; NEW_LINE for i in range ( bitscount ) : NEW_LINE INDENT x = 0 ; NEW_LINE if ( l == 0 ) : NEW_LINE INDENT x = prefix_count [ i ] [ r ] ; NEW_LINE DEDENT else : NEW_LINE INDENT x = prefix_count [ i ] [ r ] - prefix_count [ i ] [ l - 1 ] ; NEW_LINE DEDENT if ( x == r - l + 1 ) : NEW_LINE INDENT ans = ( ans | ( 1 << i ) ) ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 7 , 5 , 3 , 5 , 2 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE findPrefixCount ( arr , n ) ; NEW_LINE queries = [ [ 1 , 3 ] , [ 4 , 5 ] ] ; NEW_LINE q = len ( queries ) ; NEW_LINE for i in range ( q ) : NEW_LINE INDENT print ( rangeOr ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ; NEW_LINE DEDENT DEDENT


class GFG { static int find_leftmost_unsetbit ( int n ) { int ind = - 1 ; int i = 1 ; while ( n > 0 ) { if ( ( n % 2 ) != 1 ) { ind = i ; } i ++ ; n >>= 1 ; } return ind ; } static void perform_steps ( int n ) { int left = find_leftmost_unsetbit ( n ) ; if ( left == - 1 ) { System . out . print ( " No ▁ steps ▁ required " ) ; return ; } int step = 1 ; while ( find_leftmost_unsetbit ( n ) != - 1 ) { if ( step % 2 == 0 ) { n += 1 ; System . out . println ( " Step " + step + " : ▁ Increase ▁ by ▁ 1" ) ; } else { int m = find_leftmost_unsetbit ( n ) ; int num = ( int ) ( Math . pow ( 2 , m ) - 1 ) ; n = n ^ num ; System . out . println ( " Step " + step + " : ▁ Xor ▁ with ▁ " + num ) ; } step += 1 ; } } public static void main ( String [ ] args ) { int n = 39 ; perform_steps ( n ) ; } }

def find_leftmost_unsetbit ( n ) : NEW_LINE INDENT ind = - 1 ; NEW_LINE i = 1 ; NEW_LINE while ( n ) : NEW_LINE INDENT if ( ( n % 2 ) != 1 ) : NEW_LINE INDENT ind = i ; NEW_LINE DEDENT i += 1 ; NEW_LINE n >>= 1 ; NEW_LINE DEDENT return ind ; NEW_LINE DEDENT def perform_steps ( n ) : NEW_LINE INDENT left = find_leftmost_unsetbit ( n ) ; NEW_LINE if ( left == - 1 ) : NEW_LINE INDENT print ( " No ▁ steps ▁ required " ) ; NEW_LINE return ; NEW_LINE DEDENT step = 1 ; NEW_LINE while ( find_leftmost_unsetbit ( n ) != - 1 ) : NEW_LINE INDENT if ( step % 2 == 0 ) : NEW_LINE INDENT n += 1 ; NEW_LINE print ( " Step " , step , " : ▁ Increase ▁ by ▁ 1 \n " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT m = find_leftmost_unsetbit ( n ) ; NEW_LINE num = ( 2 ** m ) - 1 ; NEW_LINE n = n ^ num ; NEW_LINE print ( " Step " , step , " : ▁ Xor ▁ with " , num ) ; NEW_LINE DEDENT step += 1 ; NEW_LINE DEDENT DEDENT n = 39 ; NEW_LINE perform_steps ( n ) ; NEW_LINE


public class GFG { static int findNum ( int div [ ] , int rem [ ] , int N ) { int num = rem [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; i -- ) { num = num * div [ i ] + rem [ i ] ; } return num ; } public static void main ( String [ ] args ) { int div [ ] = { 8 , 3 } ; int rem [ ] = { 2 , 2 } ; int N = div . length ; System . out . println ( findNum ( div , rem , N ) ) ; } }

def findNum ( div , rem , N ) : NEW_LINE INDENT num = rem [ N - 1 ] NEW_LINE i = N - 2 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT num = num * div [ i ] + rem [ i ] NEW_LINE i -= 1 NEW_LINE DEDENT return num NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT div = [ 8 , 3 ] NEW_LINE rem = [ 2 , 2 ] NEW_LINE N = len ( div ) NEW_LINE print ( findNum ( div , rem , N ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int summation ( int n ) { int sum = 0 , j = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { sum = sum + j ; j = ( j * 10 ) + 1 ; } return sum ; } public static void main ( String args [ ] ) { int n = 5 ; System . out . println ( summation ( n ) ) ; } }

def summation ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE j = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum = sum + j NEW_LINE j = ( j * 10 ) + 1 NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 5 NEW_LINE print ( summation ( n ) ) NEW_LINE


import java . util . * ; class Odd { public static int oddSum ( int n ) { return ( n * n ) ; } public static void main ( String [ ] args ) { int n = 20 ; System . out . println ( " ▁ Sum ▁ of ▁ first ▁ " + n + " ▁ Odd ▁ Numbers ▁ is : ▁ " + oddSum ( n ) ) ; } }

def oddSum ( n ) : NEW_LINE INDENT return ( n * n ) ; NEW_LINE DEDENT n = 20 NEW_LINE print ( " ▁ Sum ▁ of ▁ first " , n , " Odd ▁ Numbers ▁ is : ▁ " , oddSum ( n ) ) NEW_LINE


class GFG { static final long mod = 1000000007 ; static final long max = 1001 ; static long nCr [ ] [ ] = new long [ 1003 ] [ 1003 ] ; static void preComputeCoeff ( ) { for ( int i = 0 ; i < max ; i ++ ) { for ( int j = 0 ; j <= i ; j ++ ) { if ( j == 0 || j == i ) nCr [ i ] [ j ] = 1 ; else nCr [ i ] [ j ] = ( nCr [ i - 1 ] [ j - 1 ] + nCr [ i - 1 ] [ j ] ) % mod ; } } } static long computeStringCount ( int N ) { int n = N / 2 ; long ans = 0 ; for ( int i = 2 ; i <= n ; i += 2 ) ans = ( ans + ( ( nCr [ n ] [ i ] * nCr [ n ] [ i / 2 ] ) % mod ) ) % mod ; return ans ; } public static void main ( String [ ] args ) { preComputeCoeff ( ) ; int N = 3 ; System . out . println ( computeStringCount ( N ) ) ; } }

mod = 1000000007 NEW_LINE Max = 1001 NEW_LINE nCr = [ [ 0 for _ in range ( 1003 ) ] for i in range ( 1003 ) ] NEW_LINE def preComputeCoeff ( ) : NEW_LINE INDENT for i in range ( Max ) : NEW_LINE INDENT for j in range ( i + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT nCr [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT nCr [ i ] [ j ] = ( nCr [ i - 1 ] [ j - 1 ] + nCr [ i - 1 ] [ j ] ) % mod NEW_LINE DEDENT DEDENT DEDENT DEDENT def computeStringCount ( N ) : NEW_LINE INDENT n = N // 2 NEW_LINE ans = 0 NEW_LINE for i in range ( 2 , n + 1 , 2 ) : NEW_LINE INDENT ans = ( ans + ( ( nCr [ n ] [ i ] * nCr [ n ] [ i // 2 ] ) % mod ) ) % mod NEW_LINE DEDENT return ans NEW_LINE DEDENT preComputeCoeff ( ) NEW_LINE N = 3 NEW_LINE print ( computeStringCount ( N ) ) NEW_LINE


public class GFG { static int PowerOFPINnfactorial ( int n , int p ) { int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int count = 0 , temp = i ; while ( temp % p == 0 ) { count ++ ; temp = temp / p ; } ans += count ; } return ans ; } public static void main ( String [ ] args ) { System . out . println ( PowerOFPINnfactorial ( 4 , 2 ) ) ; } }

def PowerOFPINnfactorial ( n , p ) : NEW_LINE INDENT ans = 0 ; NEW_LINE temp = p ; NEW_LINE while ( temp <= n ) : NEW_LINE INDENT ans += n / temp ; NEW_LINE temp = temp * p ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT print ( PowerOFPINnfactorial ( 4 , 2 ) ) ; NEW_LINE


import java . io . * ; import java . util . * ; import java . text . * ; import java . math . * ; import java . util . regex . * ; class GFG { static void printNos ( int n ) { if ( n > 0 ) { printNos ( n - 1 ) ; System . out . print ( n + " ▁ " ) ; } return ; } public static void main ( String [ ] args ) { printNos ( 100 ) ; } }

def printNos ( n ) : NEW_LINE INDENT if n > 0 : NEW_LINE INDENT printNos ( n - 1 ) NEW_LINE print ( n , end = ' ▁ ' ) NEW_LINE DEDENT DEDENT printNos ( 100 ) NEW_LINE


import java . util . * ; class Graph { static void addEdge ( ArrayList < ArrayList < Integer > > adj , int u , int v ) { adj . get ( u ) . add ( v ) ; adj . get ( v ) . add ( u ) ; } static void printGraph ( ArrayList < ArrayList < Integer > > adj ) { for ( int i = 0 ; i < adj . size ( ) ; i ++ ) { System . out . println ( " \n Adjacency ▁ list ▁ of ▁ vertex " + i ) ; for ( int j = 0 ; j < adj . get ( i ) . size ( ) ; j ++ ) { System . out . print ( " ▁ - > ▁ " + adj . get ( i ) . get ( j ) ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int V = 5 ; ArrayList < ArrayList < Integer > > adj = new ArrayList < ArrayList < Integer > > ( V ) ; for ( int i = 0 ; i < V ; i ++ ) adj . add ( new ArrayList < Integer > ( ) ) ; addEdge ( adj , 0 , 1 ) ; addEdge ( adj , 0 , 4 ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 1 , 4 ) ; addEdge ( adj , 2 , 3 ) ; addEdge ( adj , 3 , 4 ) ; printGraph ( adj ) ; } }

class AdjNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . vertex = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT class Graph : NEW_LINE INDENT def __init__ ( self , vertices ) : NEW_LINE INDENT self . V = vertices NEW_LINE self . graph = [ None ] * self . V NEW_LINE DEDENT def add_edge ( self , src , dest ) : NEW_LINE INDENT node = AdjNode ( dest ) NEW_LINE node . next = self . graph [ src ] NEW_LINE self . graph [ src ] = node NEW_LINE node = AdjNode ( src ) NEW_LINE node . next = self . graph [ dest ] NEW_LINE self . graph [ dest ] = node NEW_LINE DEDENT def print_graph ( self ) : NEW_LINE INDENT for i in range ( self . V ) : NEW_LINE INDENT print ( " Adjacency ▁ list ▁ of ▁ vertex ▁ { } \n ▁ head " . format ( i ) , end = " " ) NEW_LINE temp = self . graph [ i ] NEW_LINE while temp : NEW_LINE INDENT print ( " ▁ - > ▁ { } " . format ( temp . vertex ) , end = " " ) NEW_LINE temp = temp . next NEW_LINE DEDENT print ( " ▁ \n " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT V = 5 NEW_LINE graph = Graph ( V ) NEW_LINE graph . add_edge ( 0 , 1 ) NEW_LINE graph . add_edge ( 0 , 4 ) NEW_LINE graph . add_edge ( 1 , 2 ) NEW_LINE graph . add_edge ( 1 , 3 ) NEW_LINE graph . add_edge ( 1 , 4 ) NEW_LINE graph . add_edge ( 2 , 3 ) NEW_LINE graph . add_edge ( 3 , 4 ) NEW_LINE graph . print_graph ( ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int center_octadecagon_num ( int n ) { return 9 * n * n - 9 * n + 1 ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( n + " th ▁ centered ▁ " + " octadecagonal ▁ number ▁ : ▁ " ) ; System . out . println ( center_octadecagon_num ( n ) ) ; n = 13 ; System . out . print ( n + " th ▁ centered ▁ " + " octadecagonal ▁ number ▁ : ▁ " ) ; System . out . println ( center_octadecagon_num ( n ) ) ; } }

def center_octadecagon_num ( n ) : NEW_LINE INDENT return ( 9 * n * n - 9 * n + 1 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( n , " rd ▁ centered ▁ octadecagonal ▁ " + " number ▁ : ▁ " , center_octadecagon_num ( n ) ) NEW_LINE n = 13 NEW_LINE print ( n , " th ▁ centered ▁ octadecagonal ▁ " + " number ▁ : ▁ " , center_octadecagon_num ( n ) ) NEW_LINE DEDENT


class GFG { static int MinOfCubedDP ( int k ) { int [ ] DP = new int [ k + 1 ] ; int j = 1 , t = 1 ; DP [ 0 ] = 0 ; for ( int i = 1 ; i <= k ; i ++ ) { DP [ i ] = Integer . MAX_VALUE ; while ( j <= i ) { if ( j == i ) DP [ i ] = 1 ; else if ( DP [ i ] > DP [ i - j ] ) DP [ i ] = DP [ i - j ] + 1 ; t ++ ; j = t * t * t ; } t = j = 1 ; } return DP [ k ] ; } public static void main ( String [ ] args ) { int num = 15 ; System . out . println ( MinOfCubedDP ( num ) ) ; } }

import sys NEW_LINE def MinOfCubedDP ( k ) : NEW_LINE INDENT DP = [ 0 ] * ( k + 1 ) ; NEW_LINE j = 1 ; NEW_LINE t = 1 ; NEW_LINE DP [ 0 ] = 0 ; NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT DP [ i ] = sys . maxsize ; NEW_LINE while ( j <= i ) : NEW_LINE INDENT if ( j == i ) : NEW_LINE INDENT DP [ i ] = 1 ; NEW_LINE DEDENT elif ( DP [ i ] > DP [ i - j ] ) : NEW_LINE INDENT DP [ i ] = DP [ i - j ] + 1 ; NEW_LINE DEDENT t += 1 ; NEW_LINE j = t * t * t ; NEW_LINE DEDENT t = j = 1 ; NEW_LINE DEDENT return DP [ k ] ; NEW_LINE DEDENT num = 15 ; NEW_LINE print ( MinOfCubedDP ( num ) ) ; NEW_LINE


public class Pyramid_Pattern { static void printPattern ( int n ) { int j , k = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( i % 2 != 0 ) { for ( j = k + 1 ; j < k + i ; j ++ ) System . out . print ( j + " * " ) ; System . out . println ( j ++ ) ; k = j ; } else { k = k + i - 1 ; for ( j = k ; j > k - i + 1 ; j -- ) System . out . print ( j + " * " ) ; System . out . println ( j ) ; } } } public static void main ( String args [ ] ) { int n = 5 ; printPattern ( n ) ; } }

def printPattern ( n ) : NEW_LINE INDENT j , k = 0 , 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if i % 2 != 0 : NEW_LINE INDENT for j in range ( k + 1 , k + i ) : NEW_LINE INDENT print ( str ( j ) + " * " , end = " " ) NEW_LINE DEDENT j = k + i NEW_LINE print ( j ) NEW_LINE j += 1 NEW_LINE k = j NEW_LINE DEDENT else : NEW_LINE INDENT k = k + i - 1 NEW_LINE for j in range ( k , k - i + 1 , - 1 ) : NEW_LINE INDENT print ( str ( j ) + " * " , end = " " ) NEW_LINE DEDENT j = k - i + 1 NEW_LINE print ( j ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE printPattern ( n ) NEW_LINE DEDENT


public class ParallelogramPoints { public static void main ( String [ ] s ) { int ax = 5 , ay = 0 ; int bx = 1 , by = 1 ; int cx = 2 , cy = 5 ; System . out . println ( ax + bx - cx + " , ▁ " + ( ay + by - cy ) ) ; System . out . println ( ax + cx - bx + " , ▁ " + ( ay + cy - by ) ) ; System . out . println ( cx + bx - ax + " , ▁ " + ( cy + by - ax ) ) ; } }

ax = 5 NEW_LINE ay = 0 NEW_LINE bx = 1 NEW_LINE by = 1 NEW_LINE cx = 2 NEW_LINE cy = 5 NEW_LINE print ( ax + bx - cx , " , ▁ " , ay + by - cy ) NEW_LINE print ( ax + cx - bx , " , ▁ " , ay + cy - by ) NEW_LINE print ( cx + bx - ax , " , ▁ " , cy + by - ax ) NEW_LINE


import java . io . * ; class GFG { float sum ( float n ) { if ( n < 2 ) return 1 ; else return 1 / n + ( sum ( n - 1 ) ) ; } public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; System . out . println ( g . sum ( 8 ) ) ; System . out . print ( g . sum ( 10 ) ) ; } }

def sum ( n ) : NEW_LINE INDENT if n < 2 : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 1 / n + ( sum ( n - 1 ) ) NEW_LINE DEDENT DEDENT print ( sum ( 8 ) ) NEW_LINE print ( sum ( 10 ) ) NEW_LINE


import java . util . * ; class GFG { static final int M = 1000000007 ; static long power ( long x , int y , int p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long modInverse ( long n , int p ) { return power ( n , p - 2 , p ) ; } static long nCrModPFermat ( long n , int r , int p ) { if ( r == 0 ) return 1 ; long fac [ ] = new long [ ( int ) n + 1 ] ; fac [ 0 ] = 1 ; int i ; for ( i = 1 ; i <= n ; i ++ ) fac [ i ] = fac [ i - 1 ] * i % p ; return ( fac [ ( int ) n ] * modInverse ( fac [ r ] , p ) % p * modInverse ( fac [ ( int ) n - r ] , p ) % p ) % p ; } static long countOdd ( long n ) { long x = n / 2 ; if ( n % 2 == 1 ) x ++ ; return x ; } static long counteEven ( long n ) { long x = n / 2 ; return x ; } static long CountEvenSumSequences ( long n ) { long count = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { int even = i , odd = ( int ) n - i ; if ( odd % 2 == 1 ) continue ; long tot = ( power ( countOdd ( n ) , odd , M ) * nCrModPFermat ( n , odd , M ) ) % M ; tot = ( tot * power ( counteEven ( n ) , i , M ) ) % M ; count += tot ; count %= M ; } return count ; } public static void main ( String [ ] args ) { long n = 5 ; System . out . println ( CountEvenSumSequences ( n ) ) ; } }

M = 1000000007 NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def modInverse ( n , p ) : NEW_LINE INDENT return power ( n , p - 2 , p ) NEW_LINE DEDENT def nCrModPFermat ( n , r , p ) : NEW_LINE INDENT if ( r == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT fac = [ 0 ] * ( n + 1 ) NEW_LINE fac [ 0 ] = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT fac [ i ] = fac [ i - 1 ] * i % p NEW_LINE DEDENT return ( fac [ n ] * modInverse ( fac [ r ] , p ) % p * modInverse ( fac [ n - r ] , p ) % p ) % p NEW_LINE DEDENT def countOdd ( n ) : NEW_LINE INDENT x = n // 2 NEW_LINE if ( n % 2 == 1 ) : NEW_LINE INDENT x += 1 NEW_LINE DEDENT return x NEW_LINE DEDENT def counteEven ( n ) : NEW_LINE INDENT x = n // 2 NEW_LINE return x NEW_LINE DEDENT def CountEvenSumSequences ( n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT even = i NEW_LINE odd = n - i NEW_LINE if ( odd % 2 == 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT tot = ( power ( countOdd ( n ) , odd , M ) * nCrModPFermat ( n , odd , M ) ) % M NEW_LINE tot = ( tot * power ( counteEven ( n ) , i , M ) ) % M NEW_LINE count += tot NEW_LINE count %= M NEW_LINE DEDENT return count NEW_LINE DEDENT n = 5 NEW_LINE print ( CountEvenSumSequences ( n ) ) NEW_LINE