import java . lang . * ; class GFG { static float findWater ( int i , int j , float X ) { if ( j > i ) { System . out . println ( " Incorrect ▁ Input " ) ; System . exit ( 0 ) ; } int ll = Math . round ( ( i * ( i + 1 ) ) ) ; float [ ] glass = new float [ ll + 2 ] ; int index = 0 ; glass [ index ] = X ; for ( int row = 1 ; row <= i ; ++ row ) { for ( int col = 1 ; col <= row ; ++ col , ++ index ) { X = glass [ index ] ; glass [ index ] = ( X >= 1.0f ) ? 1.0f : X ; X = ( X >= 1.0f ) ? ( X - 1 ) : 0.0f ; glass [ index + row ] += X / 2 ; glass [ index + row + 1 ] += X / 2 ; } } return glass [ ( int ) ( i * ( i - 1 ) / 2 + j - 1 ) ] ; } public static void main ( String [ ] args ) { int i = 2 , j = 2 ; float X = 2.0f ; System . out . println ( " Amount ▁ of ▁ water ▁ in ▁ jth ▁ " + " glass ▁ of ▁ ith ▁ row ▁ is : ▁ " + findWater ( i , j , X ) ) ; } }

def findWater ( i , j , X ) : NEW_LINE INDENT if ( j > i ) : NEW_LINE INDENT print ( " Incorrect ▁ Input " ) ; NEW_LINE return ; NEW_LINE DEDENT glass = [ 0 ] * int ( i * ( i + 1 ) / 2 ) ; NEW_LINE index = 0 ; NEW_LINE glass [ index ] = X ; NEW_LINE for row in range ( 1 , i ) : NEW_LINE INDENT for col in range ( 1 , row + 1 ) : NEW_LINE INDENT X = glass [ index ] ; NEW_LINE glass [ index ] = 1.0 if ( X >= 1.0 ) else X ; NEW_LINE X = ( X - 1 ) if ( X >= 1.0 ) else 0.0 ; NEW_LINE glass [ index + row ] += ( X / 2 ) ; NEW_LINE glass [ index + row + 1 ] += ( X / 2 ) ; NEW_LINE index += 1 ; NEW_LINE DEDENT DEDENT return glass [ int ( i * ( i - 1 ) / 2 + j - 1 ) ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT i = 2 ; NEW_LINE j = 2 ; NEW_LINE X = 2.0 ; NEW_LINE res = repr ( findWater ( i , j , X ) ) ; NEW_LINE print ( " Amount ▁ of ▁ water ▁ in ▁ jth ▁ glass ▁ of ▁ ith ▁ row ▁ is : " , res . ljust ( 8 , '0' ) ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static double cyl ( double r , double h ) { if ( r < 0 && h < 0 ) return - 1 ; double R = ( 2 * r ) / 3 ; double H = ( 2 * h ) / 3 ; double V = 3.14 * Math . pow ( R , 2 ) * H ; return V ; } public static void main ( String [ ] args ) { double r = 4 , h = 8 ; System . out . println ( cyl ( r , h ) ) ; } }

import math NEW_LINE def cyl ( r , h ) : NEW_LINE INDENT if ( r < 0 and h < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT R = ( 2 * r ) / 3 NEW_LINE H = ( 2 * h ) / 3 NEW_LINE V = 3.14 * math . pow ( R , 2 ) * H NEW_LINE return V NEW_LINE DEDENT r = 4 ; h = 8 ; NEW_LINE print ( cyl ( r , h ) , " \n " ) NEW_LINE


import java . io . * ; class GFG { static int countBits ( int n ) { int count = 0 ; while ( n > 0 ) { count ++ ; n >>= 1 ; } return count ; } public static void main ( String [ ] args ) { int n = 32 ; System . out . println ( " Minimum ▁ value ▁ of ▁ K ▁ is ▁ = ▁ " + countBits ( n ) ) ; } }

def countBits ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE while ( n ) : NEW_LINE INDENT count += 1 ; NEW_LINE n >>= 1 ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT n = 32 ; NEW_LINE print ( " Minimum ▁ value ▁ of ▁ K ▁ is ▁ = " , countBits ( n ) ) ; NEW_LINE


class GFG { static void minAdjDifference ( int arr [ ] , int n ) { if ( n < 2 ) return ; int res = Math . abs ( arr [ 1 ] - arr [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) res = Math . min ( res , Math . abs ( arr [ i ] - arr [ i - 1 ] ) ) ; res = Math . min ( res , Math . abs ( arr [ n - 1 ] - arr [ 0 ] ) ) ; System . out . print ( " Min ▁ Difference ▁ = ▁ " + res ) ; } public static void main ( String arg [ ] ) { int a [ ] = { 10 , 12 , 13 , 15 , 10 } ; int n = a . length ; minAdjDifference ( a , n ) ; } }

def minAdjDifference ( arr , n ) : NEW_LINE INDENT if ( n < 2 ) : return NEW_LINE res = abs ( arr [ 1 ] - arr [ 0 ] ) NEW_LINE for i in range ( 2 , n ) : NEW_LINE INDENT res = min ( res , abs ( arr [ i ] - arr [ i - 1 ] ) ) NEW_LINE DEDENT res = min ( res , abs ( arr [ n - 1 ] - arr [ 0 ] ) ) NEW_LINE print ( " Min ▁ Difference ▁ = ▁ " , res ) NEW_LINE DEDENT a = [ 10 , 12 , 13 , 15 , 10 ] NEW_LINE n = len ( a ) NEW_LINE minAdjDifference ( a , n ) NEW_LINE


import java . io . * ; class GFG { static int findMinCost ( int arr [ ] , int n , int choc_cost ) { int choc_buy = arr [ 0 ] ; int curr_choc = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int choc = arr [ i ] - arr [ i + 1 ] ; curr_choc += choc ; if ( curr_choc < 0 ) { choc_buy += Math . abs ( curr_choc ) ; curr_choc = 0 ; } } return choc_buy * choc_cost ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 6 , 11 , 4 , 7 , 1 } ; int n = arr . length ; int p = 5 ; System . out . println ( findMinCost ( arr , n , p ) ) ; } }

def findMinCost ( arr , n , choc_cost ) : NEW_LINE INDENT choc_buy = arr [ 0 ] NEW_LINE curr_choc = 0 NEW_LINE for i in range ( 0 , n - 1 ) : NEW_LINE INDENT choc = arr [ i ] - arr [ i + 1 ] NEW_LINE curr_choc += choc NEW_LINE if ( curr_choc < 0 ) : NEW_LINE INDENT choc_buy += abs ( curr_choc ) NEW_LINE curr_choc = 0 NEW_LINE DEDENT DEDENT return choc_buy * choc_cost NEW_LINE DEDENT arr = [ 10 , 6 , 11 , 4 , 7 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE p = 5 NEW_LINE print ( findMinCost ( arr , n , p ) ) NEW_LINE


import java . io . * ; class GFG { static int countSub ( int arr [ ] , int n ) { int count [ ] = new int [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = arr [ i ] - 1 ; j >= 0 ; j -- ) count [ arr [ i ] ] += count [ j ] ; count [ arr [ i ] ] ++ ; } int result = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) result += count [ i ] ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 5 , 4 } ; int n = arr . length ; System . out . println ( countSub ( arr , n ) ) ; } }

def countSub ( arr , n ) : NEW_LINE INDENT count = [ 0 for i in range ( 10 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( arr [ i ] - 1 , - 1 , - 1 ) : NEW_LINE INDENT count [ arr [ i ] ] += count [ j ] NEW_LINE DEDENT count [ arr [ i ] ] += 1 NEW_LINE DEDENT result = 0 NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT result += count [ i ] NEW_LINE DEDENT return result NEW_LINE DEDENT arr = [ 3 , 2 , 4 , 5 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countSub ( arr , n ) ) NEW_LINE


class GFG { static int MAX = 100 ; static void spiralFill ( int m , int n , int a [ ] [ ] ) { int val = 1 ; int k = 0 , l = 0 ; while ( k < m && l < n ) { for ( int i = l ; i < n ; ++ i ) { a [ k ] [ i ] = val ++ ; } k ++ ; for ( int i = k ; i < m ; ++ i ) { a [ i ] [ n - 1 ] = val ++ ; } n -- ; if ( k < m ) { for ( int i = n - 1 ; i >= l ; -- i ) { a [ m - 1 ] [ i ] = val ++ ; } m -- ; } if ( l < n ) { for ( int i = m - 1 ; i >= k ; -- i ) { a [ i ] [ l ] = val ++ ; } l ++ ; } } } public static void main ( String [ ] args ) { int m = 4 , n = 4 ; int a [ ] [ ] = new int [ MAX ] [ MAX ] ; spiralFill ( m , n , a ) ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { System . out . print ( a [ i ] [ j ] + " ▁ " ) ; } System . out . println ( " " ) ; } } }

def spiralFill ( m , n , a ) : NEW_LINE INDENT val = 1 NEW_LINE k , l = 0 , 0 NEW_LINE while ( k < m and l < n ) : NEW_LINE INDENT for i in range ( l , n ) : NEW_LINE INDENT a [ k ] [ i ] = val NEW_LINE val += 1 NEW_LINE DEDENT k += 1 NEW_LINE for i in range ( k , m ) : NEW_LINE INDENT a [ i ] [ n - 1 ] = val NEW_LINE val += 1 NEW_LINE DEDENT n -= 1 NEW_LINE if ( k < m ) : NEW_LINE INDENT for i in range ( n - 1 , l - 1 , - 1 ) : NEW_LINE INDENT a [ m - 1 ] [ i ] = val NEW_LINE val += 1 NEW_LINE DEDENT m -= 1 NEW_LINE DEDENT if ( l < n ) : NEW_LINE INDENT for i in range ( m - 1 , k - 1 , - 1 ) : NEW_LINE INDENT a [ i ] [ l ] = val NEW_LINE val += 1 NEW_LINE DEDENT l += 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT m , n = 4 , 4 NEW_LINE a = [ [ 0 for j in range ( m ) ] for i in range ( n ) ] NEW_LINE spiralFill ( m , n , a ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT print ( a [ i ] [ j ] , end = ' ▁ ' ) NEW_LINE DEDENT print ( ' ' ) NEW_LINE DEDENT DEDENT


class GFG { static class Node { int data ; Node next ; } ; static Node circular ( Node head ) { Node start = head ; while ( head . next != null ) head = head . next ; head . next = start ; return start ; } static Node push ( Node head , int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . next = ( head ) ; ( head ) = newNode ; return head ; } static void displayList ( Node node ) { Node start = node ; while ( node . next != start ) { System . out . print ( " ▁ " + node . data ) ; node = node . next ; } System . out . print ( " ▁ " + node . data ) ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 15 ) ; head = push ( head , 14 ) ; head = push ( head , 13 ) ; head = push ( head , 22 ) ; head = push ( head , 17 ) ; circular ( head ) ; System . out . print ( " Display ▁ list : ▁ \n " ) ; displayList ( head ) ; } }

import sys NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def push ( head , data ) : NEW_LINE INDENT if not head : NEW_LINE INDENT return Node ( data ) NEW_LINE DEDENT newNode = Node ( data ) NEW_LINE newNode . next = head NEW_LINE head = newNode NEW_LINE return head NEW_LINE DEDENT def circular ( head ) : NEW_LINE INDENT start = head NEW_LINE while ( head . next is not None ) : NEW_LINE INDENT head = head . next NEW_LINE DEDENT head . next = start NEW_LINE return start NEW_LINE DEDENT def displayList ( node ) : NEW_LINE INDENT start = node NEW_LINE while ( node . next is not start ) : NEW_LINE INDENT print ( " { } ▁ " . format ( node . data ) , end = " " ) NEW_LINE node = node . next NEW_LINE DEDENT print ( " { } ▁ " . format ( node . data ) , end = " " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = None NEW_LINE head = push ( head , 15 ) NEW_LINE head = push ( head , 14 ) NEW_LINE head = push ( head , 13 ) NEW_LINE head = push ( head , 22 ) NEW_LINE head = push ( head , 17 ) NEW_LINE circular ( head ) NEW_LINE print ( " Display ▁ List : " ) NEW_LINE displayList ( head ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int findAnswer ( int n , int [ ] arr ) { Arrays . sort ( arr ) ; int sum = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) { sum += ( arr [ i ] + arr [ n - i - 1 ] ) * ( arr [ i ] + arr [ n - i - 1 ] ) ; } return sum ; } public static void main ( String [ ] args ) { int [ ] arr = { 53 , 28 , 143 , 5 } ; int n = arr . length ; System . out . println ( findAnswer ( n , arr ) ) ; } }

def findAnswer ( n , arr ) : NEW_LINE INDENT arr . sort ( reverse = False ) NEW_LINE sum = 0 NEW_LINE for i in range ( int ( n / 2 ) ) : NEW_LINE INDENT sum += ( ( arr [ i ] + arr [ n - i - 1 ] ) * ( arr [ i ] + arr [ n - i - 1 ] ) ) NEW_LINE DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 53 , 28 , 143 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( findAnswer ( n , arr ) ) NEW_LINE DEDENT


public class GFG { static int minSwaps ( int arr [ ] , int n ) { int numberOfOnes = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 1 ) numberOfOnes ++ ; } int x = numberOfOnes ; int count_ones = 0 , maxOnes ; for ( int i = 0 ; i < x ; i ++ ) { if ( arr [ i ] == 1 ) count_ones ++ ; } maxOnes = count_ones ; for ( int i = 1 ; i <= n - x ; i ++ ) { if ( arr [ i - 1 ] == 1 ) count_ones -- ; if ( arr [ i + x - 1 ] == 1 ) count_ones ++ ; if ( maxOnes < count_ones ) maxOnes = count_ones ; } int numberOfZeroes = x - maxOnes ; return numberOfZeroes ; } public static void main ( String args [ ] ) { int a [ ] = new int [ ] { 0 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 } ; int n = a . length ; System . out . println ( minSwaps ( a , n ) ) ; } }

def minSwaps ( arr , n ) : NEW_LINE INDENT numberOfOnes = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE INDENT numberOfOnes = numberOfOnes + 1 NEW_LINE DEDENT DEDENT x = numberOfOnes NEW_LINE count_ones = 0 NEW_LINE maxOnes = 0 NEW_LINE for i in range ( 0 , x ) : NEW_LINE INDENT if ( arr [ i ] == 1 ) : NEW_LINE INDENT count_ones = count_ones + 1 NEW_LINE DEDENT DEDENT maxOnes = count_ones NEW_LINE for i in range ( 1 , ( n - x + 1 ) ) : NEW_LINE INDENT if ( arr [ i - 1 ] == 1 ) : NEW_LINE INDENT count_ones = count_ones - 1 NEW_LINE DEDENT if ( arr [ i + x - 1 ] == 1 ) : NEW_LINE INDENT count_ones = count_ones + 1 NEW_LINE DEDENT if ( maxOnes < count_ones ) : NEW_LINE INDENT maxOnes = count_ones NEW_LINE DEDENT DEDENT numberOfZeroes = x - maxOnes NEW_LINE return numberOfZeroes NEW_LINE DEDENT a = [ 0 , 0 , 1 , 0 , 1 , 1 , 0 , 0 , 1 ] NEW_LINE n = 9 NEW_LINE print ( minSwaps ( a , n ) ) NEW_LINE


class GFG { static void printRepeatingEven ( int arr [ ] , int n ) { long _xor = 0L ; long pos ; for ( int i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; _xor ^= pos ; } for ( int i = 0 ; i < n ; ++ i ) { pos = 1 << arr [ i ] ; if ( ! ( ( pos & _xor ) != 0 ) ) { System . out . print ( arr [ i ] + " ▁ " ) ; _xor ^= pos ; } } } public static void main ( String args [ ] ) { int arr [ ] = { 9 , 12 , 23 , 10 , 12 , 12 , 15 , 23 , 14 , 12 , 15 } ; int n = arr . length ; printRepeatingEven ( arr , n ) ; } }

def printRepeatingEven ( arr , n ) : NEW_LINE INDENT axor = 0 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT pos = 1 << arr [ i ] ; NEW_LINE axor ^= pos ; NEW_LINE DEDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT pos = 1 << arr [ i ] ; NEW_LINE if ( not ( pos & axor ) ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE axor ^= pos ; NEW_LINE DEDENT DEDENT DEDENT arr = [ 9 , 12 , 23 , 10 , 12 , 12 , 15 , 23 , 14 , 12 , 15 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE printRepeatingEven ( arr , n ) ; NEW_LINE


import java . io . * ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] [ ] C = new int [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } static int maxcoefficientvalue ( int n ) { if ( n % 2 == 0 ) return binomialCoeff ( n , n / 2 ) ; else return binomialCoeff ( n , ( n + 1 ) / 2 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( maxcoefficientvalue ( n ) ) ; } }

def binomialCoeff ( n , k ) : NEW_LINE INDENT C = [ [ 0 for x in range ( k + 1 ) ] for y in range ( n + 1 ) ] NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT for j in range ( min ( i , k ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; NEW_LINE DEDENT DEDENT DEDENT return C [ n ] [ k ] ; NEW_LINE DEDENT def maxcoefficientvalue ( n ) : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT return binomialCoeff ( n , int ( n / 2 ) ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return binomialCoeff ( n , int ( ( n + 1 ) / 2 ) ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 ; NEW_LINE print ( maxcoefficientvalue ( n ) ) ; NEW_LINE DEDENT


class GFG { static boolean canBeBalanced ( String s , int n ) { int count = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' ( ' ) count ++ ; else count -- ; count_1 = Math . min ( count_1 , count ) ; } if ( count_1 >= - 1 && count == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { String s = " ( ) ) ( ) ( " ; int n = s . length ( ) ; if ( canBeBalanced ( s , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def canBeBalanced ( s , n ) : NEW_LINE INDENT count = 0 NEW_LINE count_1 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == ' ( ' ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count -= 1 NEW_LINE DEDENT count_1 = min ( count_1 , count ) NEW_LINE DEDENT if ( count_1 >= - 1 and count == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT s = " ( ) ) ( ) ( " NEW_LINE n = len ( s ) NEW_LINE if ( canBeBalanced ( s , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


public class MergeTwoSortedArrays { private static int nextGap ( int gap ) { if ( gap <= 1 ) return 0 ; return ( gap / 2 ) + ( gap % 2 ) ; } private static void merge ( int [ ] arr1 , int [ ] arr2 , int n , int m ) { int i , j , gap = n + m ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) { for ( i = 0 ; i + gap < n ; i ++ ) if ( arr1 [ i ] > arr1 [ i + gap ] ) { int temp = arr1 [ i ] ; arr1 [ i ] = arr1 [ i + gap ] ; arr1 [ i + gap ] = temp ; } for ( j = gap > n ? gap - n : 0 ; i < n && j < m ; i ++ , j ++ ) if ( arr1 [ i ] > arr2 [ j ] ) { int temp = arr1 [ i ] ; arr1 [ i ] = arr2 [ j ] ; arr2 [ j ] = temp ; } if ( j < m ) { for ( j = 0 ; j + gap < m ; j ++ ) if ( arr2 [ j ] > arr2 [ j + gap ] ) { int temp = arr2 [ j ] ; arr2 [ j ] = arr2 [ j + gap ] ; arr2 [ j + gap ] = temp ; } } } } public static void main ( String [ ] args ) { int [ ] a1 = { 10 , 27 , 38 , 43 , 82 } ; int [ ] a2 = { 3 , 9 } ; merge ( a1 , a2 , a1 . length , a2 . length ) ; System . out . print ( " First ▁ Array : ▁ " ) ; for ( int i = 0 ; i < a1 . length ; i ++ ) { System . out . print ( a1 [ i ] + " ▁ " ) ; } System . out . println ( ) ; System . out . print ( " Second ▁ Array : ▁ " ) ; for ( int i = 0 ; i < a2 . length ; i ++ ) { System . out . print ( a2 [ i ] + " ▁ " ) ; } } }

def nextGap ( gap ) : NEW_LINE INDENT if ( gap <= 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return ( gap // 2 ) + ( gap % 2 ) NEW_LINE DEDENT def merge ( arr1 , arr2 , n , m ) : NEW_LINE INDENT gap = n + m NEW_LINE gap = nextGap ( gap ) NEW_LINE while gap > 0 : NEW_LINE INDENT i = 0 NEW_LINE while i + gap < n : NEW_LINE INDENT if ( arr1 [ i ] > arr1 [ i + gap ] ) : NEW_LINE INDENT arr1 [ i ] , arr1 [ i + gap ] = arr1 [ i + gap ] , arr1 [ i ] NEW_LINE DEDENT i += 1 NEW_LINE DEDENT j = gap - n if gap > n else 0 NEW_LINE while i < n and j < m : NEW_LINE INDENT if ( arr1 [ i ] > arr2 [ j ] ) : NEW_LINE INDENT arr1 [ i ] , arr2 [ j ] = arr2 [ j ] , arr1 [ i ] NEW_LINE DEDENT i += 1 NEW_LINE j += 1 NEW_LINE DEDENT if ( j < m ) : NEW_LINE INDENT j = 0 NEW_LINE while j + gap < m : NEW_LINE INDENT if ( arr2 [ j ] > arr2 [ j + gap ] ) : NEW_LINE INDENT arr2 [ j ] , arr2 [ j + gap ] = arr2 [ j + gap ] , arr2 [ j ] NEW_LINE DEDENT j += 1 NEW_LINE DEDENT DEDENT gap = nextGap ( gap ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a1 = [ 10 , 27 , 38 , 43 , 82 ] NEW_LINE a2 = [ 3 , 9 ] NEW_LINE n = len ( a1 ) NEW_LINE m = len ( a2 ) NEW_LINE merge ( a1 , a2 , n , m ) NEW_LINE print ( " First ▁ Array : ▁ " , end = " " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( a1 [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE print ( " Second ▁ Array : ▁ " , end = " " ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT print ( a2 [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT


class GFG { static int isSubstring ( String s1 , String s2 ) { int M = s1 . length ( ) ; int N = s2 . length ( ) ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( s2 . charAt ( i + j ) != s1 . charAt ( j ) ) break ; if ( j == M ) return i ; } return - 1 ; } public static void main ( String args [ ] ) { String s1 = " for " ; String s2 = " geeksforgeeks " ; int res = isSubstring ( s1 , s2 ) ; if ( res == - 1 ) System . out . println ( " Not ▁ present " ) ; else System . out . println ( " Present ▁ at ▁ index ▁ " + res ) ; } }

def isSubstring ( s1 , s2 ) : NEW_LINE INDENT M = len ( s1 ) NEW_LINE N = len ( s2 ) NEW_LINE for i in range ( N - M + 1 ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( s2 [ i + j ] != s1 [ j ] ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if j + 1 == M : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s1 = " for " NEW_LINE s2 = " geeksforgeeks " NEW_LINE res = isSubstring ( s1 , s2 ) NEW_LINE if res == - 1 : NEW_LINE INDENT print ( " Not ▁ present " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Present ▁ at ▁ index ▁ " + str ( res ) ) NEW_LINE DEDENT DEDENT


import java . util . * ; class GFG { static boolean check ( String s ) { for ( int i = 0 ; i + 1 < s . length ( ) ; ++ i ) { if ( Math . abs ( s . charAt ( i ) - s . charAt ( i + 1 ) ) == 1 ) { return false ; } } return true ; } static void Rearrange ( String str ) { String odd = " " , even = " " ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { if ( str . charAt ( i ) % 2 == 0 ) { even += str . charAt ( i ) ; } else { odd += str . charAt ( i ) ; } } odd = sort ( odd ) ; even = sort ( even ) ; if ( check ( odd + even ) ) { System . out . print ( odd + even ) ; } else if ( check ( even + odd ) ) { System . out . print ( even + odd ) ; } else { System . out . print ( - 1 ) ; } } public static String sort ( String inputString ) { char tempArray [ ] = inputString . toCharArray ( ) ; Arrays . sort ( tempArray ) ; return new String ( tempArray ) ; } public static void main ( String [ ] args ) { String str = " aabcd " ; Rearrange ( str ) ; } }

def check ( s ) : NEW_LINE INDENT for i in range ( len ( s ) - 1 ) : NEW_LINE INDENT if ( abs ( ord ( s [ i ] ) - ord ( s [ i + 1 ] ) ) == 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def Rearrange ( Str ) : NEW_LINE INDENT odd , even = " " , " " NEW_LINE for i in range ( len ( Str ) ) : NEW_LINE INDENT if ( ord ( Str [ i ] ) % 2 == 0 ) : NEW_LINE INDENT even += Str [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT odd += Str [ i ] NEW_LINE DEDENT DEDENT odd = sorted ( odd ) NEW_LINE even = sorted ( even ) NEW_LINE if ( check ( odd + even ) ) : NEW_LINE INDENT print ( " " . join ( odd + even ) ) NEW_LINE DEDENT elif ( check ( even + odd ) ) : NEW_LINE INDENT print ( " " . join ( even + odd ) ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT Str = " aabcd " NEW_LINE Rearrange ( Str ) NEW_LINE


class GFG { static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } static void sort_shell_metzner ( int arr [ ] , int n ) { int i , j , k , l , m , temp ; m = n ; while ( m > 0 ) { m /= 2 ; k = n - m ; j = 0 ; do { i = j ; do { l = i + m ; if ( l < n && arr [ i ] > arr [ l ] ) { swap ( arr , i , l ) ; i -= m ; } else { break ; } } while ( i >= 0 ) ; j ++ ; } while ( j <= k ) ; } } static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 0 , - 2 , 8 , 5 , 1 } ; int n = arr . length ; sort_shell_metzner ( arr , n ) ; printArray ( arr , n ) ; } }

def sort_shell_metzner ( arr , n ) : NEW_LINE INDENT m = n ; NEW_LINE while ( m > 0 ) : NEW_LINE INDENT m //= 2 NEW_LINE k = n - m NEW_LINE j = 0 NEW_LINE while ( j < k ) : NEW_LINE INDENT i = j NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT l = i + m NEW_LINE if ( arr [ i ] > arr [ l ] ) : NEW_LINE INDENT arr [ i ] , arr [ l ] = arr [ l ] , arr [ i ] NEW_LINE i -= m NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT j += 1 NEW_LINE DEDENT DEDENT DEDENT def printArray ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 0 , - 2 , 8 , 5 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE sort_shell_metzner ( arr , n ) NEW_LINE printArray ( arr , n ) NEW_LINE DEDENT


class Test { static int arr [ ] = new int [ ] { 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 } ; static void findZeroes ( int m ) { int wL = 0 , wR = 0 ; int bestL = 0 , bestWindow = 0 ; int zeroCount = 0 ; while ( wR < arr . length ) { if ( zeroCount <= m ) { if ( arr [ wR ] == 0 ) zeroCount ++ ; wR ++ ; } if ( zeroCount > m ) { if ( arr [ wL ] == 0 ) zeroCount -- ; wL ++ ; } if ( ( wR - wL > bestWindow ) && ( zeroCount <= m ) ) { bestWindow = wR - wL ; bestL = wL ; } } for ( int i = 0 ; i < bestWindow ; i ++ ) { if ( arr [ bestL + i ] == 0 ) System . out . print ( bestL + i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int m = 2 ; System . out . println ( " Indexes ▁ of ▁ zeroes ▁ to ▁ be ▁ flipped ▁ are ▁ " ) ; findZeroes ( m ) ; } }

def findZeroes ( arr , n , m ) : NEW_LINE INDENT wL = wR = 0 NEW_LINE bestL = bestWindow = 0 NEW_LINE zeroCount = 0 NEW_LINE while wR < n : NEW_LINE INDENT if zeroCount <= m : NEW_LINE INDENT if arr [ wR ] == 0 : NEW_LINE INDENT zeroCount += 1 NEW_LINE DEDENT wR += 1 NEW_LINE DEDENT if zeroCount > m : NEW_LINE INDENT if arr [ wL ] == 0 : NEW_LINE INDENT zeroCount -= 1 NEW_LINE DEDENT wL += 1 NEW_LINE DEDENT if ( wR - wL > bestWindow ) and ( zeroCount <= m ) : NEW_LINE INDENT bestWindow = wR - wL NEW_LINE bestL = wL NEW_LINE DEDENT DEDENT for i in range ( 0 , bestWindow ) : NEW_LINE INDENT if arr [ bestL + i ] == 0 : NEW_LINE INDENT print ( bestL + i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ] NEW_LINE m = 2 NEW_LINE n = len ( arr ) NEW_LINE print ( " Indexes ▁ of ▁ zeroes ▁ to ▁ be ▁ flipped ▁ are " , end = " ▁ " ) NEW_LINE findZeroes ( arr , n , m ) NEW_LINE


import java . io . * ; import java . util . * ; import java . lang . Math ; class Multipy { static void modify ( 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 ; modify ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

def modify ( 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 arr = [ 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE modify ( arr , n ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT


import java . util . * ; class GfG { static int countPairs ( int A1 [ ] , int A2 [ ] , int n1 , int n2 , int K ) { int res = 0 ; Map < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n1 ; ++ i ) { if ( m . containsKey ( A1 [ i ] ) ) m . put ( A1 [ i ] , m . get ( A1 [ i ] ) + 1 ) ; else m . put ( A1 [ i ] , 1 ) ; } for ( int i = 0 ; i < n2 ; ++ i ) { int temp = K - A2 [ i ] ; if ( m . containsKey ( temp ) && m . get ( temp ) != 0 ) { res ++ ; m . put ( temp , m . get ( A1 [ i ] ) - 1 ) ; } } return res ; } public static void main ( String [ ] args ) { int A1 [ ] = { 1 , 1 , 3 , 4 , 5 , 6 , 6 } ; int A2 [ ] = { 1 , 4 , 4 , 5 , 7 } , K = 10 ; int n1 = A1 . length ; int n2 = A2 . length ; System . out . println ( countPairs ( A1 , A2 , n1 , n2 , K ) ) ; } }

def countPairs ( A1 , A2 , n1 , n2 , K ) : NEW_LINE INDENT res = 0 NEW_LINE m = dict ( ) NEW_LINE for i in range ( 0 , n1 ) : NEW_LINE INDENT if A1 [ i ] not in m . keys ( ) : NEW_LINE INDENT m [ A1 [ i ] ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ A1 [ i ] ] = m [ A1 [ i ] ] + 1 NEW_LINE DEDENT DEDENT for i in range ( 0 , n2 ) : NEW_LINE INDENT temp = K - A2 [ i ] NEW_LINE if temp in m . keys ( ) : NEW_LINE INDENT res = res + 1 NEW_LINE m [ temp ] = m [ temp ] - 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT A1 = [ 1 , 1 , 3 , 4 , 5 , 6 , 6 ] NEW_LINE A2 = [ 1 , 4 , 4 , 5 , 7 ] NEW_LINE K = 10 NEW_LINE n1 = len ( A1 ) NEW_LINE n2 = len ( A2 ) NEW_LINE print ( countPairs ( A1 , A2 , n1 , n2 , K ) ) NEW_LINE


import java . io . * ; class GFG { static int MAX = 50 ; static void remove_row_col ( int arr [ ] [ ] , int n , int x ) { for ( int i = x ; i < n ; i ++ ) { for ( int j = x ; j < n ; j ++ ) { System . out . print ( arr [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int n = 3 ; int arr [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; int x = 1 ; remove_row_col ( arr , n , x ) ; } }

def remove_row_col ( arr , n , x ) : NEW_LINE INDENT for i in range ( x , n ) : NEW_LINE INDENT for j in range ( x , n ) : NEW_LINE INDENT print ( arr [ i ] [ j ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 NEW_LINE MAX = 50 NEW_LINE arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] NEW_LINE x = 1 NEW_LINE remove_row_col ( arr , n , x ) NEW_LINE DEDENT


class GFG { public static boolean isDivisible ( int num , int x , int y ) { while ( num % x == 0 || num % y == 0 ) { if ( num % x == 0 ) num /= x ; if ( num % y == 0 ) num /= y ; } if ( num > 1 ) return false ; return true ; } public static int _gcd ( int a , int b ) { while ( a != b ) { if ( a > b ) a = a - b ; else b = b - a ; } return a ; } public static boolean isPossible ( int [ ] arr , int n , int x , int y ) { int gcd = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) gcd = _gcd ( gcd , arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! isDivisible ( arr [ i ] / gcd , x , y ) ) return false ; } return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 6 , 8 } ; int n = arr . length ; int x = 2 , y = 3 ; if ( isPossible ( arr , n , x , y ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

from math import gcd as __gcd NEW_LINE def isDivisible ( num , x , y ) : NEW_LINE INDENT while ( num % x == 0 or num % y == 0 ) : NEW_LINE INDENT if ( num % x == 0 ) : NEW_LINE INDENT num //= x NEW_LINE DEDENT if ( num % y == 0 ) : NEW_LINE INDENT num //= y NEW_LINE DEDENT DEDENT if ( num > 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT return True NEW_LINE DEDENT def isPossible ( arr , n , x , y ) : NEW_LINE INDENT gcd = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT gcd = __gcd ( gcd , arr [ i ] ) NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( isDivisible ( arr [ i ] // gcd , x , y ) == False ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT arr = [ 2 , 4 , 6 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE x = 2 NEW_LINE y = 3 NEW_LINE if ( isPossible ( arr , n , x , y ) == True ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int factorial ( int n ) { int result = 1 ; for ( int i = 1 ; i <= n ; i ++ ) result = result * i ; return result ; } static int nCr ( int n , int r ) { return factorial ( n ) / ( factorial ( r ) * factorial ( n - r ) ) ; } static int calculate_result ( int n ) { int result = 2 * nCr ( ( n - 2 ) , ( n / 2 - 1 ) ) ; return result ; } public static void main ( String [ ] args ) { int a = 2 , b = 4 ; System . out . println ( calculate_result ( 2 * a ) ) ; System . out . print ( calculate_result ( 2 * b ) ) ; } }

def factorial ( n ) : NEW_LINE INDENT result = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT result *= i NEW_LINE DEDENT return result NEW_LINE DEDENT def nCr ( n , r ) : NEW_LINE INDENT return ( factorial ( n ) // ( factorial ( r ) * factorial ( n - r ) ) ) NEW_LINE DEDENT def calculate_result ( n ) : NEW_LINE INDENT result = 2 * nCr ( ( n - 2 ) , ( n // 2 - 1 ) ) NEW_LINE return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a , b = 2 , 4 NEW_LINE print ( calculate_result ( 2 * a ) ) NEW_LINE print ( calculate_result ( 2 * b ) ) NEW_LINE DEDENT


class GFG { static int MAX_CHAR = 26 ; static void sortString ( String str ) { int charCount [ ] = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { charCount [ str . charAt ( i ) - ' a ' ] ++ ; } for ( int i = MAX_CHAR - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < charCount [ i ] ; j ++ ) { System . out . print ( ( char ) ( ' a ' + i ) ) ; } } } public static void main ( String [ ] args ) { String s = " alkasingh " ; sortString ( s ) ; } }

MAX_CHAR = 26 ; NEW_LINE def sortString ( str ) : NEW_LINE INDENT charCount = [ 0 ] * MAX_CHAR ; NEW_LINE for i in range ( len ( str ) ) : NEW_LINE INDENT charCount [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1 ; NEW_LINE DEDENT for i in range ( MAX_CHAR - 1 , - 1 , - 1 ) : NEW_LINE INDENT for j in range ( charCount [ i ] ) : NEW_LINE INDENT print ( chr ( 97 + i ) , end = " " ) ; NEW_LINE DEDENT DEDENT DEDENT s = " alkasingh " ; NEW_LINE sortString ( s ) ; NEW_LINE


class GFG { static double average ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; return sum / n ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int n = arr . length ; System . out . println ( average ( arr , n ) ) ; } }

def average ( a , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += a [ i ] NEW_LINE DEDENT return sum / n ; NEW_LINE DEDENT arr = [ 10 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] NEW_LINE n = len ( arr ) NEW_LINE print ( average ( arr , n ) ) NEW_LINE


import java . util . HashSet ; class geeks { public static int countTotalDistinct ( String str ) { int cnt = 0 ; HashSet < String > items = new HashSet < > ( ) ; for ( int i = 0 ; i < str . length ( ) ; ++ i ) { String temp = " " ; HashSet < Character > ans = new HashSet < > ( ) ; for ( int j = i ; j < str . length ( ) ; ++ j ) { temp = temp + str . charAt ( j ) ; ans . add ( str . charAt ( j ) ) ; if ( ! items . contains ( temp ) ) { items . add ( temp ) ; cnt += ans . size ( ) ; } } } return cnt ; } public static void main ( String [ ] args ) { String str = " ABCA " ; System . out . println ( countTotalDistinct ( str ) ) ; } }

def countTotalDistinct ( string ) : NEW_LINE INDENT cnt = 0 ; NEW_LINE items = set ( ) ; NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT temp = " " ; NEW_LINE ans = set ( ) ; NEW_LINE for j in range ( i , len ( string ) ) : NEW_LINE INDENT temp = temp + string [ j ] ; NEW_LINE ans . add ( string [ j ] ) ; NEW_LINE if temp not in items : NEW_LINE INDENT items . add ( temp ) ; NEW_LINE cnt += len ( ans ) ; NEW_LINE DEDENT DEDENT DEDENT return cnt ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " ABCA " ; NEW_LINE print ( countTotalDistinct ( string ) ) ; NEW_LINE DEDENT


class solution { static int oddEquivalent ( String s , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) count ++ ; } return count ; } public static void main ( String ar [ ] ) { String s = "1011011" ; int n = s . length ( ) ; System . out . println ( oddEquivalent ( s , n ) ) ; } }

def oddEquivalent ( s , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( s [ i ] == '1' ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = "1011011" NEW_LINE n = len ( s ) NEW_LINE print ( oddEquivalent ( s , n ) ) NEW_LINE DEDENT


public class GFG { static void printNumbers ( int n , int d ) { String st = " " + d ; char ch = st . charAt ( 0 ) ; for ( int i = 0 ; i <= n ; i ++ ) { st = " " ; st = st + i ; if ( i == d || st . indexOf ( ch ) >= 0 ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 100 , d = 5 ; printNumbers ( n , d ) ; } }

def index ( st , ch ) : NEW_LINE INDENT for i in range ( len ( st ) ) : NEW_LINE INDENT if ( st [ i ] == ch ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT def printNumbers ( n , d ) : NEW_LINE INDENT st = " " + str ( d ) NEW_LINE ch = st [ 0 ] NEW_LINE for i in range ( 0 , n + 1 , 1 ) : NEW_LINE INDENT st = " " NEW_LINE st = st + str ( i ) NEW_LINE if ( i == d or index ( st , ch ) >= 0 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 100 NEW_LINE d = 5 NEW_LINE printNumbers ( n , d ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int countRectangles ( int radius ) { int rectangles = 0 ; int diameter = 2 * radius ; int diameterSquare = diameter * diameter ; for ( int a = 1 ; a < 2 * radius ; a ++ ) { for ( int b = 1 ; b < 2 * radius ; b ++ ) { int diagnalLengthSquare = ( a * a + b * b ) ; if ( diagnalLengthSquare <= diameterSquare ) { rectangles ++ ; } } } return rectangles ; } public static void main ( String [ ] args ) { int radius = 2 ; int totalRectangles ; totalRectangles = countRectangles ( radius ) ; System . out . println ( totalRectangles + " ▁ rectangles ▁ can ▁ be ▁ " + " cut ▁ from ▁ a ▁ circle ▁ of " + " ▁ Radius ▁ " + radius ) ; } }

def countRectangles ( radius ) : NEW_LINE INDENT rectangles = 0 NEW_LINE diameter = 2 * radius NEW_LINE diameterSquare = diameter * diameter NEW_LINE for a in range ( 1 , 2 * radius ) : NEW_LINE INDENT for b in range ( 1 , 2 * radius ) : NEW_LINE INDENT diagnalLengthSquare = ( a * a + b * b ) NEW_LINE if ( diagnalLengthSquare <= diameterSquare ) : NEW_LINE INDENT rectangles += 1 NEW_LINE DEDENT DEDENT DEDENT return rectangles NEW_LINE DEDENT radius = 2 NEW_LINE totalRectangles = countRectangles ( radius ) NEW_LINE print ( totalRectangles , " rectangles ▁ can ▁ be " , " cut ▁ from ▁ a ▁ circle ▁ of ▁ Radius " , radius ) NEW_LINE


import java . util . * ; class GFG { public static int sumOfPairs ( int n ) { ArrayList < Integer > v = new ArrayList < Integer > ( ) ; int sum = 0 ; while ( n > 0 ) { v . add ( n % 2 ) ; n = n / 2 ; } Collections . reverse ( v ) ; for ( int i = 0 ; i < v . size ( ) - 1 ; i ++ ) { for ( int j = i + 1 ; j < v . size ( ) ; j ++ ) { if ( v . get ( i ) == 0 && v . get ( j ) == 1 ) sum += 1 ; if ( v . get ( i ) == 1 && v . get ( j ) == 1 ) sum += 3 ; if ( v . get ( i ) == 1 && v . get ( j ) == 0 ) sum += 2 ; } } return sum ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( sumOfPairs ( N ) ) ; } }

def sumofPairs ( n ) : NEW_LINE INDENT v = [ ] NEW_LINE sum = 0 NEW_LINE while n > 0 : NEW_LINE INDENT v . append ( n % 2 ) NEW_LINE n = n // 2 NEW_LINE DEDENT v . reverse ( ) NEW_LINE for i in range ( len ( v ) - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , len ( v ) ) : NEW_LINE INDENT if v [ i ] == 0 and v [ j ] == 1 : NEW_LINE INDENT sum += 1 NEW_LINE DEDENT if v [ i ] == 1 and v [ j ] == 1 : NEW_LINE INDENT sum += 3 NEW_LINE DEDENT if v [ i ] == 1 and v [ j ] == 0 : NEW_LINE INDENT sum += 2 NEW_LINE DEDENT DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 NEW_LINE print ( sumofPairs ( N ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static class Point { int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static int findmin ( Point p [ ] , int n ) { int a = 0 , b = 0 , c = 0 , d = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( p [ i ] . x <= 0 ) a ++ ; else if ( p [ i ] . x >= 0 ) b ++ ; if ( p [ i ] . y >= 0 ) c ++ ; else if ( p [ i ] . y <= 0 ) d ++ ; } return Math . min ( Math . min ( a , b ) , Math . min ( c , d ) ) ; } public static void main ( String [ ] args ) { Point p [ ] = { new Point ( 1 , 1 ) , new Point ( 2 , 2 ) , new Point ( - 1 , - 1 ) , new Point ( - 2 , 2 ) } ; int n = p . length ; System . out . println ( findmin ( p , n ) ) ; } }

def findmin ( p , n ) : NEW_LINE INDENT a , b , c , d = 0 , 0 , 0 , 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( p [ i ] [ 0 ] <= 0 ) : NEW_LINE INDENT a += 1 NEW_LINE DEDENT elif ( p [ i ] [ 0 ] >= 0 ) : NEW_LINE INDENT b += 1 NEW_LINE DEDENT if ( p [ i ] [ 1 ] >= 0 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT elif ( p [ i ] [ 1 ] <= 0 ) : NEW_LINE INDENT d += 1 NEW_LINE DEDENT DEDENT return min ( [ a , b , c , d ] ) NEW_LINE DEDENT p = [ [ 1 , 1 ] , [ 2 , 2 ] , [ - 1 , - 1 ] , [ - 2 , 2 ] ] NEW_LINE n = len ( p ) NEW_LINE print ( findmin ( p , n ) ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static void main ( String args [ ] ) { int N = 6 ; int Even = N / 2 ; int Odd = N - Even ; System . out . println ( Even * Odd ) ; } }

N = 6 NEW_LINE Even = N // 2 NEW_LINE Odd = N - Even NEW_LINE print ( Even * Odd ) NEW_LINE


class GfG { static String strBitwiseAND ( String [ ] arr , int n ) { String res = " " ; int smallest_size = Integer . MAX_VALUE ; int largest_size = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { StringBuilder temp = new StringBuilder ( ) ; temp . append ( arr [ i ] ) ; arr [ i ] = temp . reverse ( ) . toString ( ) ; smallest_size = Math . min ( smallest_size , arr [ i ] . length ( ) ) ; largest_size = Math . max ( largest_size , arr [ i ] . length ( ) ) ; } for ( int i = 0 ; i < smallest_size ; i ++ ) { boolean all_ones = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] . charAt ( i ) == '0' ) { all_ones = false ; break ; } } res += ( all_ones ? '1' : '0' ) ; } for ( int i = 0 ; i < largest_size - smallest_size ; i ++ ) res += '0' ; StringBuilder temp = new StringBuilder ( ) ; temp . append ( res ) ; res = temp . reverse ( ) . toString ( ) ; return res ; } public static void main ( String [ ] args ) { String arr [ ] = { "101" , "110110" , "111" } ; int n = arr . length ; System . out . println ( strBitwiseAND ( arr , n ) ) ; } }

import sys ; NEW_LINE def strBitwiseAND ( arr , n ) : NEW_LINE INDENT res = " " NEW_LINE smallest_size = sys . maxsize ; NEW_LINE largest_size = - ( sys . maxsize - 1 ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ i ] = arr [ i ] [ : : - 1 ] ; NEW_LINE smallest_size = min ( smallest_size , len ( arr [ i ] ) ) ; NEW_LINE largest_size = max ( largest_size , len ( arr [ i ] ) ) ; NEW_LINE DEDENT for i in range ( smallest_size ) : NEW_LINE INDENT all_ones = True ; NEW_LINE for j in range ( n ) : NEW_LINE INDENT if ( arr [ j ] [ i ] == '0' ) : NEW_LINE INDENT all_ones = False ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if all_ones : NEW_LINE INDENT res += '1' ; NEW_LINE DEDENT else : NEW_LINE INDENT res += '0' ; NEW_LINE DEDENT DEDENT for i in range ( largest_size - smallest_size ) : NEW_LINE INDENT res += '0' ; NEW_LINE DEDENT res = res [ : : - 1 ] ; NEW_LINE return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ "101" , "110110" , "111" ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( strBitwiseAND ( arr , n ) ) ; NEW_LINE DEDENT


import java . io . * ; import java . math . * ; public class GFG { static int sumofFactors ( int n ) { int res = 1 ; for ( int i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { int curr_sum = 1 ; int curr_term = 1 ; while ( n % i == 0 ) { n = n / i ; curr_term *= i ; curr_sum += curr_term ; } res *= curr_sum ; } if ( n > 2 ) res *= ( 1 + n ) ; return res ; } public static void main ( String args [ ] ) { int n = 30 ; System . out . println ( sumofFactors ( n ) ) ; } }

import math as m NEW_LINE def sumofFactors ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 2 , int ( m . sqrt ( n ) + 1 ) ) : NEW_LINE INDENT curr_sum = 1 NEW_LINE curr_term = 1 NEW_LINE while n % i == 0 : NEW_LINE INDENT n = n / i ; NEW_LINE curr_term = curr_term * i ; NEW_LINE curr_sum += curr_term ; NEW_LINE DEDENT res = res * curr_sum NEW_LINE DEDENT if n > 2 : NEW_LINE INDENT res = res * ( 1 + n ) NEW_LINE DEDENT return res ; NEW_LINE DEDENT sum = sumofFactors ( 30 ) NEW_LINE print ( " Sum ▁ of ▁ all ▁ divisors ▁ is : ▁ " , sum ) NEW_LINE


class GFG { static int countDecoding ( char [ ] digits , int n ) { if ( n == 0 || n == 1 ) return 1 ; if ( digits [ 0 ] == '0' ) return 0 ; int count = 0 ; if ( digits [ n - 1 ] > '0' ) count = countDecoding ( digits , n - 1 ) ; if ( digits [ n - 2 ] == '1' || ( digits [ n - 2 ] == '2' && digits [ n - 1 ] < '7' ) ) count += countDecoding ( digits , n - 2 ) ; return count ; } public static void main ( String [ ] args ) { char digits [ ] = { '1' , '2' , '3' , '4' } ; int n = digits . length ; System . out . printf ( " Count ▁ is ▁ % d " , countDecoding ( digits , n ) ) ; } }

def numDecodings ( s : str ) -> int : NEW_LINE INDENT return numDecodingsHelper ( s , len ( s ) ) ; NEW_LINE DEDENT def numDecodingsHelper ( s : str , n : int ) -> int : NEW_LINE INDENT if n == 0 or n == 1 : NEW_LINE INDENT return 1 NEW_LINE DEDENT count = 0 NEW_LINE if s [ n - 1 ] > "0" : NEW_LINE INDENT count = numDecodingsHelper ( s , n - 1 ) NEW_LINE DEDENT if ( s [ n - 2 ] == '1' or ( s [ n - 2 ] == '2' and s [ n - 1 ] < '7' ) ) : NEW_LINE INDENT count += numDecodingsHelper ( s , n - 2 ) NEW_LINE DEDENT return count NEW_LINE DEDENT digits = "1234" NEW_LINE print ( " Count ▁ is ▁ " , numDecodings ( digits ) ) NEW_LINE


class GFG { static int countDistinct ( int arr [ ] , int n ) { int res = 1 ; for ( int i = 1 ; i < n ; i ++ ) { int j = 0 ; for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] == arr [ j ] ) break ; if ( i == j ) res ++ ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 10 , 9 , 45 , 2 , 10 , 10 , 45 } ; int n = arr . length ; System . out . println ( countDistinct ( arr , n ) ) ; } }

def countDistinct ( arr , n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT j = 0 NEW_LINE for j in range ( i ) : NEW_LINE INDENT if ( arr [ i ] == arr [ j ] ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( i == j + 1 ) : NEW_LINE INDENT res += 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT arr = [ 12 , 10 , 9 , 45 , 2 , 10 , 10 , 45 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countDistinct ( arr , n ) ) NEW_LINE


class GFG { static String get_maximum ( char [ ] s , int a [ ] ) { int n = s . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] - '0' < a [ s [ i ] - '0' ] ) { int j = i ; while ( j < n && ( s [ j ] - '0' <= a [ s [ j ] - '0' ] ) ) { s [ j ] = ( char ) ( '0' + a [ s [ j ] - '0' ] ) ; j ++ ; } return String . valueOf ( s ) ; } } return String . valueOf ( s ) ; } public static void main ( String [ ] args ) { String s = "1337" ; int a [ ] = { 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 } ; System . out . println ( get_maximum ( s . toCharArray ( ) , a ) ) ; } }

def get_maximum ( s , a ) : NEW_LINE INDENT s = list ( s ) NEW_LINE n = len ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ord ( s [ i ] ) - ord ( '0' ) < a [ ord ( s [ i ] ) - ord ( '0' ) ] ) : NEW_LINE INDENT j = i NEW_LINE while ( j < n and ( ord ( s [ j ] ) - ord ( '0' ) <= a [ ord ( s [ j ] ) - ord ( '0' ) ] ) ) : NEW_LINE INDENT s [ j ] = chr ( ord ( '0' ) + a [ ord ( s [ j ] ) - ord ( '0' ) ] ) NEW_LINE j += 1 NEW_LINE DEDENT return " " . join ( s ) ; NEW_LINE DEDENT DEDENT return s NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "1337" NEW_LINE a = [ 0 , 1 , 2 , 5 , 4 , 6 , 6 , 3 , 1 , 9 ] NEW_LINE print ( get_maximum ( s , a ) ) NEW_LINE DEDENT


import java . io . * ; public class GFG { static int maxDiff ( int [ ] arr , int n ) { int SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { boolean isSingleOccurance = true ; for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { isSingleOccurance = false ; arr [ i ] = arr [ j ] = 0 ; break ; } } if ( isSingleOccurance ) { if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ; else SubsetSum_2 += arr [ i ] ; } } return Math . abs ( SubsetSum_1 - SubsetSum_2 ) ; } static public void main ( String [ ] args ) { int [ ] arr = { 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 } ; int n = arr . length ; System . out . println ( " Maximum ▁ Difference ▁ = ▁ " + maxDiff ( arr , n ) ) ; } }

import math NEW_LINE def maxDiff ( arr , n ) : NEW_LINE INDENT SubsetSum_1 = 0 NEW_LINE SubsetSum_2 = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT isSingleOccurance = True NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( arr [ i ] == arr [ j ] ) : NEW_LINE INDENT isSingleOccurance = False NEW_LINE arr [ i ] = arr [ j ] = 0 NEW_LINE break NEW_LINE DEDENT DEDENT if ( isSingleOccurance == True ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT SubsetSum_1 += arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT SubsetSum_2 += arr [ i ] NEW_LINE DEDENT DEDENT DEDENT return abs ( SubsetSum_1 - SubsetSum_2 ) NEW_LINE DEDENT arr = [ 4 , 2 , - 3 , 3 , - 2 , - 2 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ Difference ▁ = ▁ { } " . format ( maxDiff ( arr , n ) ) ) NEW_LINE


class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( catalan ( n ) ) ; } }

def binomialCoeff ( n , k ) : NEW_LINE INDENT res = 1 ; NEW_LINE if ( k > n - k ) : NEW_LINE INDENT k = n - k ; NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT res *= ( n - i ) ; NEW_LINE res /= ( i + 1 ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT def catalan ( n ) : NEW_LINE INDENT c = binomialCoeff ( 2 * n , n ) ; NEW_LINE return int ( c / ( n + 1 ) ) ; NEW_LINE DEDENT n = 3 ; NEW_LINE print ( catalan ( n ) ) ; NEW_LINE


class GFG { static void makePolygon ( double a ) { double n = 360 / ( 180 - a ) ; if ( n == ( int ) n ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { double a = 90 ; makePolygon ( a ) ; } }

def makePolygon ( a ) : NEW_LINE INDENT n = 360 / ( 180 - a ) NEW_LINE if n == int ( n ) : 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 = 90 NEW_LINE makePolygon ( a ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean isPrime ( int x ) { for ( int i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) return false ; } return true ; } static int minimumCost ( int n ) { if ( isPrime ( n ) ) return 1 ; if ( n % 2 == 1 && isPrime ( n - 2 ) ) return 2 ; if ( n % 2 == 0 ) return 2 ; return 3 ; } public static void main ( String args [ ] ) { int n = 6 ; System . out . println ( minimumCost ( n ) ) ; } }

from math import sqrt NEW_LINE def isPrime ( x ) : NEW_LINE INDENT for i in range ( 2 , int ( sqrt ( x ) ) + 1 ) : NEW_LINE INDENT if ( x % i == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT return 1 ; NEW_LINE DEDENT def minimumCost ( n ) : NEW_LINE INDENT if ( isPrime ( n ) ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT if ( n % 2 == 1 and isPrime ( n - 2 ) ) : NEW_LINE INDENT return 2 ; NEW_LINE DEDENT if ( n % 2 == 0 ) : NEW_LINE INDENT return 2 ; NEW_LINE DEDENT return 3 ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 6 ; NEW_LINE print ( minimumCost ( n ) ) ; NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static int [ ] pref = new int [ 100010 ] ; static int isPerfectCube ( int x ) { double cr = Math . round ( Math . cbrt ( x ) ) ; if ( cr * cr * cr == ( double ) x ) return x ; return 0 ; } static void compute ( ) { for ( int i = 1 ; i <= 100000 ; ++ i ) { pref [ i ] = pref [ i - 1 ] + isPerfectCube ( i ) ; } } static void printSum ( int L , int R ) { long sum = pref [ R ] - pref [ L - 1 ] ; System . out . print ( sum + " ▁ " ) ; } public static void main ( String [ ] args ) { compute ( ) ; int Q = 4 ; int [ ] [ ] arr = { { 1 , 10 } , { 1 , 100 } , { 2 , 25 } , { 4 , 50 } } ; for ( int i = 0 ; i < Q ; i ++ ) { printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; } } }

pref = [ 0 ] * 100010 ; NEW_LINE def isPerfectCube ( x ) : NEW_LINE INDENT cr = round ( x ** ( 1 / 3 ) ) ; NEW_LINE rslt = x if ( cr * cr * cr == x ) else 0 ; NEW_LINE return rslt ; NEW_LINE DEDENT def compute ( ) : NEW_LINE INDENT for i in range ( 1 , 100001 ) : NEW_LINE INDENT pref [ i ] = pref [ i - 1 ] + isPerfectCube ( i ) ; NEW_LINE DEDENT DEDENT def printSum ( L , R ) : NEW_LINE INDENT sum = pref [ R ] - pref [ L - 1 ] ; NEW_LINE print ( sum , end = " ▁ " ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT compute ( ) ; NEW_LINE Q = 4 ; NEW_LINE arr = [ [ 1 , 10 ] , [ 1 , 100 ] , [ 2 , 25 ] , [ 4 , 50 ] ] ; NEW_LINE for i in range ( Q ) : NEW_LINE INDENT printSum ( arr [ i ] [ 0 ] , arr [ i ] [ 1 ] ) ; NEW_LINE DEDENT DEDENT


class GFG { static void print_asterisk ( int asterisk ) { if ( asterisk == 0 ) return ; System . out . print ( " * ▁ " ) ; print_asterisk ( asterisk - 1 ) ; } static void print_space ( int space ) { if ( space == 0 ) return ; System . out . print ( " ▁ " ) ; System . out . print ( " ▁ " ) ; print_space ( space - 1 ) ; } static void pattern_upper ( int n , int num ) { if ( n == 0 ) return ; print_asterisk ( num - n + 1 ) ; print_space ( 2 * n - 1 ) ; print_asterisk ( num - n + 1 ) ; System . out . println ( ) ; pattern_upper ( n - 1 , num ) ; } static void pattern_lower ( int n , int num ) { if ( n == 0 ) return ; print_asterisk ( n ) ; print_space ( 2 * ( num - n ) + 1 ) ; print_asterisk ( n ) ; System . out . println ( ) ; pattern_lower ( n - 1 , num ) ; } static void pattern ( int n , int num ) { pattern_upper ( n , num ) ; pattern_lower ( n - 1 , num ) ; } public static void main ( String [ ] args ) { int n = 5 ; pattern ( n , n ) ; } }

def print_asterisk ( asterisk ) : NEW_LINE INDENT if ( asterisk == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print ( " * ▁ " , end = " " ) ; NEW_LINE print_asterisk ( asterisk - 1 ) ; NEW_LINE DEDENT def print_space ( space ) : NEW_LINE INDENT if ( space == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print ( " ▁ " , end = " " ) ; NEW_LINE print ( " ▁ " , end = " " ) ; NEW_LINE print_space ( space - 1 ) ; NEW_LINE DEDENT def pattern_upper ( n , num ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print_asterisk ( num - n + 1 ) ; NEW_LINE print_space ( 2 * n - 1 ) ; NEW_LINE print_asterisk ( num - n + 1 ) ; NEW_LINE print ( ) ; NEW_LINE pattern_upper ( n - 1 , num ) ; NEW_LINE DEDENT def pattern_lower ( n , num ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print_asterisk ( n ) ; NEW_LINE print_space ( 2 * ( num - n ) + 1 ) ; NEW_LINE print_asterisk ( n ) ; NEW_LINE print ( ) ; NEW_LINE pattern_lower ( n - 1 , num ) ; NEW_LINE DEDENT def pattern ( n , num ) : NEW_LINE INDENT pattern_upper ( n , num ) ; NEW_LINE pattern_lower ( n - 1 , num ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 ; NEW_LINE pattern ( n , n ) ; NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { static void printDistinct ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( i < n - 1 && arr [ i ] == arr [ i + 1 ] ) i ++ ; System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 } ; int n = arr . length ; printDistinct ( arr , n ) ; } }

def printDistinct ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT while ( i < n - 1 and ( arr [ i ] == arr [ i + 1 ] ) ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT arr = [ 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE printDistinct ( arr , n ) ; NEW_LINE


class Main { static int kth ( int arr1 [ ] , int arr2 [ ] , int m , int n , int k ) { int [ ] sorted1 = new int [ m + n ] ; int i = 0 , j = 0 , d = 0 ; while ( i < m && j < n ) { if ( arr1 [ i ] < arr2 [ j ] ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; else sorted1 [ d ++ ] = arr2 [ j ++ ] ; } while ( i < m ) sorted1 [ d ++ ] = arr1 [ i ++ ] ; while ( j < n ) sorted1 [ d ++ ] = arr2 [ j ++ ] ; return sorted1 [ k - 1 ] ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 2 , 3 , 6 , 7 , 9 } ; int arr2 [ ] = { 1 , 4 , 8 , 10 } ; int k = 5 ; System . out . print ( kth ( arr1 , arr2 , 5 , 4 , k ) ) ; } }

def kth ( arr1 , arr2 , m , n , k ) : NEW_LINE INDENT sorted1 = [ 0 ] * ( m + n ) NEW_LINE i = 0 NEW_LINE j = 0 NEW_LINE d = 0 NEW_LINE while ( i < m and j < n ) : NEW_LINE INDENT if ( arr1 [ i ] < arr2 [ j ] ) : NEW_LINE INDENT sorted1 [ d ] = arr1 [ i ] NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT sorted1 [ d ] = arr2 [ j ] NEW_LINE j += 1 NEW_LINE DEDENT d += 1 NEW_LINE DEDENT while ( i < m ) : NEW_LINE INDENT sorted1 [ d ] = arr1 [ i ] NEW_LINE d += 1 NEW_LINE i += 1 NEW_LINE DEDENT while ( j < n ) : NEW_LINE INDENT sorted1 [ d ] = arr2 [ j ] NEW_LINE d += 1 NEW_LINE j += 1 NEW_LINE DEDENT return sorted1 [ k - 1 ] NEW_LINE DEDENT arr1 = [ 2 , 3 , 6 , 7 , 9 ] NEW_LINE arr2 = [ 1 , 4 , 8 , 10 ] NEW_LINE k = 5 ; NEW_LINE print ( kth ( arr1 , arr2 , 5 , 4 , k ) ) NEW_LINE


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

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


class GFG { static int MAX = 10001 ; static void sieveOfEratosthenes ( int [ ] s ) { boolean [ ] prime = new boolean [ MAX + 1 ] ; for ( int i = 2 ; i <= MAX ; i += 2 ) s [ i ] = 2 ; for ( int i = 3 ; i <= MAX ; i += 2 ) { if ( prime [ i ] == false ) { s [ i ] = i ; for ( int j = i ; j * i <= MAX ; j += 2 ) { if ( prime [ i * j ] == false ) { prime [ i * j ] = true ; s [ i * j ] = i ; } } } } } static int kPrimeFactor ( int n , int k , int [ ] s ) { while ( n > 1 ) { if ( k == 1 ) return s [ n ] ; k -- ; n /= s [ n ] ; } return - 1 ; } public static void main ( String [ ] args ) { int [ ] s = new int [ MAX + 1 ] ; sieveOfEratosthenes ( s ) ; int n = 12 , k = 3 ; System . out . println ( kPrimeFactor ( n , k , s ) ) ; n = 14 ; k = 3 ; System . out . println ( kPrimeFactor ( n , k , s ) ) ; } }

MAX = 10001 NEW_LINE def sieveOfEratosthenes ( s ) : NEW_LINE INDENT prime = [ False for i in range ( MAX + 1 ) ] NEW_LINE for i in range ( 2 , MAX + 1 , 2 ) : NEW_LINE INDENT s [ i ] = 2 ; NEW_LINE DEDENT for i in range ( 3 , MAX , 2 ) : NEW_LINE INDENT if ( prime [ i ] == False ) : NEW_LINE INDENT s [ i ] = i NEW_LINE for j in range ( i , MAX + 1 , 2 ) : NEW_LINE INDENT if j * j > MAX : NEW_LINE INDENT break NEW_LINE DEDENT if ( prime [ i * j ] == False ) : NEW_LINE INDENT prime [ i * j ] = True NEW_LINE s [ i * j ] = i NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT def kPrimeFactor ( n , k , s ) : NEW_LINE INDENT while ( n > 1 ) : NEW_LINE INDENT if ( k == 1 ) : NEW_LINE INDENT return s [ n ] NEW_LINE DEDENT k -= 1 NEW_LINE n //= s [ n ] NEW_LINE DEDENT return - 1 NEW_LINE DEDENT s = [ - 1 for i in range ( MAX + 1 ) ] NEW_LINE sieveOfEratosthenes ( s ) NEW_LINE n = 12 NEW_LINE k = 3 NEW_LINE print ( kPrimeFactor ( n , k , s ) ) NEW_LINE n = 14 NEW_LINE k = 3 NEW_LINE print ( kPrimeFactor ( n , k , s ) ) NEW_LINE


import java . io . * ; import java . util . * ; public class GFG { static List < Integer > power = new ArrayList < Integer > ( ) ; static void nextPower ( Integer N ) { Integer carry = 0 ; for ( int i = 0 ; i < power . size ( ) ; i ++ ) { Integer prod = ( power . get ( i ) * N ) + carry ; power . set ( i , prod % 10 ) ; carry = prod / 10 ; } while ( carry >= 1 ) { power . add ( carry % 10 ) ; carry = carry / 10 ; } } static void printPowerNumber ( int X , int N ) { power . add ( 1 ) ; List < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= X ; i ++ ) { nextPower ( N ) ; res . add ( power . get ( power . size ( ) - 1 ) ) ; res . add ( power . get ( 0 ) ) ; } for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) ) ; } public static void main ( String args [ ] ) { Integer N = 19 , X = 4 ; printPowerNumber ( X , N ) ; } }

power = [ ] NEW_LINE def nextPower ( N ) : NEW_LINE INDENT global power NEW_LINE carry = 0 NEW_LINE for i in range ( 0 , len ( power ) ) : NEW_LINE INDENT prod = ( power [ i ] * N ) + carry NEW_LINE power [ i ] = prod % 10 NEW_LINE carry = ( int ) ( prod / 10 ) NEW_LINE DEDENT while ( carry ) : NEW_LINE INDENT power . append ( carry % 10 ) NEW_LINE carry = ( int ) ( carry / 10 ) NEW_LINE DEDENT DEDENT def printPowerNumber ( X , N ) : NEW_LINE INDENT global power NEW_LINE power . append ( 1 ) NEW_LINE res = [ ] NEW_LINE for i in range ( 1 , X + 1 ) : NEW_LINE INDENT nextPower ( N ) NEW_LINE res . append ( power [ - 1 ] ) NEW_LINE res . append ( power [ 0 ] ) NEW_LINE DEDENT for i in range ( 0 , len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " " ) NEW_LINE DEDENT DEDENT N = 19 NEW_LINE X = 4 NEW_LINE printPowerNumber ( X , N ) NEW_LINE


import java . util . * ; class GFG { static void findMostOccurringChar ( Vector < String > str ) { int [ ] hash = new int [ 26 ] ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { for ( int j = 0 ; j < str . get ( i ) . length ( ) ; j ++ ) { hash [ str . get ( i ) . charAt ( j ) - 97 ] ++ ; } } int max = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { max = hash [ i ] > hash [ max ] ? i : max ; } System . out . print ( ( char ) ( max + 97 ) + " \n " ) ; } public static void main ( String [ ] args ) { Vector < String > str = new Vector < String > ( ) ; str . add ( " animal " ) ; str . add ( " zebra " ) ; str . add ( " lion " ) ; str . add ( " giraffe " ) ; findMostOccurringChar ( str ) ; } }

def findMostOccurringChar ( string ) : NEW_LINE INDENT hash = [ 0 ] * 26 ; NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT for j in range ( len ( string [ i ] ) ) : NEW_LINE INDENT hash [ ord ( string [ i ] [ j ] ) - ord ( ' a ' ) ] += 1 ; NEW_LINE DEDENT DEDENT max = 0 ; NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT max = i if hash [ i ] > hash [ max ] else max ; NEW_LINE DEDENT print ( ( chr ) ( max + 97 ) ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = [ ] ; NEW_LINE string . append ( " animal " ) ; NEW_LINE string . append ( " zebra " ) ; NEW_LINE string . append ( " lion " ) ; NEW_LINE string . append ( " giraffe " ) ; NEW_LINE findMostOccurringChar ( string ) ; NEW_LINE DEDENT


import java . util . * ; import java . io . * ; class GFG { static int maxSum ( int arr [ ] , int n ) { int res = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int curr_sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int index = ( i + j ) % n ; curr_sum += j * arr [ index ] ; } res = Math . max ( res , curr_sum ) ; } return res ; } public static void main ( String args [ ] ) { int arr [ ] = { 8 , 3 , 1 , 2 } ; int n = arr . length ; System . out . println ( maxSum ( arr , n ) ) ; } }

import sys NEW_LINE def maxSum ( arr , n ) : NEW_LINE INDENT res = - sys . maxsize NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT curr_sum = 0 NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT index = int ( ( i + j ) % n ) NEW_LINE curr_sum += j * arr [ index ] NEW_LINE DEDENT res = max ( res , curr_sum ) NEW_LINE DEDENT return res NEW_LINE DEDENT arr = [ 8 , 3 , 1 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxSum ( arr , n ) ) NEW_LINE


import java . util . * ; class GFG { static ArrayList < Integer > primes = new ArrayList < Integer > ( ) ; static void SieveofEratosthenes ( int n ) { boolean [ ] visited = new boolean [ n * n + 2 ] ; for ( int i = 2 ; i <= n + 1 ; i ++ ) if ( ! visited [ i ] ) { for ( int j = i * i ; j <= n + 1 ; j += i ) visited [ j ] = true ; primes . add ( i ) ; } } static boolean specialPrimeNumbers ( int n , int k ) { SieveofEratosthenes ( n ) ; int count = 0 ; for ( int i = 0 ; i < primes . size ( ) ; i ++ ) { for ( int j = 0 ; j < i - 1 ; j ++ ) { if ( primes . get ( j ) + primes . get ( j + 1 ) + 1 == primes . get ( i ) ) { count ++ ; break ; } } if ( count == k ) return true ; } return false ; } public static void main ( String [ ] args ) { int n = 27 , k = 2 ; if ( specialPrimeNumbers ( n , k ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

primes = [ ] ; NEW_LINE def SieveofEratosthenes ( n ) : NEW_LINE INDENT visited = [ False ] * ( n + 2 ) ; NEW_LINE for i in range ( 2 , n + 2 ) : NEW_LINE INDENT if ( visited [ i ] == False ) : NEW_LINE INDENT for j in range ( i * i , n + 2 , i ) : NEW_LINE INDENT visited [ j ] = True ; NEW_LINE DEDENT primes . append ( i ) ; NEW_LINE DEDENT DEDENT DEDENT def specialPrimeNumbers ( n , k ) : NEW_LINE INDENT SieveofEratosthenes ( n ) ; NEW_LINE count = 0 ; NEW_LINE for i in range ( len ( primes ) ) : NEW_LINE INDENT for j in range ( i - 1 ) : NEW_LINE INDENT if ( primes [ j ] + primes [ j + 1 ] + 1 == primes [ i ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE break ; NEW_LINE DEDENT DEDENT if ( count == k ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT n = 27 ; NEW_LINE k = 2 ; NEW_LINE if ( specialPrimeNumbers ( n , k ) ) : NEW_LINE INDENT print ( " YES " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int setBits ( int n ) { int count = 0 ; while ( n > 0 ) { n = n & ( n - 1 ) ; count ++ ; } return count ; } static int countPairs ( int a [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int setbits_x = setBits ( a [ i ] ) ; for ( int j = i + 1 ; j < n ; j ++ ) { int setbits_y = setBits ( a [ j ] ) ; int setbits_xor_xy = setBits ( a [ i ] ^ a [ j ] ) ; if ( setbits_x + setbits_y == setbits_xor_xy ) count ++ ; } } return count ; } public static void main ( String [ ] args ) { int [ ] a = { 2 , 3 , 4 , 5 , 6 } ; int n = a . length ; System . out . println ( countPairs ( a , n ) ) ; } }

def setBits ( n ) : NEW_LINE INDENT count = 0 NEW_LINE while ( n ) : NEW_LINE INDENT n = n & ( n - 1 ) NEW_LINE count += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def countPairs ( a , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , n - 1 , 1 ) : NEW_LINE INDENT setbits_x = setBits ( a [ i ] ) NEW_LINE for j in range ( i + 1 , n , 1 ) : NEW_LINE INDENT setbits_y = setBits ( a [ j ] ) NEW_LINE setbits_xor_xy = setBits ( a [ i ] ^ a [ j ] ) ; NEW_LINE if ( setbits_x + setbits_y == setbits_xor_xy ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 2 , 3 , 4 , 5 , 6 ] NEW_LINE n = len ( a ) NEW_LINE print ( countPairs ( a , n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int distinctCount ( int arr [ ] , int n ) { Set < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . add ( Math . abs ( arr [ i ] ) ) ; return s . size ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , - 1 , 0 , 1 , 1 } ; int n = arr . length ; System . out . println ( " Count ▁ of ▁ absolute ▁ distinct ▁ values ▁ : ▁ " + distinctCount ( arr , n ) ) ; } }

def distinctCount ( arr , n ) : NEW_LINE INDENT s = set ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT s . add ( abs ( arr [ i ] ) ) NEW_LINE DEDENT return len ( s ) NEW_LINE DEDENT arr = [ - 2 , - 1 , 0 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Count ▁ of ▁ absolute ▁ distinct ▁ values : " , distinctCount ( arr , n ) ) NEW_LINE


import java . io . * ; import java . util . * ; class GFG { static int countSubseq ( int arr [ ] , int n ) { int count = 0 ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( mp . containsKey ( arr [ i ] ) ) mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; else mp . put ( arr [ i ] , 1 ) ; for ( Map . Entry < Integer , Integer > entry : mp . entrySet ( ) ) { if ( entry . getKey ( ) == 0 ) count += Math . pow ( 2 , entry . getValue ( ) ) - 1 ; else count += Math . pow ( 2 , entry . getValue ( ) - 1 ) ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 2 , 5 , 6 } ; int n = arr . length ; System . out . println ( countSubseq ( arr , n ) ) ; } }

def countSubseq ( arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE mp = { } NEW_LINE for x in arr : NEW_LINE INDENT if x in mp . keys ( ) : NEW_LINE INDENT mp [ x ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ x ] = 1 NEW_LINE DEDENT DEDENT for i in mp . keys ( ) : NEW_LINE INDENT if ( i == 0 ) : NEW_LINE INDENT count += pow ( 2 , mp [ i ] ) - 1 NEW_LINE DEDENT else : NEW_LINE INDENT count += pow ( 2 , mp [ i ] - 1 ) NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT arr = [ 2 , 2 , 2 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE print ( countSubseq ( arr , n ) ) NEW_LINE


class GFG { static void bin ( int n ) { if ( n > 1 ) bin ( n / 2 ) ; System . out . print ( n % 2 ) ; } public static void main ( String [ ] args ) { bin ( 7 ) ; System . out . println ( ) ; bin ( 4 ) ; } }

def bin ( n ) : NEW_LINE INDENT if n > 1 : NEW_LINE INDENT bin ( n // 2 ) NEW_LINE DEDENT print ( n % 2 , end = " " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT bin ( 7 ) NEW_LINE print ( ) NEW_LINE bin ( 4 ) NEW_LINE DEDENT


class GFG { public static void main ( String [ ] args ) { char i ; System . out . printf ( " The ▁ Alphabets ▁ from ▁ A ▁ to ▁ Z ▁ are : ▁ \n " ) ; for ( i = ' A ' ; i <= ' Z ' ; i ++ ) { System . out . printf ( " % c ▁ " , i ) ; } } }

if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT i = chr ; NEW_LINE print ( " The ▁ Alphabets ▁ from ▁ A ▁ to ▁ Z ▁ are : ▁ " ) ; NEW_LINE for i in range ( ord ( ' A ' ) , ord ( ' Z ' ) + 1 ) : NEW_LINE INDENT print ( chr ( i ) , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT


class GFG { static void findSubsequence ( int arr [ ] , int n ) { int sign [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) sign [ i ] = 1 ; else sign [ i ] = - 1 ; } int k = 0 ; int result [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int cur = arr [ i ] ; int j = i ; while ( j < n && sign [ i ] == sign [ j ] ) { cur = Math . max ( cur , arr [ j ] ) ; ++ j ; } result [ k ++ ] = cur ; i = j - 1 ; } for ( int i = 0 ; i < k ; i ++ ) System . out . print ( result [ i ] + " ▁ " ) ; System . out . print ( " \n " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 4 , 9 , 4 , 11 , - 5 , - 17 , 9 , - 3 , - 5 , 2 } ; int n = arr . length ; findSubsequence ( arr , n ) ; } }

def findSubsequence ( arr , n ) : NEW_LINE INDENT sign = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT sign [ i ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT sign [ i ] = - 1 NEW_LINE DEDENT DEDENT k = 0 NEW_LINE result = [ 0 ] * n NEW_LINE i = 0 NEW_LINE while i < n : NEW_LINE INDENT cur = arr [ i ] NEW_LINE j = i NEW_LINE while ( j < n and sign [ i ] == sign [ j ] ) : NEW_LINE INDENT cur = max ( cur , arr [ j ] ) NEW_LINE j += 1 NEW_LINE DEDENT result [ k ] = cur NEW_LINE k += 1 NEW_LINE i = j - 1 NEW_LINE i += 1 NEW_LINE DEDENT for i in range ( k ) : NEW_LINE INDENT print ( result [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 4 , 9 , 4 , 11 , - 5 , - 17 , 9 , - 3 , - 5 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE findSubsequence ( arr , n ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; class GFG { static void nearestGcd ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; ++ i ) { int closest = - 1 ; for ( int j = i - 1 , k = i + 1 ; j > 0 || k <= n ; -- j , ++ k ) { if ( j >= 0 && __gcd ( arr [ i ] , arr [ j ] ) > 1 ) { closest = j + 1 ; break ; } if ( k < n && __gcd ( arr [ i ] , arr [ k ] ) > 1 ) { closest = k + 1 ; break ; } } System . out . print ( closest + " ▁ " ) ; } } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 2 , 9 , 4 , 3 , 13 } ; int n = arr . length ; nearestGcd ( arr , n ) ; } }

import math NEW_LINE def nearestGcd ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT closest = - 1 NEW_LINE j = i - 1 NEW_LINE k = i + 1 NEW_LINE while j > 0 or k <= n : NEW_LINE INDENT if ( j >= 0 and math . gcd ( arr [ i ] , arr [ j ] ) > 1 ) : NEW_LINE INDENT closest = j + 1 NEW_LINE break NEW_LINE DEDENT if ( k < n and math . gcd ( arr [ i ] , arr [ k ] ) > 1 ) : NEW_LINE INDENT closest = k + 1 NEW_LINE break NEW_LINE DEDENT k += 1 NEW_LINE j -= 1 NEW_LINE DEDENT print ( closest , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 9 , 4 , 3 , 13 ] NEW_LINE n = len ( arr ) NEW_LINE nearestGcd ( arr , n ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void printDiamond ( int n ) { int space = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < space ; j ++ ) System . out . print ( " ▁ " ) ; for ( int j = 0 ; j <= i ; j ++ ) System . out . print ( " * ▁ " ) ; System . out . print ( " \n " ) ; space -- ; } space = 0 ; for ( int i = n ; i > 0 ; i -- ) { for ( int j = 0 ; j < space ; j ++ ) System . out . print ( " ▁ " ) ; for ( int j = 0 ; j < i ; j ++ ) System . out . print ( " * ▁ " ) ; System . out . print ( " \n " ) ; space ++ ; } } public static void main ( String [ ] args ) { printDiamond ( 5 ) ; } }

def Diamond ( rows ) : NEW_LINE INDENT n = 0 NEW_LINE for i in range ( 1 , rows + 1 ) : NEW_LINE INDENT for j in range ( 1 , ( rows - i ) + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT while n != ( 2 * i - 1 ) : NEW_LINE INDENT print ( " * " , end = " " ) NEW_LINE n = n + 1 NEW_LINE DEDENT n = 0 NEW_LINE print ( ) NEW_LINE DEDENT k = 1 NEW_LINE n = 1 NEW_LINE for i in range ( 1 , rows ) : NEW_LINE INDENT for j in range ( 1 , k + 1 ) : NEW_LINE INDENT print ( end = " ▁ " ) NEW_LINE DEDENT k = k + 1 NEW_LINE while n <= ( 2 * ( rows - i ) - 1 ) : NEW_LINE INDENT print ( " * " , end = " " ) NEW_LINE n = n + 1 NEW_LINE DEDENT n = 1 NEW_LINE print ( ) NEW_LINE DEDENT DEDENT rows = 5 NEW_LINE Diamond ( rows ) NEW_LINE


import java . util . * ; class GFG { static void SieveOfEratosthenes ( boolean prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int gcdPrimeFreq ( int arr [ ] , int n ) { boolean [ ] prime = new boolean [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , n + 1 ) ; int i , j ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } int gcd = 0 ; for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( prime [ it . getValue ( ) ] ) { gcd = __gcd ( gcd , it . getKey ( ) ) ; } } return gcd ; } static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static public void main ( String [ ] arg ) { int arr [ ] = { 5 , 4 , 6 , 5 , 4 , 6 } ; int n = arr . length ; System . out . println ( gcdPrimeFreq ( arr , n ) ) ; } }

from math import sqrt , gcd NEW_LINE def SieveOfEratosthenes ( prime , p_size ) : NEW_LINE INDENT prime [ 0 ] = False ; NEW_LINE prime [ 1 ] = False ; NEW_LINE for p in range ( 2 , int ( sqrt ( p_size ) ) + 1 ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT for i in range ( 2 * p , p_size , p ) : NEW_LINE INDENT prime [ i ] = False ; NEW_LINE DEDENT DEDENT DEDENT DEDENT def gcdPrimeFreq ( arr , n ) : NEW_LINE INDENT prime = [ True ] * ( n + 1 ) ; NEW_LINE SieveOfEratosthenes ( prime , n + 1 ) ; NEW_LINE m = dict . fromkeys ( arr , 0 ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ arr [ i ] ] += 1 ; NEW_LINE DEDENT __gcd = 0 ; NEW_LINE for key , value in m . items ( ) : NEW_LINE INDENT if ( prime [ value ] ) : NEW_LINE INDENT __gcd = gcd ( __gcd , key ) ; NEW_LINE DEDENT DEDENT return __gcd ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 5 , 4 , 6 , 5 , 4 , 6 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( gcdPrimeFreq ( arr , n ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static final int N = 10005 ; static void SieveOfEratosthenes ( Vector < Boolean > composite ) { for ( int i = 0 ; i < N ; i ++ ) { composite . add ( i , false ) ; } for ( int p = 2 ; p * p < N ; p ++ ) { if ( ! composite . get ( p ) ) { for ( int i = p * 2 ; i < N ; i += p ) { composite . add ( i , true ) ; } } } } static int sumOfElements ( int arr [ ] , int n ) { Vector < Boolean > composite = new Vector < Boolean > ( ) ; for ( int i = 0 ; i < N ; i ++ ) composite . add ( false ) ; SieveOfEratosthenes ( composite ) ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } int sum = 0 ; for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( composite . get ( it . getValue ( ) ) ) { sum += ( it . getKey ( ) ) ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 1 , 1 , 1 , 3 , 3 , 2 , 4 } ; int n = arr . length ; System . out . print ( sumOfElements ( arr , n ) ) ; } }

N = 100005 NEW_LINE def SieveOfEratosthenes ( composite ) : NEW_LINE INDENT for p in range ( 2 , N ) : NEW_LINE INDENT if p * p > N : NEW_LINE INDENT break NEW_LINE DEDENT if ( composite [ p ] == False ) : NEW_LINE INDENT for i in range ( 2 * p , N , p ) : NEW_LINE INDENT composite [ i ] = True NEW_LINE DEDENT DEDENT DEDENT DEDENT def sumOfElements ( arr , n ) : NEW_LINE INDENT composite = [ False ] * N NEW_LINE SieveOfEratosthenes ( composite ) NEW_LINE m = dict ( ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT m [ arr [ i ] ] = m . get ( arr [ i ] , 0 ) + 1 NEW_LINE DEDENT sum = 0 NEW_LINE for it in m : NEW_LINE INDENT if ( composite [ m [ it ] ] ) : NEW_LINE INDENT sum += ( it ) NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 1 , 1 , 1 , 3 , 3 , 2 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE print ( sumOfElements ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; import java . util . * ; import java . lang . Math ; class LIS { static int CeilIndex ( int A [ ] , int l , int r , int key ) { while ( r - l > 1 ) { int m = l + ( r - l ) / 2 ; if ( A [ m ] >= key ) r = m ; else l = m ; } return r ; } static int LongestIncreasingSubsequenceLength ( int A [ ] , int size ) { int [ ] tailTable = new int [ size ] ; int len ; tailTable [ 0 ] = A [ 0 ] ; len = 1 ; for ( int i = 1 ; i < size ; i ++ ) { if ( A [ i ] < tailTable [ 0 ] ) tailTable [ 0 ] = A [ i ] ; else if ( A [ i ] > tailTable [ len - 1 ] ) tailTable [ len ++ ] = A [ i ] ; else tailTable [ CeilIndex ( tailTable , - 1 , len - 1 , A [ i ] ) ] = A [ i ] ; } return len ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 5 , 3 , 7 , 11 , 8 , 10 , 13 , 6 } ; int n = A . length ; System . out . println ( " Length ▁ of ▁ Longest ▁ Increasing ▁ Subsequence ▁ is ▁ " + LongestIncreasingSubsequenceLength ( A , n ) ) ; } }

def CeilIndex ( A , l , r , key ) : NEW_LINE INDENT while ( r - l > 1 ) : NEW_LINE INDENT m = l + ( r - l ) // 2 NEW_LINE if ( A [ m ] >= key ) : NEW_LINE INDENT r = m NEW_LINE DEDENT else : NEW_LINE INDENT l = m NEW_LINE DEDENT DEDENT return r NEW_LINE DEDENT def LongestIncreasingSubsequenceLength ( A , size ) : NEW_LINE INDENT tailTable = [ 0 for i in range ( size + 1 ) ] NEW_LINE len = 0 NEW_LINE tailTable [ 0 ] = A [ 0 ] NEW_LINE len = 1 NEW_LINE for i in range ( 1 , size ) : NEW_LINE INDENT if ( A [ i ] < tailTable [ 0 ] ) : NEW_LINE INDENT tailTable [ 0 ] = A [ i ] NEW_LINE DEDENT elif ( A [ i ] > tailTable [ len - 1 ] ) : NEW_LINE INDENT tailTable [ len ] = A [ i ] NEW_LINE len += 1 NEW_LINE DEDENT else : NEW_LINE INDENT tailTable [ CeilIndex ( tailTable , - 1 , len - 1 , A [ i ] ) ] = A [ i ] NEW_LINE DEDENT DEDENT return len NEW_LINE DEDENT A = [ 2 , 5 , 3 , 7 , 11 , 8 , 10 , 13 , 6 ] NEW_LINE n = len ( A ) NEW_LINE print ( " Length ▁ of ▁ Longest ▁ Increasing ▁ Subsequence ▁ is ▁ " , LongestIncreasingSubsequenceLength ( A , n ) ) NEW_LINE


class GFG { static int subsetCount ( int arr [ ] , int n ) { return 1 << n ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 } ; int n = A . length ; System . out . println ( subsetCount ( A , n ) ) ; } }

import math NEW_LINE def subsetCount ( arr , n ) : NEW_LINE INDENT return 1 << n NEW_LINE DEDENT A = [ 1 , 2 , 3 ] NEW_LINE n = len ( A ) NEW_LINE print ( subsetCount ( A , n ) ) NEW_LINE


import java . util . * ; class GFG { static int cntSubSeq ( int arr [ ] , int n ) { int pos_count = 0 ; int neg_count = 0 ; int result ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = ( int ) Math . pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= Math . pow ( 2 , neg_count - 1 ) ; result -= 1 ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , - 3 , - 1 , 4 } ; int n = arr . length ; System . out . print ( cntSubSeq ( arr , n ) ) ; } }

import math NEW_LINE def cntSubSeq ( arr , n ) : NEW_LINE INDENT pos_count = 0 ; NEW_LINE neg_count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT pos_count += 1 NEW_LINE DEDENT if ( arr [ i ] < 0 ) : NEW_LINE INDENT neg_count += 1 NEW_LINE DEDENT DEDENT result = int ( math . pow ( 2 , pos_count ) ) NEW_LINE if ( neg_count > 0 ) : NEW_LINE INDENT result *= int ( math . pow ( 2 , neg_count - 1 ) ) NEW_LINE DEDENT result -= 1 NEW_LINE return result NEW_LINE DEDENT arr = [ 2 , - 3 , - 1 , 4 ] NEW_LINE n = len ( arr ) ; NEW_LINE print ( cntSubSeq ( arr , n ) ) NEW_LINE


class GFG { static boolean existsTriplet ( int a [ ] , int b [ ] , int c [ ] , int x , int l1 , int l2 , int l3 ) { if ( l2 <= l1 && l2 <= l3 ) { swap ( l2 , l1 ) ; swap ( a , b ) ; } else if ( l3 <= l1 && l3 <= l2 ) { swap ( l3 , l1 ) ; swap ( a , c ) ; } for ( int i = 0 ; i < l1 ; i ++ ) { int j = 0 , k = l3 - 1 ; while ( j < l2 && k >= 0 ) { if ( a [ i ] + b [ j ] + c [ k ] == x ) return true ; if ( a [ i ] + b [ j ] + c [ k ] < x ) j ++ ; else k -- ; } } return false ; } private static void swap ( int x , int y ) { int temp = x ; x = y ; y = temp ; } private static void swap ( int [ ] x , int [ ] y ) { int [ ] temp = x ; x = y ; y = temp ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 7 , 8 , 10 , 15 } ; int b [ ] = { 1 , 6 , 7 , 8 } ; int c [ ] = { 4 , 5 , 5 } ; int l1 = a . length ; int l2 = b . length ; int l3 = c . length ; int x = 14 ; if ( existsTriplet ( a , b , c , x , l1 , l2 , l3 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def existsTriplet ( a , b , c , x , l1 , l2 , l3 ) : NEW_LINE INDENT if ( l2 <= l1 and l2 <= l3 ) : NEW_LINE INDENT l1 , l2 = l2 , l1 NEW_LINE a , b = b , a NEW_LINE DEDENT elif ( l3 <= l1 and l3 <= l2 ) : NEW_LINE INDENT l1 , l3 = l3 , l1 NEW_LINE a , c = c , a NEW_LINE DEDENT for i in range ( l1 ) : NEW_LINE INDENT j = 0 NEW_LINE k = l3 - 1 NEW_LINE while ( j < l2 and k >= 0 ) : NEW_LINE INDENT if ( a [ i ] + b [ j ] + c [ k ] == x ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( a [ i ] + b [ j ] + c [ k ] < x ) : NEW_LINE INDENT j += 1 NEW_LINE DEDENT else : NEW_LINE INDENT k -= 1 NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE DEDENT a = [ 2 , 7 , 8 , 10 , 15 ] NEW_LINE b = [ 1 , 6 , 7 , 8 ] NEW_LINE c = [ 4 , 5 , 5 ] NEW_LINE l1 = len ( a ) NEW_LINE l2 = len ( b ) NEW_LINE l3 = len ( c ) NEW_LINE x = 14 NEW_LINE if ( existsTriplet ( a , b , c , x , l1 , l2 , l3 ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class Solution { static int max_element ( int A [ ] ) { int max = Integer . MIN_VALUE ; for ( int i = 0 ; i < A . length ; i ++ ) if ( max < A [ i ] ) max = A [ i ] ; return max ; } static void SumDivPrime ( int A [ ] , int n ) { int max_val = ( max_element ( A ) ) + 1 ; boolean prime [ ] = new boolean [ max_val + 1 ] ; for ( int i = 0 ; i <= max_val ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( prime [ A [ i ] ] ) sum += A [ i ] ; } for ( int i = 0 ; i < n ; ++ i ) { if ( prime [ A [ i ] ] && sum % A [ i ] == 0 ) { System . out . println ( " YES " ) ; return ; } } System . out . println ( " NO " ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = A . length ; SumDivPrime ( A , n ) ; } }

import math NEW_LINE def SumDivPrime ( A , n ) : NEW_LINE INDENT max_val = max ( A ) + 1 NEW_LINE prime = [ True ] * ( max_val + 1 ) NEW_LINE prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE for p in range ( 2 , int ( math . sqrt ( max_val ) ) + 1 ) : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT for i in range ( 2 * p , max_val + 1 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT sum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if prime [ A [ i ] ] : NEW_LINE INDENT sum += A [ i ] NEW_LINE DEDENT DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT if prime [ A [ i ] ] and sum % A [ i ] == 0 : NEW_LINE INDENT print ( " YES " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " NO " ) NEW_LINE DEDENT A = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE n = len ( A ) NEW_LINE SumDivPrime ( A , n ) NEW_LINE


class GFG { static void printNcR ( int n , int r ) { long p = 1 , k = 1 ; if ( n - r < r ) { r = n - r ; } if ( r != 0 ) { while ( r > 0 ) { p *= n ; k *= r ; long m = __gcd ( p , k ) ; p /= m ; k /= m ; n -- ; r -- ; } } else { p = 1 ; } System . out . println ( p ) ; } static long __gcd ( long n1 , long n2 ) { long gcd = 1 ; for ( int i = 1 ; i <= n1 && i <= n2 ; ++ i ) { if ( n1 % i == 0 && n2 % i == 0 ) { gcd = i ; } } return gcd ; } public static void main ( String [ ] args ) { int n = 50 , r = 25 ; printNcR ( n , r ) ; } }

from math import * NEW_LINE def printNcR ( n , r ) : NEW_LINE INDENT p = 1 NEW_LINE k = 1 NEW_LINE if ( n - r < r ) : NEW_LINE INDENT r = n - r NEW_LINE DEDENT if ( r != 0 ) : NEW_LINE INDENT while ( r ) : NEW_LINE INDENT p *= n NEW_LINE k *= r NEW_LINE m = gcd ( p , k ) NEW_LINE p //= m NEW_LINE k //= m NEW_LINE n -= 1 NEW_LINE r -= 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT p = 1 NEW_LINE DEDENT print ( p ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 50 NEW_LINE r = 25 NEW_LINE printNcR ( n , r ) NEW_LINE DEDENT


import java . util . Arrays ; import java . io . * ; class GFG { static int CalculateMax ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int min_sum = arr [ 0 ] + arr [ 1 ] ; int max_sum = arr [ n - 1 ] + arr [ n - 2 ] ; return ( Math . abs ( max_sum - min_sum ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 7 , 1 , 11 } ; int n = arr . length ; System . out . println ( CalculateMax ( arr , n ) ) ; } }

def CalculateMax ( arr , n ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE min_sum = arr [ 0 ] + arr [ 1 ] NEW_LINE max_sum = arr [ n - 1 ] + arr [ n - 2 ] NEW_LINE return abs ( max_sum - min_sum ) NEW_LINE DEDENT arr = [ 6 , 7 , 1 , 11 ] NEW_LINE n = len ( arr ) NEW_LINE print ( CalculateMax ( arr , n ) ) NEW_LINE


class GFG { static long sumOfDigits ( long n ) { long sum = 0 ; while ( n > 0 ) { sum += n % 10 ; n /= 10 ; } return sum ; } static long countDigits ( long num , long limit ) { long left = 1 , right = num , result = 0 ; while ( left <= right ) { long mid = ( right + left ) / 2 ; if ( ( mid - sumOfDigits ( mid ) ) >= limit ) { result = num - mid + 1 ; right = mid - 1 ; } else { left = mid + 1 ; } } return result ; } public static void main ( String [ ] args ) { long N = 1546300 , L = 30651 ; System . out . println ( countDigits ( N , L ) ) ; } }

def sumOfDigits ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT sum += n % 10 NEW_LINE n = int ( n / 10 ) NEW_LINE DEDENT return sum NEW_LINE DEDENT def countDigits ( num , limit ) : NEW_LINE INDENT left = 1 NEW_LINE right = num NEW_LINE result = 0 NEW_LINE while ( left <= right ) : NEW_LINE INDENT mid = int ( ( right + left ) / 2 ) NEW_LINE if ( ( mid - sumOfDigits ( mid ) ) >= limit ) : NEW_LINE INDENT result = num - mid + 1 NEW_LINE right = mid - 1 NEW_LINE DEDENT else : NEW_LINE INDENT left = mid + 1 NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 1546300 NEW_LINE L = 30651 NEW_LINE print ( countDigits ( N , L ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static class Node { int data ; Node left , right ; Node ( int val ) { data = val ; left = null ; right = null ; } } ; static void spiralOrder ( Node root ) { Deque < Node > d = new LinkedList < Node > ( ) ; d . addLast ( root ) ; int dir = 0 ; while ( d . size ( ) > 0 ) { int size = d . size ( ) ; while ( size -- > 0 ) { if ( dir == 0 ) { Node temp = d . peekLast ( ) ; d . pollLast ( ) ; if ( temp . right != null ) d . addFirst ( temp . right ) ; if ( temp . left != null ) d . addFirst ( temp . left ) ; System . out . print ( temp . data + " ▁ " ) ; } else { Node temp = d . peekFirst ( ) ; d . pollFirst ( ) ; if ( temp . left != null ) d . addLast ( temp . left ) ; if ( temp . right != null ) d . addLast ( temp . right ) ; System . out . print ( temp . data + " ▁ " ) ; } } System . out . println ( ) ; dir = 1 - dir ; } } public static void main ( String args [ ] ) { Node root = new Node ( 10 ) ; root . left = new Node ( 20 ) ; root . right = new Node ( 30 ) ; root . left . left = new Node ( 40 ) ; root . left . right = new Node ( 60 ) ; spiralOrder ( root ) ; } }

class Node : NEW_LINE INDENT def __init__ ( self , val ) : NEW_LINE INDENT self . data = val ; NEW_LINE self . left = None ; NEW_LINE self . right = None ; NEW_LINE DEDENT DEDENT def spiralOrder ( root ) : NEW_LINE INDENT d = [ ] ; NEW_LINE d . append ( root ) ; NEW_LINE direct = 0 ; NEW_LINE while ( len ( d ) != 0 ) : NEW_LINE INDENT size = len ( d ) ; NEW_LINE while ( size ) : NEW_LINE INDENT size -= 1 ; NEW_LINE if ( direct == 0 ) : NEW_LINE INDENT temp = d . pop ( ) ; NEW_LINE if ( temp . right ) : NEW_LINE INDENT d . insert ( 0 , temp . right ) ; NEW_LINE DEDENT if ( temp . left ) : NEW_LINE INDENT d . insert ( 0 , temp . left ) ; NEW_LINE DEDENT print ( temp . data , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT temp = d [ 0 ] ; NEW_LINE d . pop ( 0 ) ; NEW_LINE if ( temp . left ) : NEW_LINE INDENT d . append ( temp . left ) ; NEW_LINE DEDENT if ( temp . right ) : NEW_LINE INDENT d . append ( temp . right ) ; NEW_LINE DEDENT print ( temp . data , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( ) NEW_LINE direct = 1 - direct ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT root = Node ( 10 ) ; NEW_LINE root . left = Node ( 20 ) ; NEW_LINE root . right = Node ( 30 ) ; NEW_LINE root . left . left = Node ( 40 ) ; NEW_LINE root . left . right = Node ( 60 ) ; NEW_LINE spiralOrder ( root ) ; NEW_LINE DEDENT


class GFG { public static boolean strcheck ( String s1 , String s2 ) { if ( s1 . compareTo ( s2 ) != 0 ) return false ; return true ; } public static boolean check ( String s ) { if ( s . length ( ) >= 10 ) return true ; for ( int i = 1 ; i < s . length ( ) ; i ++ ) { for ( int j = i + 1 ; j < s . length ( ) ; j ++ ) { for ( int k = j + 1 ; k < s . length ( ) ; k ++ ) { String s1 = " " , s2 = " " , s3 = " " , s4 = " " ; try { s1 = s . substring ( 0 , i ) ; s2 = s . substring ( i , j - i ) ; s3 = s . substring ( j , k - j ) ; s4 = s . substring ( k , s . length ( ) - k ) ; } catch ( StringIndexOutOfBoundsException e ) { } if ( strcheck ( s1 , s2 ) && strcheck ( s1 , s3 ) && strcheck ( s1 , s4 ) && strcheck ( s2 , s3 ) && strcheck ( s2 , s4 ) && strcheck ( s3 , s4 ) ) return true ; } } } return false ; } public static void main ( String [ ] args ) { String str = " aaabb " ; if ( check ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def check ( s ) : NEW_LINE INDENT if ( len ( s ) >= 10 ) : NEW_LINE INDENT return True NEW_LINE DEDENT for i in range ( 1 , len ( s ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( s ) ) : NEW_LINE INDENT for k in range ( j + 1 , len ( s ) ) : NEW_LINE INDENT s1 = s [ 0 : i ] NEW_LINE s2 = s [ i : j - i ] NEW_LINE s3 = s [ j : k - j ] NEW_LINE s4 = s [ k : len ( s ) - k ] NEW_LINE if ( s1 != s2 and s1 != s3 and s1 != s4 and s2 != s3 and s2 != s4 and s3 != s4 ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = " aaabb " NEW_LINE print ( " Yes " ) if ( check ( str ) ) else print ( " NO " ) NEW_LINE DEDENT


static int mod ( int a , int m ) { return ( a % m + m ) % m ; }

def mod ( a , m ) : NEW_LINE INDENT return ( a % m + m ) % m NEW_LINE DEDENT


import static java . lang . Math . * ; class GFG { static int sumofsquare ( int n ) { int [ ] [ ] C = new int [ n + 1 ] [ n + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= min ( i , n ) ; j ++ ) { if ( j == 0 || j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } int sum = 0 ; for ( i = 0 ; i <= n ; i ++ ) sum += ( C [ n ] [ i ] * C [ n ] [ i ] ) ; return sum ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( sumofsquare ( n ) ) ; } }

def sumofsquare ( n ) : NEW_LINE INDENT C = [ [ 0 for i in range ( n + 1 ) ] for j in range ( n + 1 ) ] NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT for j in range ( 0 , min ( i , n ) + 1 ) : NEW_LINE INDENT if ( j == 0 or j == i ) : NEW_LINE INDENT C [ i ] [ j ] = 1 NEW_LINE DEDENT else : NEW_LINE INDENT C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT sum = 0 NEW_LINE for i in range ( 0 , n + 1 ) : NEW_LINE INDENT sum = sum + ( C [ n ] [ i ] * C [ n ] [ i ] ) NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 4 NEW_LINE print ( sumofsquare ( n ) , end = " \n " ) NEW_LINE


import java . io . * ; class GFG { static double Area ( int b1 , int b2 , int h ) { return ( ( b1 + b2 ) / 2 ) * h ; } public static void main ( String [ ] args ) { int base1 = 8 , base2 = 10 , height = 6 ; double area = Area ( base1 , base2 , height ) ; System . out . println ( " Area ▁ is : ▁ " + area ) ; } }

def Area ( b1 , b2 , h ) : NEW_LINE INDENT return ( ( b1 + b2 ) / 2 ) * h NEW_LINE DEDENT base1 = 8 ; base2 = 10 ; height = 6 NEW_LINE area = Area ( base1 , base2 , height ) NEW_LINE print ( " Area ▁ is : " , area ) NEW_LINE


class GFG { static int MAXN = 100000 ; static int MOD = 1000000007 ; static long fact [ ] = new long [ MAXN ] ; static void factorial ( ) { fact [ 0 ] = 1 ; for ( int i = 1 ; i < MAXN ; i ++ ) fact [ i ] = ( fact [ i - 1 ] * i ) % MOD ; } static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long modInverse ( long x , long p ) { return power ( x , p - 2 , p ) ; } static long countDifferentNumbers ( long arr [ ] , long P ) { factorial ( ) ; long res = 0 , X = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) X += arr [ i ] ; res = fact [ ( int ) X ] ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( arr [ i ] > 1 ) res = ( res * modInverse ( fact [ ( int ) arr [ i ] ] , P ) ) % P ; } return res ; } public static void main ( String [ ] args ) { long arr [ ] = { 1 , 0 , 2 , 0 , 0 , 7 , 4 , 0 , 0 , 3 } ; System . out . println ( countDifferentNumbers ( arr , MOD ) ) ; } }

MAXN = 100000 NEW_LINE MOD = 1000000007 NEW_LINE fact = [ 0 ] * MAXN ; NEW_LINE def factorial ( ) : NEW_LINE INDENT fact [ 0 ] = 1 NEW_LINE for i in range ( 1 , MAXN ) : NEW_LINE INDENT fact [ i ] = ( fact [ i - 1 ] * i ) % MOD NEW_LINE DEDENT DEDENT def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 ; NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def modInverse ( x , p ) : NEW_LINE INDENT return power ( x , p - 2 , p ) NEW_LINE DEDENT def countDifferentNumbers ( arr , P ) : NEW_LINE INDENT factorial ( ) ; NEW_LINE res = 0 ; X = 0 ; NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT X += arr [ i ] NEW_LINE DEDENT res = fact [ X ] NEW_LINE for i in range ( 10 ) : NEW_LINE INDENT if ( arr [ i ] > 1 ) : NEW_LINE INDENT res = ( res * modInverse ( fact [ arr [ i ] ] , P ) ) % P ; NEW_LINE DEDENT DEDENT return res ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 0 , 2 , 0 , 0 , 7 , 4 , 0 , 0 , 3 ] NEW_LINE print ( countDifferentNumbers ( arr , MOD ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int count_pairs ( int a [ ] , int b [ ] , int n , int m ) { int odd1 = 0 , even1 = 0 ; int odd2 = 0 , even2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 1 ) odd1 ++ ; else even1 ++ ; } for ( int i = 0 ; i < m ; i ++ ) { if ( b [ i ] % 2 == 1 ) odd2 ++ ; else even2 ++ ; } int pairs = Math . min ( odd1 , odd2 ) + Math . min ( even1 , even2 ) ; return pairs ; } public static void main ( String [ ] args ) { int a [ ] = { 9 , 14 , 6 , 2 , 11 } ; int b [ ] = { 8 , 4 , 7 , 20 } ; int n = a . length ; int m = b . length ; System . out . println ( count_pairs ( a , b , n , m ) ) ; } }

def count_pairs ( a , b , n , m ) : NEW_LINE INDENT odd1 = 0 NEW_LINE even1 = 0 NEW_LINE odd2 = 0 NEW_LINE even2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] % 2 == 1 ) : NEW_LINE INDENT odd1 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT even1 += 1 NEW_LINE DEDENT DEDENT for i in range ( m ) : NEW_LINE INDENT if ( b [ i ] % 2 == 1 ) : NEW_LINE INDENT odd2 += 1 NEW_LINE DEDENT else : NEW_LINE INDENT even2 += 1 NEW_LINE DEDENT DEDENT pairs = min ( odd1 , odd2 ) + min ( even1 , even2 ) NEW_LINE return pairs NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 9 , 14 , 6 , 2 , 11 ] NEW_LINE b = [ 8 , 4 , 7 , 20 ] NEW_LINE n = len ( a ) NEW_LINE m = len ( b ) NEW_LINE print ( count_pairs ( a , b , n , m ) ) NEW_LINE DEDENT