class Test { static final double PI = Math . PI ; static double findArea ( int r ) { return PI * Math . pow ( r , 2 ) ; } public static void main ( String [ ] args ) { System . out . println ( " Area ▁ is ▁ " + findArea ( 5 ) ) ; } }

def findArea ( r ) : NEW_LINE INDENT PI = 3.142 NEW_LINE return PI * ( r * r ) ; NEW_LINE DEDENT print ( " Area ▁ is ▁ % .6f " % findArea ( 5 ) ) ; NEW_LINE


public class GFG { static boolean isProductEven ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & 1 ) == 0 ) return true ; return false ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 4 , 3 , 5 } ; int n = arr . length ; if ( isProductEven ( arr , n ) ) System . out . println ( " Even " ) ; else System . out . println ( " Odd " ) ; } }

def isProductEven ( arr , n ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT if ( ( arr [ i ] & 1 ) == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT arr = [ 2 , 4 , 3 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE if ( isProductEven ( arr , n ) ) : NEW_LINE INDENT print ( " Even " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Odd " ) NEW_LINE DEDENT


class GFG { static int cntWays ( int arr [ ] , int n ) { if ( n == 1 ) { return 0 ; } int tot_sum = 0 , sum = 0 , ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { tot_sum += arr [ i ] ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += arr [ i ] ; if ( sum == tot_sum / 2 ) { ans ++ ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , - 1 , 1 , - 1 , 1 , - 1 } ; int n = arr . length ; System . out . println ( cntWays ( arr , n ) ) ; } }

def cntWays ( arr , n ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT tot_sum = 0 ; sum = 0 ; ans = 0 ; NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT tot_sum += arr [ i ] ; NEW_LINE DEDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT sum += arr [ i ] ; NEW_LINE if ( sum == tot_sum / 2 ) : NEW_LINE INDENT ans += 1 ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT arr = [ 1 , - 1 , 1 , - 1 , 1 , - 1 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( cntWays ( arr , n ) ) ; NEW_LINE


import java . util . * ; class GFG { static void print ( int n , int k ) { System . out . print ( k + " ▁ " ) ; for ( int i = 2 ; i <= n ; i ++ ) { int x = ( int ) ( Math . pow ( k , i ) - Math . pow ( k , i - 1 ) ) ; System . out . print ( x + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 3 , K = 4 ; print ( N , K ) ; } }

from math import pow NEW_LINE def printf ( n , k ) : NEW_LINE INDENT print ( int ( k ) , end = " ▁ " ) NEW_LINE for i in range ( 2 , n + 1 , 1 ) : NEW_LINE INDENT x = pow ( k , i ) - pow ( k , i - 1 ) NEW_LINE print ( int ( x ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE K = 4 NEW_LINE printf ( N , K ) NEW_LINE DEDENT


import java . util . * ; class GfG { static long countWays ( int n , int k ) { long dp [ ] = new long [ n + 1 ] ; Arrays . fill ( dp , 0 ) ; int mod = 1000000007 ; dp [ 1 ] = k ; int same = 0 , diff = k ; for ( int i = 2 ; i <= n ; i ++ ) { same = diff ; diff = ( int ) ( dp [ i - 1 ] * ( k - 1 ) ) ; diff = diff % mod ; dp [ i ] = ( same + diff ) % mod ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 3 , k = 2 ; System . out . println ( countWays ( n , k ) ) ; } }

def countWays ( n , k ) : NEW_LINE INDENT dp = [ 0 ] * ( n + 1 ) NEW_LINE total = k NEW_LINE mod = 1000000007 NEW_LINE dp [ 1 ] = k NEW_LINE dp [ 2 ] = k * k NEW_LINE for i in range ( 3 , n + 1 ) : NEW_LINE INDENT dp [ i ] = ( ( k - 1 ) * ( dp [ i - 1 ] + dp [ i - 2 ] ) ) % mod NEW_LINE DEDENT return dp [ n ] NEW_LINE DEDENT n = 3 NEW_LINE k = 2 NEW_LINE print ( countWays ( n , k ) ) NEW_LINE


public class GFG { final static int MAX = 100 ; static void smallestInRow ( int mat [ ] [ ] , int n , int m ) { System . out . print ( " ▁ { ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { int minm = mat [ i ] [ 0 ] ; for ( int j = 1 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] < minm ) { minm = mat [ i ] [ j ] ; } } System . out . print ( minm + " , ▁ " ) ; } System . out . println ( " } " ) ; } static void smallestInCol ( int mat [ ] [ ] , int n , int m ) { System . out . print ( " ▁ { ▁ " ) ; for ( int i = 0 ; i < m ; i ++ ) { int minm = mat [ 0 ] [ i ] ; for ( int j = 1 ; j < n ; j ++ ) { if ( mat [ j ] [ i ] < minm ) { minm = mat [ j ] [ i ] ; } } System . out . print ( minm + " , ▁ " ) ; } System . out . print ( " } " ) ; } public static void main ( String args [ ] ) { int n = 3 , m = 3 ; int mat [ ] [ ] = { { 2 , 1 , 7 } , { 3 , 7 , 2 } , { 5 , 4 , 9 } } ; System . out . print ( " Minimum ▁ element ▁ of ▁ each ▁ row ▁ is ▁ " ) ; smallestInRow ( mat , n , m ) ; System . out . print ( " \n Minimum ▁ element ▁ of ▁ each ▁ column ▁ is ▁ " ) ; smallestInCol ( mat , n , m ) ; } }

MAX = 100 NEW_LINE def smallestInRow ( mat , n , m ) : NEW_LINE INDENT print ( " { " , end = " " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT minm = mat [ i ] [ 0 ] NEW_LINE for j in range ( 1 , m , 1 ) : NEW_LINE INDENT if ( mat [ i ] [ j ] < minm ) : NEW_LINE INDENT minm = mat [ i ] [ j ] NEW_LINE DEDENT DEDENT print ( minm , end = " , " ) NEW_LINE DEDENT print ( " } " ) NEW_LINE DEDENT def smallestInCol ( mat , n , m ) : NEW_LINE INDENT print ( " { " , end = " " ) NEW_LINE for i in range ( m ) : NEW_LINE INDENT minm = mat [ 0 ] [ i ] NEW_LINE for j in range ( 1 , n , 1 ) : NEW_LINE INDENT if ( mat [ j ] [ i ] < minm ) : NEW_LINE INDENT minm = mat [ j ] [ i ] NEW_LINE DEDENT DEDENT print ( minm , end = " , " ) NEW_LINE DEDENT print ( " } " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE m = 3 NEW_LINE mat = [ [ 2 , 1 , 7 ] , [ 3 , 7 , 2 ] , [ 5 , 4 , 9 ] ] ; NEW_LINE print ( " Minimum ▁ element ▁ of ▁ each ▁ row ▁ is " , end = " ▁ " ) NEW_LINE smallestInRow ( mat , n , m ) NEW_LINE print ( " Minimum ▁ element ▁ of ▁ each ▁ column ▁ is " , end = " ▁ " ) NEW_LINE smallestInCol ( mat , n , m ) NEW_LINE DEDENT


class GFG { static int MinOfCubed ( int k ) { if ( k < 8 ) return k ; int res = k ; for ( int i = 1 ; i <= k ; i ++ ) { if ( ( i * i * i ) > k ) return res ; res = Math . min ( res , MinOfCubed ( k - ( i * i * i ) ) + 1 ) ; } return res ; } public static void main ( String [ ] args ) { int num = 15 ; System . out . println ( MinOfCubed ( num ) ) ; } }

def MinOfCubed ( k ) : NEW_LINE INDENT if ( k < 8 ) : NEW_LINE INDENT return k ; NEW_LINE DEDENT res = k ; NEW_LINE for i in range ( 1 , k + 1 ) : NEW_LINE INDENT if ( ( i * i * i ) > k ) : NEW_LINE INDENT return res ; NEW_LINE DEDENT res = min ( res , MinOfCubed ( k - ( i * i * i ) ) + 1 ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT num = 15 ; NEW_LINE print ( MinOfCubed ( num ) ) ; NEW_LINE


import java . io . * ; class GFG { public static int countSetBits ( int n ) { if ( n == 0 ) return 0 ; else return ( n & 1 ) + countSetBits ( n >> 1 ) ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( countSetBits ( n ) ) ; } }

def countSetBits ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return ( n & 1 ) + countSetBits ( n >> 1 ) NEW_LINE DEDENT DEDENT n = 9 NEW_LINE print ( countSetBits ( n ) ) NEW_LINE


import java . io . * ; class GFG { static float findArea ( float a ) { float area ; area = ( float ) ( Math . sqrt ( 5 * ( 5 + 2 * ( Math . sqrt ( 5 ) ) ) ) * a * a ) / 4 ; return area ; } public static void main ( String [ ] args ) { float a = 5 ; System . out . println ( " Area ▁ of ▁ Pentagon : ▁ " + findArea ( a ) ) ; } }

from math import sqrt NEW_LINE def findArea ( a ) : NEW_LINE INDENT area = ( sqrt ( 5 * ( 5 + 2 * ( sqrt ( 5 ) ) ) ) * a * a ) / 4 NEW_LINE return area NEW_LINE DEDENT a = 5 NEW_LINE print ( " Area ▁ of ▁ Pentagon : ▁ " , findArea ( a ) ) NEW_LINE


import java . util . * ; class GFG { static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 || n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static int findSmallest ( int N ) { if ( N == 0 ) return 2 ; if ( N == 1 ) return 1 ; int prime = N , counter = 0 ; boolean found = false ; while ( ! found ) { if ( isPrime ( prime ) ) found = true ; else { prime ++ ; counter ++ ; } } return counter ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . print ( findSmallest ( N ) ) ; } }

def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = 5 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i += 6 NEW_LINE DEDENT return True NEW_LINE DEDENT def findSmallest ( N ) : NEW_LINE INDENT if ( N == 0 ) : NEW_LINE INDENT return 2 NEW_LINE DEDENT if ( N == 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT prime , counter = N , 0 NEW_LINE found = False NEW_LINE while ( not found ) : NEW_LINE INDENT if ( isPrime ( prime ) ) : NEW_LINE INDENT found = True NEW_LINE DEDENT else : NEW_LINE INDENT prime += 1 NEW_LINE counter += 1 NEW_LINE DEDENT DEDENT return counter NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 10 NEW_LINE print ( findSmallest ( N ) ) NEW_LINE DEDENT


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

def findSum ( n ) : NEW_LINE INDENT summ = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT summ = ( summ + ( ( i * ( i + 1 ) * ( 2 * i + 1 ) ) / 6 ) ) NEW_LINE DEDENT return summ NEW_LINE DEDENT n = 3 NEW_LINE print ( int ( findSum ( n ) ) ) NEW_LINE


import java . io . * ; class GFG { static void findAllTriplets ( int arr [ ] , int n ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { for ( int j = i - 1 , k = i + 1 ; j >= 0 && k < n ; ) { if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) { System . out . println ( arr [ j ] + " ▁ " + arr [ i ] + " ▁ " + arr [ k ] ) ; k ++ ; j -- ; } else if ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) k ++ ; else j -- ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = arr . length ; findAllTriplets ( arr , n ) ; } }

def printAllAPTriplets ( arr , n ) : NEW_LINE INDENT for i in range ( 1 , n - 1 ) : NEW_LINE INDENT j = i - 1 NEW_LINE k = i + 1 NEW_LINE while ( j >= 0 and k < n ) : NEW_LINE INDENT if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) : NEW_LINE INDENT print ( arr [ j ] , " " , arr [ i ] , " " , arr [ k ] ) NEW_LINE k += 1 NEW_LINE j -= 1 NEW_LINE DEDENT elif ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) : NEW_LINE INDENT k += 1 NEW_LINE DEDENT else : NEW_LINE INDENT j -= 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT arr = [ 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 ] NEW_LINE n = len ( arr ) NEW_LINE printAllAPTriplets ( arr , n ) NEW_LINE


class GFG { static int findDigitsInFactorial ( int n ) { if ( n < 0 ) return 0 ; if ( n <= 1 ) return 1 ; double x = ( ( n * Math . log10 ( n / Math . E ) + Math . log10 ( 2 * Math . PI * n ) / 2.0 ) ) ; return ( int ) ( Math . floor ( x ) + 1 ) ; } static int findNum ( int n ) { int low = 0 , hi = 2 * n ; if ( n <= 0 ) return - 1 ; if ( findDigitsInFactorial ( low ) == n ) return low ; while ( low <= hi ) { int mid = ( low + hi ) / 2 ; if ( findDigitsInFactorial ( mid ) >= n && findDigitsInFactorial ( mid - 1 ) < n ) return mid ; else if ( findDigitsInFactorial ( mid ) < n ) low = mid + 1 ; else hi = mid - 1 ; } return low ; } public static void main ( String [ ] args ) { System . out . println ( findNum ( 1 ) ) ; System . out . println ( findNum ( 2 ) ) ; System . out . println ( findNum ( 5 ) ) ; System . out . println ( findNum ( 24 ) ) ; System . out . println ( findNum ( 100 ) ) ; System . out . println ( findNum ( 1221 ) ) ; } }

import math NEW_LINE def findDigitsInFactorial ( n ) : NEW_LINE INDENT if ( n < 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( n <= 1 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT M_E = 2.7182818284590452354 NEW_LINE M_PI = 3.14159265358979323846 NEW_LINE x = ( ( n * math . log10 ( n / M_E ) + math . log10 ( 2 * M_PI * n ) / 2.0 ) ) NEW_LINE return int ( math . floor ( x ) + 1 ) NEW_LINE DEDENT def findNum ( n ) : NEW_LINE INDENT low = 0 NEW_LINE hi = 2 * n NEW_LINE if ( n <= 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT if ( findDigitsInFactorial ( low ) == n ) : NEW_LINE INDENT return int ( round ( low ) ) NEW_LINE DEDENT while ( low <= hi ) : NEW_LINE INDENT mid = int ( ( low + hi ) / 2 ) NEW_LINE if ( ( findDigitsInFactorial ( mid ) >= n and findDigitsInFactorial ( mid - 1 ) < n ) ) : NEW_LINE INDENT return int ( round ( mid ) ) NEW_LINE DEDENT elif ( findDigitsInFactorial ( mid ) < n ) : NEW_LINE INDENT low = mid + 1 NEW_LINE DEDENT else : NEW_LINE INDENT hi = mid - 1 NEW_LINE DEDENT DEDENT return int ( round ( low ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT print ( findNum ( 1 ) ) ; NEW_LINE print ( findNum ( 2 ) ) ; NEW_LINE print ( findNum ( 5 ) ) ; NEW_LINE print ( findNum ( 24 ) ) ; NEW_LINE print ( findNum ( 100 ) ) ; NEW_LINE print ( findNum ( 1221 ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean Prime ( int n ) { for ( int j = 2 ; j <= Math . sqrt ( n ) ; j ++ ) if ( n % j == 0 ) return false ; return true ; } static int find_prime ( int x , int xsqmodp , int y , int ysqmodp ) { int n = x * x - xsqmodp ; int n1 = y * y - ysqmodp ; for ( int j = 2 ; j <= Math . max ( Math . sqrt ( n ) , Math . sqrt ( n1 ) ) ; j ++ ) { if ( n % j == 0 && ( x * x ) % j == xsqmodp && n1 % j == 0 && ( y * y ) % j == ysqmodp ) if ( Prime ( j ) ) return j ; int j1 = n / j ; if ( n % j1 == 0 && ( x * x ) % j1 == xsqmodp && n1 % j1 == 0 && ( y * y ) % j1 == ysqmodp ) if ( Prime ( j1 ) ) return j1 ; j1 = n1 / j ; if ( n % j1 == 0 && ( x * x ) % j1 == xsqmodp && n1 % j1 == 0 && ( y * y ) % j1 == ysqmodp ) if ( Prime ( j1 ) ) return j1 ; } if ( n == n1 ) return n ; return Integer . MIN_VALUE ; } public static void main ( String [ ] args ) { int x = 3 , xsqmodp = 0 , y = 5 , ysqmodp = 1 ; System . out . println ( find_prime ( x , xsqmodp , y , ysqmodp ) ) ; } }

from math import sqrt NEW_LINE def Prime ( n ) : NEW_LINE INDENT for j in range ( 2 , int ( sqrt ( n ) ) + 1 , 1 ) : NEW_LINE INDENT if ( n % j == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def find_prime ( x , xsqmodp , y , ysqmodp ) : NEW_LINE INDENT n = x * x - xsqmodp NEW_LINE n1 = y * y - ysqmodp NEW_LINE for j in range ( 2 , max ( int ( sqrt ( n ) ) , int ( sqrt ( n1 ) ) ) , 1 ) : NEW_LINE INDENT if ( n % j == 0 and ( x * x ) % j == xsqmodp and n1 % j == 0 and ( y * y ) % j == ysqmodp ) : NEW_LINE INDENT if ( Prime ( j ) ) : NEW_LINE INDENT return j NEW_LINE DEDENT DEDENT j1 = n // j NEW_LINE if ( n % j1 == 0 and ( x * x ) % j1 == xsqmodp and n1 % j1 == 0 and ( y * y ) % j1 == ysqmodp ) : NEW_LINE INDENT if ( Prime ( j1 ) ) : NEW_LINE INDENT return j1 NEW_LINE DEDENT DEDENT j1 = n1 // j NEW_LINE if ( n % j1 == 0 and ( x * x ) % j1 == xsqmodp and n1 % j1 == 0 and ( y * y ) % j1 == ysqmodp ) : NEW_LINE INDENT if ( Prime ( j1 ) ) : NEW_LINE INDENT return j1 NEW_LINE DEDENT DEDENT DEDENT if ( n == n1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 3 NEW_LINE xsqmodp = 0 NEW_LINE y = 5 NEW_LINE ysqmodp = 1 NEW_LINE print ( find_prime ( x , xsqmodp , y , ysqmodp ) ) NEW_LINE DEDENT


import java . util . HashMap ; class CountDistinctWindow { static void countDistinct ( int arr [ ] , int k ) { HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ; int dist_count = 0 ; for ( int i = 0 ; i < k ; i ++ ) { if ( hM . get ( arr [ i ] ) == null ) { hM . put ( arr [ i ] , 1 ) ; dist_count ++ ; } else { int count = hM . get ( arr [ i ] ) ; hM . put ( arr [ i ] , count + 1 ) ; } } System . out . println ( dist_count ) ; for ( int i = k ; i < arr . length ; i ++ ) { if ( hM . get ( arr [ i - k ] ) == 1 ) { hM . remove ( arr [ i - k ] ) ; dist_count -- ; } else { int count = hM . get ( arr [ i - k ] ) ; hM . put ( arr [ i - k ] , count - 1 ) ; } if ( hM . get ( arr [ i ] ) == null ) { hM . put ( arr [ i ] , 1 ) ; dist_count ++ ; } else { int count = hM . get ( arr [ i ] ) ; hM . put ( arr [ i ] , count + 1 ) ; } System . out . println ( dist_count ) ; } } public static void main ( String arg [ ] ) { int arr [ ] = { 1 , 2 , 1 , 3 , 4 , 2 , 3 } ; int k = 4 ; countDistinct ( arr , k ) ; } }

from collections import defaultdict NEW_LINE def countDistinct ( arr , k , n ) : NEW_LINE INDENT mp = defaultdict ( lambda : 0 ) NEW_LINE dist_count = 0 NEW_LINE for i in range ( k ) : NEW_LINE INDENT if mp [ arr [ i ] ] == 0 : NEW_LINE INDENT dist_count += 1 NEW_LINE DEDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT print ( dist_count ) NEW_LINE for i in range ( k , n ) : NEW_LINE INDENT if mp [ arr [ i - k ] ] == 1 : NEW_LINE INDENT dist_count -= 1 NEW_LINE DEDENT mp [ arr [ i - k ] ] -= 1 NEW_LINE if mp [ arr [ i ] ] == 0 : NEW_LINE INDENT dist_count += 1 NEW_LINE DEDENT mp [ arr [ i ] ] += 1 NEW_LINE print ( dist_count ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 1 , 3 , 4 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE k = 4 NEW_LINE countDistinct ( arr , k , n ) NEW_LINE


import java . util . Arrays ; class GfG { static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } static void printMaxMean ( int arr [ ] , int n ) { int newArr [ ] = new int [ n ] ; Arrays . sort ( arr , 0 , 2 * n ) ; for ( int i = 0 ; i < n ; i ++ ) newArr [ i ] = arr [ i + n ] ; printArray ( newArr , n ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 8 , 3 , 1 , 3 , 7 , 0 , 4 } ; int n = arr . length ; printMaxMean ( arr , n / 2 ) ; } }

def printArray ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def printMaxMean ( arr , n ) : NEW_LINE INDENT newArr = [ 0 ] * n NEW_LINE arr . sort ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT newArr [ i ] = arr [ i + n ] NEW_LINE DEDENT printArray ( newArr , n ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 8 , 3 , 1 , 3 , 7 , 0 , 4 ] NEW_LINE n = len ( arr ) NEW_LINE printMaxMean ( arr , n // 2 ) NEW_LINE DEDENT


import java . util . * ; import java . lang . Math ; class GfG { static void powerfulIntegers ( int x , int y , int bound ) { Set < Integer > s = new HashSet < > ( ) ; ArrayList < Integer > powersOfY = new ArrayList < > ( ) ; int i ; powersOfY . add ( 1 ) ; for ( i = y ; i < bound ; i = i * y ) powersOfY . add ( i ) ; i = 0 ; while ( true ) { int xPowI = ( int ) Math . pow ( ( double ) x , ( double ) i ) ; if ( xPowI >= bound ) break ; for ( int j = 0 ; j < powersOfY . size ( ) ; ++ j ) { int num = xPowI + powersOfY . get ( j ) ; if ( num <= bound ) s . add ( num ) ; else break ; } i ++ ; } Iterator itr = s . iterator ( ) ; while ( itr . hasNext ( ) ) { System . out . print ( itr . next ( ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int x = 2 , y = 3 , bound = 10 ; powerfulIntegers ( x , y , bound ) ; } }

def powerfulIntegers ( x , y , bound ) : NEW_LINE INDENT s = set ( ) NEW_LINE powersOfY = [ ] NEW_LINE powersOfY . append ( 1 ) NEW_LINE i = y NEW_LINE while i < bound : NEW_LINE INDENT powersOfY . append ( i ) NEW_LINE i *= y NEW_LINE DEDENT i = 0 NEW_LINE while ( True ) : NEW_LINE INDENT xPowI = pow ( x , i ) NEW_LINE if ( xPowI >= bound ) : NEW_LINE INDENT break NEW_LINE DEDENT for j in powersOfY : NEW_LINE INDENT num = xPowI + j NEW_LINE if ( num <= bound ) : NEW_LINE INDENT s . add ( num ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT i += 1 NEW_LINE DEDENT for itr in s : NEW_LINE INDENT print ( itr , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT x = 2 NEW_LINE y = 3 NEW_LINE bound = 10 NEW_LINE powerfulIntegers ( x , y , bound ) NEW_LINE DEDENT


import java . util . HashMap ; class GFG { static void removeElements ( int arr [ ] , int n , int l , int r ) { HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int val = 0 ; if ( mp . get ( arr [ i ] ) == null ) { val = 1 ; } else { val = mp . get ( arr [ i ] ) + 1 ; } mp . put ( arr [ i ] , val ) ; } for ( int i = 0 ; i < n ; ++ i ) { if ( mp . get ( arr [ i ] ) < l || mp . get ( arr [ i ] ) > r ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 2 , 5 } ; int n = arr . length ; int l = 2 , r = 3 ; removeElements ( arr , n , l , r ) ; } }

def removeElements ( arr , n , l , r ) : NEW_LINE INDENT mp = { i : 0 for i in range ( len ( arr ) ) } NEW_LINE for i in range ( n ) : NEW_LINE INDENT mp [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( mp [ arr [ i ] ] < l or mp [ arr [ i ] > r ] ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 3 , 2 , 2 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE l = 2 NEW_LINE r = 3 NEW_LINE removeElements ( arr , n , l , r ) ; NEW_LINE DEDENT


public class RatMaze { static int N ; void printSolution ( int sol [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) System . out . print ( " ▁ " + sol [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } boolean isSafe ( int maze [ ] [ ] , int x , int y ) { return ( x >= 0 && x < N && y >= 0 && y < N && maze [ x ] [ y ] == 1 ) ; } boolean solveMaze ( int maze [ ] [ ] ) { int sol [ ] [ ] = new int [ N ] [ N ] ; if ( solveMazeUtil ( maze , 0 , 0 , sol ) == false ) { System . out . print ( " Solution ▁ doesn ' t ▁ exist " ) ; return false ; } printSolution ( sol ) ; return true ; } boolean solveMazeUtil ( int maze [ ] [ ] , int x , int y , int sol [ ] [ ] ) { if ( x == N - 1 && y == N - 1 && maze [ x ] [ y ] == 1 ) { sol [ x ] [ y ] = 1 ; return true ; } if ( isSafe ( maze , x , y ) == true ) { sol [ x ] [ y ] = 1 ; if ( solveMazeUtil ( maze , x + 1 , y , sol ) ) return true ; if ( solveMazeUtil ( maze , x , y + 1 , sol ) ) return true ; sol [ x ] [ y ] = 0 ; return false ; } return false ; } public static void main ( String args [ ] ) { RatMaze rat = new RatMaze ( ) ; int maze [ ] [ ] = { { 1 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 0 } , { 1 , 1 , 1 , 1 } } ; N = maze . length ; rat . solveMaze ( maze ) ; } }

N = 4 NEW_LINE def printSolution ( sol ) : NEW_LINE INDENT for i in sol : NEW_LINE INDENT for j in i : NEW_LINE INDENT print ( str ( j ) + " ▁ " , end = " " ) NEW_LINE DEDENT print ( " " ) NEW_LINE DEDENT DEDENT def isSafe ( maze , x , y ) : NEW_LINE INDENT if x >= 0 and x < N and y >= 0 and y < N and maze [ x ] [ y ] == 1 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def solveMaze ( maze ) : NEW_LINE INDENT sol = [ [ 0 for j in range ( 4 ) ] for i in range ( 4 ) ] NEW_LINE if solveMazeUtil ( maze , 0 , 0 , sol ) == False : NEW_LINE INDENT print ( " Solution ▁ doesn ' t ▁ exist " ) ; NEW_LINE return False NEW_LINE DEDENT printSolution ( sol ) NEW_LINE return True NEW_LINE DEDENT def solveMazeUtil ( maze , x , y , sol ) : NEW_LINE INDENT if x == N - 1 and y == N - 1 and maze [ x ] [ y ] == 1 : NEW_LINE INDENT sol [ x ] [ y ] = 1 NEW_LINE return True NEW_LINE DEDENT if isSafe ( maze , x , y ) == True : NEW_LINE INDENT sol [ x ] [ y ] = 1 NEW_LINE if solveMazeUtil ( maze , x + 1 , y , sol ) == True : NEW_LINE INDENT return True NEW_LINE DEDENT if solveMazeUtil ( maze , x , y + 1 , sol ) == True : NEW_LINE INDENT return True NEW_LINE DEDENT sol [ x ] [ y ] = 0 NEW_LINE return False NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT maze = [ [ 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 0 ] , [ 1 , 1 , 1 , 1 ] ] NEW_LINE solveMaze ( maze ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static void printLines ( int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . println ( k * ( 6 * i + 1 ) + " ▁ " + k * ( 6 * i + 2 ) + " ▁ " + k * ( 6 * i + 3 ) + " ▁ " + k * ( 6 * i + 5 ) ) ; } } public static void main ( String args [ ] ) { int n = 2 , k = 2 ; printLines ( n , k ) ; } }

def printLines ( n , k ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( k * ( 6 * i + 1 ) , k * ( 6 * i + 2 ) , k * ( 6 * i + 3 ) , k * ( 6 * i + 5 ) ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , k = 2 , 2 NEW_LINE printLines ( n , k ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int findpos ( String n ) { int k = 0 , pos = 0 , i = 0 ; while ( k != n . length ( ) ) { switch ( n . charAt ( i ) ) { case '4' : pos = pos * 2 + 1 ; break ; case '7' : pos = pos * 2 + 2 ; break ; } i ++ ; k ++ ; } return pos ; } public static void main ( String [ ] args ) { String n = "774" ; System . out . println ( findpos ( n ) ) ; } }

def findpos ( n ) : NEW_LINE INDENT i = 0 NEW_LINE j = len ( n ) NEW_LINE pos = 0 NEW_LINE while ( i < j ) : NEW_LINE INDENT if ( n [ i ] == '4' ) : NEW_LINE INDENT pos = pos * 2 + 1 NEW_LINE DEDENT if ( n [ i ] == '7' ) : NEW_LINE INDENT pos = pos * 2 + 2 NEW_LINE DEDENT i = i + 1 NEW_LINE DEDENT return pos NEW_LINE DEDENT n = "774" NEW_LINE print ( findpos ( n ) ) NEW_LINE


import java . util . * ; class GFG { static int NotParallel ( int p [ ] [ ] , int n ) { HashMap < Integer , Integer > x_axis = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > y_axis = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( x_axis . containsKey ( p [ i ] [ 0 ] ) ) x_axis . put ( p [ i ] [ 0 ] , x_axis . get ( p [ i ] [ 0 ] ) + 1 ) ; else x_axis . put ( p [ i ] [ 0 ] , 1 ) ; if ( y_axis . containsKey ( p [ i ] [ 1 ] ) ) y_axis . put ( p [ i ] [ 1 ] , y_axis . get ( p [ i ] [ 1 ] ) + 1 ) ; else y_axis . put ( p [ i ] [ 1 ] , 1 ) ; } int total = ( n * ( n - 1 ) ) / 2 ; for ( Map . Entry < Integer , Integer > i : x_axis . entrySet ( ) ) { int c = i . getValue ( ) ; total -= ( c * ( c - 1 ) ) / 2 ; } for ( Map . Entry < Integer , Integer > i : y_axis . entrySet ( ) ) { int c = i . getValue ( ) ; total -= ( c * ( c - 1 ) ) / 2 ; } return total ; } public static void main ( String [ ] args ) { int p [ ] [ ] = { { 1 , 2 } , { 1 , 5 } , { 1 , 15 } , { 2 , 10 } } ; int n = p . length ; System . out . print ( NotParallel ( p , n ) ) ; } }

def NotParallel ( p , n ) : NEW_LINE INDENT x_axis = { } ; y_axis = { } ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if p [ i ] [ 0 ] not in x_axis : NEW_LINE INDENT x_axis [ p [ i ] [ 0 ] ] = 0 ; NEW_LINE DEDENT x_axis [ p [ i ] [ 0 ] ] += 1 ; NEW_LINE if p [ i ] [ 1 ] not in y_axis : NEW_LINE INDENT y_axis [ p [ i ] [ 1 ] ] = 0 ; NEW_LINE DEDENT y_axis [ p [ i ] [ 1 ] ] += 1 ; NEW_LINE DEDENT total = ( n * ( n - 1 ) ) // 2 ; NEW_LINE for i in x_axis : NEW_LINE INDENT c = x_axis [ i ] ; NEW_LINE total -= ( c * ( c - 1 ) ) // 2 ; NEW_LINE DEDENT for i in y_axis : NEW_LINE INDENT c = y_axis [ i ] ; NEW_LINE total -= ( c * ( c - 1 ) ) // 2 ; NEW_LINE DEDENT return total ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT p = [ [ 1 , 2 ] , [ 1 , 5 ] , [ 1 , 15 ] , [ 2 , 10 ] ] ; NEW_LINE n = len ( p ) ; NEW_LINE print ( NotParallel ( p , n ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static int sz = 100000 ; static boolean isPrime [ ] = new boolean [ sz + 1 ] ; static void sieve ( ) { for ( int i = 0 ; i <= sz ; i ++ ) isPrime [ i ] = true ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( int j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } static void findPrimesD ( int d ) { int left = ( int ) Math . pow ( 10 , d - 1 ) ; int right = ( int ) Math . pow ( 10 , d ) - 1 ; for ( int i = left ; i <= right ; i ++ ) { if ( isPrime [ i ] ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String args [ ] ) { sieve ( ) ; int d = 1 ; findPrimesD ( d ) ; } }

from math import sqrt , pow NEW_LINE sz = 100005 NEW_LINE isPrime = [ True for i in range ( sz + 1 ) ] NEW_LINE def sieve ( ) : NEW_LINE INDENT isPrime [ 0 ] = isPrime [ 1 ] = False NEW_LINE for i in range ( 2 , int ( sqrt ( sz ) ) + 1 , 1 ) : NEW_LINE INDENT if ( isPrime [ i ] ) : NEW_LINE INDENT for j in range ( i * i , sz , i ) : NEW_LINE INDENT isPrime [ j ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def findPrimesD ( d ) : NEW_LINE INDENT left = int ( pow ( 10 , d - 1 ) ) NEW_LINE right = int ( pow ( 10 , d ) - 1 ) NEW_LINE for i in range ( left , right + 1 , 1 ) : NEW_LINE INDENT if ( isPrime [ i ] ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT sieve ( ) NEW_LINE d = 1 NEW_LINE findPrimesD ( d ) NEW_LINE DEDENT


class GFG { static int multiplyWith4 ( int n ) { return ( n << 2 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( multiplyWith4 ( n ) ) ; } }

def multiplyWith4 ( n ) : NEW_LINE INDENT return ( n << 2 ) NEW_LINE DEDENT n = 4 NEW_LINE print ( multiplyWith4 ( n ) ) NEW_LINE


import java . util . * ; class GFG { static String nthprimedigitsnumber ( int number ) { int rem ; String num = " " ; while ( number > 0 ) { rem = number % 4 ; switch ( rem ) { case 1 : num += '2' ; break ; case 2 : num += '3' ; break ; case 3 : num += '5' ; break ; case 0 : num += '7' ; break ; } if ( number % 4 == 0 ) number -- ; number = number / 4 ; } return new StringBuilder ( num ) . reverse ( ) . toString ( ) ; } public static void main ( String [ ] args ) { int number = 21 ; System . out . println ( nthprimedigitsnumber ( 10 ) ) ; System . out . println ( nthprimedigitsnumber ( 21 ) ) ; } }

def nthprimedigitsnumber ( number ) : NEW_LINE INDENT num = " " ; NEW_LINE while ( number > 0 ) : NEW_LINE INDENT rem = number % 4 ; NEW_LINE if ( rem == 1 ) : NEW_LINE INDENT num += '2' ; NEW_LINE DEDENT if ( rem == 2 ) : NEW_LINE INDENT num += '3' ; NEW_LINE DEDENT if ( rem == 3 ) : NEW_LINE INDENT num += '5' ; NEW_LINE DEDENT if ( rem == 0 ) : NEW_LINE INDENT num += '7' ; NEW_LINE DEDENT if ( number % 4 == 0 ) : NEW_LINE INDENT number = number - 1 NEW_LINE DEDENT number = number // 4 ; NEW_LINE DEDENT return num [ : : - 1 ] ; NEW_LINE DEDENT number = 21 ; NEW_LINE print ( nthprimedigitsnumber ( 10 ) ) ; NEW_LINE print ( nthprimedigitsnumber ( number ) ) ; NEW_LINE


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

def ncr ( n , r ) : NEW_LINE INDENT ans = 1 NEW_LINE for i in range ( 1 , r + 1 ) : NEW_LINE INDENT ans *= ( n - r + i ) NEW_LINE ans //= i NEW_LINE DEDENT return ans NEW_LINE DEDENT def totalWays ( X , Y , M , W ) : NEW_LINE INDENT return ( ncr ( M , X ) * ncr ( W , Y ) ) NEW_LINE DEDENT X = 4 NEW_LINE Y = 3 NEW_LINE M = 6 NEW_LINE W = 5 NEW_LINE print ( totalWays ( X , Y , M , W ) ) NEW_LINE


import java . util . * ; class GFG { static String first_subString ( String s ) { int n = s . length ( ) , c = 0 ; String s1 , s2 ; HashMap < String , Integer > mpp = new HashMap < String , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' ▁ ' || s . charAt ( i ) == ' # ' ) { s1 = s . substring ( c , i ) ; mpp . put ( s1 , 1 ) ; c = i + 1 ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' ▁ ' ) { continue ; } for ( int j = 0 ; j < n ; j ++ ) { if ( s . charAt ( i ) == ' ▁ ' ) { break ; } s1 = s . substring ( i , j - i + 1 ) ; s2 = s1 ; s1 = reverse ( s1 ) ; if ( mpp . containsKey ( s1 ) ) { return s2 ; } } } return " - 1" ; } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { String s , s1 ; s = " mango ▁ is ▁ sweet ▁ when ▁ nam ▁ en ▁ tastes ▁ it # " ; s1 = first_subString ( s ) ; System . out . print ( s1 + " \n " ) ; } }

def first_substring ( s ) : NEW_LINE INDENT n = len ( s ) ; c = 0 ; NEW_LINE mpp = { } ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == ' ▁ ' or s [ i ] == ' # ' ) : NEW_LINE INDENT s1 = s [ c : i ] ; NEW_LINE mpp [ s1 ] = 1 ; NEW_LINE c = i + 1 ; NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == ' ▁ ' ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT for j in range ( n ) : NEW_LINE INDENT if ( s [ j ] == ' ▁ ' ) : NEW_LINE INDENT break ; NEW_LINE DEDENT s1 = s [ i : j + 1 ] ; NEW_LINE s2 = s1 ; NEW_LINE s1 = s1 [ : : - 1 ] ; NEW_LINE if s1 in mpp : NEW_LINE INDENT if mpp [ s1 ] : NEW_LINE INDENT return s2 ; NEW_LINE DEDENT DEDENT DEDENT DEDENT return " - 1" ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " mango ▁ is ▁ sweet ▁ when ▁ nam ▁ en ▁ tastes ▁ it # " ; NEW_LINE s1 = first_substring ( s ) ; NEW_LINE print ( s1 ) ; NEW_LINE DEDENT


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

def numberofterm ( digit , number ) : NEW_LINE INDENT firstnum = pow ( 10 , digit - 1 ) NEW_LINE lastnum = pow ( 10 , digit ) NEW_LINE firstnum = ( firstnum - firstnum % number ) + number NEW_LINE lastnum = ( lastnum - lastnum % number ) NEW_LINE return ( ( lastnum - firstnum ) // number + 1 ) ; NEW_LINE DEDENT n = 3 ; number = 7 NEW_LINE print ( numberofterm ( n , number ) ) NEW_LINE


import java . io . * ; class GFG { static int pairsInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; int cnt = 0 ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) { cnt ++ ; if ( l == ( r - 1 + n ) % n ) { return cnt ; } l = ( l + 1 ) % n ; r = ( r - 1 + n ) % n ; } else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 15 , 6 , 7 , 9 , 10 } ; int sum = 16 ; int n = arr . length ; System . out . println ( pairsInSortedRotated ( arr , n , sum ) ) ; } }

def pairsInSortedRotated ( arr , n , x ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if arr [ i ] > arr [ i + 1 ] : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT l = ( i + 1 ) % n NEW_LINE r = i NEW_LINE cnt = 0 NEW_LINE while ( l != r ) : NEW_LINE INDENT if arr [ l ] + arr [ r ] == x : NEW_LINE INDENT cnt += 1 NEW_LINE if l == ( r - 1 + n ) % n : NEW_LINE INDENT return cnt NEW_LINE DEDENT l = ( l + 1 ) % n NEW_LINE r = ( r - 1 + n ) % n NEW_LINE DEDENT elif arr [ l ] + arr [ r ] < x : NEW_LINE INDENT l = ( l + 1 ) % n NEW_LINE DEDENT else : NEW_LINE INDENT r = ( n + r - 1 ) % n NEW_LINE DEDENT DEDENT return cnt NEW_LINE DEDENT arr = [ 11 , 15 , 6 , 7 , 9 , 10 ] NEW_LINE s = 16 NEW_LINE print ( pairsInSortedRotated ( arr , 6 , s ) ) NEW_LINE


import java . io . * ; class GFG { static long getSum ( long n , int d ) { if ( n < d ) return 0 ; while ( n % 10 != d ) n -- ; long k = n / 10 ; return ( k + 1 ) * d + ( k * 10 + 10 * k * k ) / 2 ; } public static void main ( String [ ] args ) { long n = 30 ; int d = 3 ; System . out . println ( getSum ( n , d ) ) ; } }

def getSum ( n , d ) : NEW_LINE INDENT if ( n < d ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT while ( n % 10 != d ) : NEW_LINE INDENT n -= 1 NEW_LINE DEDENT k = n // 10 NEW_LINE return ( ( k + 1 ) * d + ( k * 10 + 10 * k * k ) // 2 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 30 NEW_LINE d = 3 NEW_LINE print ( getSum ( n , d ) ) NEW_LINE DEDENT


class GFG { static float rmsValue ( int arr [ ] , int n ) { int square = 0 ; float mean = 0 ; float root = 0 ; for ( int i = 0 ; i < n ; i ++ ) { square += Math . pow ( arr [ i ] , 2 ) ; } mean = ( square / ( float ) ( n ) ) ; root = ( float ) Math . sqrt ( mean ) ; return root ; } public static void main ( String args [ ] ) { int arr [ ] = { 10 , 4 , 6 , 8 } ; int n = arr . length ; System . out . println ( rmsValue ( arr , n ) ) ; } }

import math NEW_LINE def rmsValue ( arr , n ) : NEW_LINE INDENT square = 0 NEW_LINE mean = 0.0 NEW_LINE root = 0.0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT square += ( arr [ i ] ** 2 ) NEW_LINE DEDENT mean = ( square / ( float ) ( n ) ) NEW_LINE root = math . sqrt ( mean ) NEW_LINE return root NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 10 , 4 , 6 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( rmsValue ( arr , n ) ) NEW_LINE DEDENT


class GFG { static final long MAX = 1000000000 ; static void findTriangle ( long S ) { long X1 = 0 , Y1 = 0 ; long X2 = MAX , Y2 = 1 ; long X3 = ( MAX - S % MAX ) % MAX ; long Y3 = ( S + X3 ) / MAX ; System . out . println ( " ( " + X1 + " , ▁ " + Y1 + " ) " ) ; System . out . println ( " ( " + X2 + " , ▁ " + Y2 + " ) " ) ; System . out . println ( " ( " + X3 + " , ▁ " + Y3 + " ) " ) ; } public static void main ( String [ ] args ) { long S = 4 ; findTriangle ( S ) ; } }

MAX = 1000000000 ; NEW_LINE def findTriangle ( S ) : NEW_LINE INDENT X1 = 0 ; Y1 = 0 ; NEW_LINE X2 = MAX ; Y2 = 1 ; NEW_LINE X3 = ( MAX - S % MAX ) % MAX ; NEW_LINE Y3 = ( S + X3 ) / MAX ; NEW_LINE print ( " ( " , X1 , " , " , Y1 , " ) " ) ; NEW_LINE print ( " ( " , X2 , " , " , Y2 , " ) " ) ; NEW_LINE print ( " ( " , X3 , " , " , Y3 , " ) " ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = 4 ; NEW_LINE findTriangle ( S ) ; NEW_LINE DEDENT


class GFG { static int xorOfArray ( int arr [ ] , int n ) { int xor_arr = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xor_arr = xor_arr ^ arr [ i ] ; } return xor_arr ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 9 , 12 , 13 , 15 } ; int n = arr . length ; System . out . println ( xorOfArray ( arr , n ) ) ; } }

def xorOfArray ( arr , n ) : NEW_LINE INDENT xor_arr = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT xor_arr = xor_arr ^ arr [ i ] NEW_LINE DEDENT return xor_arr NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 9 , 12 , 13 , 15 ] NEW_LINE n = len ( arr ) NEW_LINE print ( xorOfArray ( arr , n ) ) NEW_LINE DEDENT


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

def check ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT if ( s [ i ] > s [ i + 1 ] ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " geeksforgeeks " NEW_LINE if ( check ( s ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int minJumps ( int a , int b , int d ) { int temp = a ; a = Math . min ( a , b ) ; b = Math . max ( temp , b ) ; if ( d >= b ) return ( d + b - 1 ) / b ; if ( d == 0 ) return 0 ; if ( d == a ) return 1 ; return 2 ; } public static void main ( String [ ] args ) { int a = 3 , b = 4 , d = 11 ; System . out . println ( minJumps ( a , b , d ) ) ; } }

def minJumps ( a , b , d ) : NEW_LINE INDENT temp = a NEW_LINE a = min ( a , b ) NEW_LINE b = max ( temp , b ) NEW_LINE if ( d >= b ) : NEW_LINE INDENT return ( d + b - 1 ) / b NEW_LINE DEDENT if ( d == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( d == a ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT return 2 NEW_LINE DEDENT a , b , d = 3 , 4 , 11 NEW_LINE print ( int ( minJumps ( a , b , d ) ) ) NEW_LINE


class GFG { static String maxInt ( char str [ ] ) { for ( int i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] < '5' ) { str [ i ] = ( char ) ( ( '9' - str [ i ] ) + '0' ) ; } } if ( str [ 0 ] == '0' ) str [ 0 ] = '9' ; String str2 = new String ( str ) ; return str2 ; } public static void main ( String [ ] args ) { String str = "42" ; System . out . println ( maxInt ( str . toCharArray ( ) ) ) ; } }

def maxInt ( string ) : NEW_LINE INDENT string2 = " " NEW_LINE for i in range ( 0 , len ( string ) ) : NEW_LINE INDENT if ( string [ i ] < '5' ) : NEW_LINE INDENT string2 += str ( ( ord ( '9' ) - ord ( string [ i ] ) ) ) NEW_LINE DEDENT else : NEW_LINE INDENT string2 += str ( string [ i ] ) NEW_LINE DEDENT DEDENT if ( string2 [ 0 ] == '0' ) : NEW_LINE INDENT string2 [ 0 ] = '9' NEW_LINE DEDENT return string2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT string = "42" NEW_LINE print ( maxInt ( string ) ) NEW_LINE DEDENT


import java . util . * ; class gfg { static int sub_arrays ( int [ ] a , int n , int k ) { int sum [ ] = new int [ n + 2 ] ; for ( int i = 0 ; i < n + 2 ; i ++ ) { sum [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { a [ i ] -- ; a [ i ] %= k ; sum [ i + 1 ] += sum [ i ] + a [ i ] ; sum [ i + 1 ] %= k ; } int ans = 0 , l = 0 , r = 0 ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { mp . put ( sum [ i ] , 0 ) ; } int temp ; for ( int i = 0 ; i < n + 1 ; i ++ ) { ans += ( int ) mp . get ( sum [ i ] ) ; temp = ( int ) mp . get ( sum [ i ] ) + 1 ; mp . put ( sum [ i ] , temp ) ; r ++ ; if ( r - l >= k ) { temp = ( int ) mp . get ( sum [ l ] ) - 1 ; mp . put ( sum [ l ] , temp ) ; l ++ ; } } return ans ; } public static void main ( String args [ ] ) { int [ ] a = { 1 , 4 , 2 , 3 , 5 } ; int n = a . length ; int k = 4 ; System . out . print ( sub_arrays ( a , n , k ) ) ; } }

def sub_arrays ( a , n , k ) : NEW_LINE INDENT sum = [ 0 for i in range ( n + 2 ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ i ] -= 1 NEW_LINE a [ i ] %= k NEW_LINE sum [ i + 1 ] += sum [ i ] + a [ i ] NEW_LINE sum [ i + 1 ] %= k NEW_LINE DEDENT ans = 0 NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE mp = dict ( ) NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT if sum [ i ] in mp : NEW_LINE INDENT ans += mp [ sum [ i ] ] NEW_LINE DEDENT mp [ sum [ i ] ] = mp . get ( sum [ i ] , 0 ) + 1 NEW_LINE r += 1 NEW_LINE if ( r - l >= k ) : NEW_LINE INDENT mp [ sum [ l ] ] -= 1 NEW_LINE l += 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT a = [ 1 , 4 , 2 , 3 , 5 ] NEW_LINE n = len ( a ) NEW_LINE k = 4 NEW_LINE print ( sub_arrays ( a , n , k ) ) NEW_LINE


import java . io . * ; import java . math . * ; class GFG { static int lastKDigits ( int a [ ] , int n , int k ) { int num = ( int ) ( Math . pow ( 10 , k ) ) ; int mul = a [ 0 ] % num ; for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i ] % num ; mul = ( a [ i ] * mul ) % num ; } return mul ; } public static void main ( String args [ ] ) { int a [ ] = { 22 , 31 , 44 , 27 , 37 , 43 } ; int k = 2 ; int n = a . length ; System . out . println ( lastKDigits ( a , n , k ) ) ; } }

import math NEW_LINE def lastKDigits ( a , n , k ) : NEW_LINE INDENT num = ( int ) ( math . pow ( 10 , k ) ) NEW_LINE mul = a [ 0 ] % num NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT a [ i ] = a [ i ] % num NEW_LINE mul = ( a [ i ] * mul ) % num NEW_LINE DEDENT return mul NEW_LINE DEDENT a = [ 22 , 31 , 44 , 27 , 37 , 43 ] NEW_LINE k = 2 NEW_LINE n = len ( a ) NEW_LINE print ( lastKDigits ( a , n , k ) ) NEW_LINE


import java . io . * ; class GFG { static int getMinVal ( int p , int q ) { if ( q % p == 0 ) return p ; return - 1 ; } public static void main ( String [ ] args ) { int p = 24 , q = 48 ; System . out . println ( getMinVal ( p , q ) ) ; } }

def getMinVal ( p , q ) : NEW_LINE INDENT if q % p == 0 : NEW_LINE INDENT return p NEW_LINE DEDENT return - 1 NEW_LINE DEDENT p = 24 ; q = 48 NEW_LINE print ( getMinVal ( p , q ) ) NEW_LINE


class GFG { static double increaseInVol ( double l , double b , double h ) { double percentInc = ( 1 + ( l / 100 ) ) * ( 1 + ( b / 100 ) ) * ( 1 + ( h / 100 ) ) ; percentInc -= 1 ; percentInc *= 100 ; return percentInc ; } public static void main ( String [ ] args ) { double l = 50 , b = 20 , h = 10 ; System . out . println ( increaseInVol ( l , b , h ) + " % " ) ; } }

def increaseInVol ( l , b , h ) : NEW_LINE INDENT percentInc = ( ( 1 + ( l / 100 ) ) * ( 1 + ( b / 100 ) ) * ( 1 + ( h / 100 ) ) ) NEW_LINE percentInc -= 1 NEW_LINE percentInc *= 100 NEW_LINE return percentInc NEW_LINE DEDENT l = 50 NEW_LINE b = 20 NEW_LINE h = 10 NEW_LINE print ( increaseInVol ( l , b , h ) , " % " ) NEW_LINE


import java . util . * ; class GFG { static boolean isPrime ( int n ) { int i ; if ( n == 1 ) return false ; for ( i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static int countDistinct ( String s ) { Set < Character > m = new HashSet < Character > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { m . add ( s . charAt ( i ) ) ; } return m . size ( ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; if ( isPrime ( countDistinct ( str ) ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

from math import sqrt NEW_LINE def isPrime ( n ) : NEW_LINE INDENT if n == 1 : NEW_LINE INDENT return False NEW_LINE DEDENT for i in range ( 2 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if n % i == 0 : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def countDistinct ( s ) : NEW_LINE INDENT m = { } NEW_LINE m = m . fromkeys ( s , 0 ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT m [ s [ i ] ] += 1 NEW_LINE DEDENT return len ( m . keys ( ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " geeksforgeeks " NEW_LINE if isPrime ( countDistinct ( str ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


class GFG { static boolean isSemiPrime ( int num ) { int cnt = 0 ; for ( int i = 2 ; cnt < 2 && i * i <= num ; ++ i ) while ( num % i == 0 ) { num /= i ; ++ cnt ; } if ( num > 1 ) ++ cnt ; return cnt == 2 ? true : false ; } static boolean isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 || n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) { return false ; } } return true ; } static boolean isChenPrime ( int n ) { if ( isPrime ( n ) && ( isSemiPrime ( n + 2 ) || isPrime ( n + 2 ) ) ) return true ; else return false ; } public static void main ( String [ ] args ) { int n = 7 ; if ( isChenPrime ( n ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

import math NEW_LINE def isSemiPrime ( num ) : NEW_LINE INDENT cnt = 0 NEW_LINE for i in range ( 2 , int ( math . sqrt ( num ) ) + 1 ) : NEW_LINE INDENT while num % i == 0 : NEW_LINE INDENT num /= i NEW_LINE cnt += 1 NEW_LINE DEDENT if cnt >= 2 : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( num > 1 ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT return cnt == 2 NEW_LINE DEDENT def isPrime ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( n <= 3 ) : NEW_LINE INDENT return True NEW_LINE DEDENT if ( n % 2 == 0 or n % 3 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = 5 NEW_LINE while ( i * i <= n ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT i = i + 6 NEW_LINE DEDENT return True NEW_LINE DEDENT def isChenPrime ( n ) : NEW_LINE INDENT if ( isPrime ( n ) and ( isSemiPrime ( n + 2 ) or isPrime ( n + 2 ) ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT n = 7 NEW_LINE if ( isChenPrime ( n ) ) : NEW_LINE INDENT print ( " YES " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) ; NEW_LINE DEDENT


class GFG { static int ___gcd ( int a , int b ) { if ( a == 0 || b == 0 ) return 0 ; if ( a == b ) return a ; if ( a > b ) return ___gcd ( a - b , b ) ; return ___gcd ( a , b - a ) ; } static int findLargest ( int arr [ ] , int n ) { int gcd = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) gcd = ___gcd ( gcd , arr [ i ] ) ; return ( gcd == 1 ) ? n : - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 } ; int n = arr . length ; System . out . print ( " Length ▁ of ▁ the ▁ " + " largest ▁ subarray ▁ = ▁ " + findLargest ( arr , n ) ) ; } }

def ___gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 or b == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( a == b ) : NEW_LINE INDENT return a NEW_LINE DEDENT if ( a > b ) : NEW_LINE INDENT return ___gcd ( a - b , b ) NEW_LINE DEDENT return ___gcd ( a , b - a ) NEW_LINE DEDENT def findLargest ( arr , n ) : 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 return n if ( gcd == 1 ) else - 1 NEW_LINE DEDENT arr = [ 1 , 3 , 5 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Length ▁ of ▁ the ▁ largest ▁ subarray ▁ = ▁ " , findLargest ( arr , n ) ) NEW_LINE


class GFG { static final int MAXN = 100001 ; static boolean prime [ ] = new boolean [ MAXN ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < prime . length ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < MAXN ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i < MAXN ; i += p ) prime [ i ] = false ; } } } static void common_prime ( int a , int b ) { int gcd = ( int ) __gcd ( a , b ) ; for ( int i = 2 ; i <= ( gcd ) ; i ++ ) { if ( prime [ i ] && gcd % i == 0 ) { System . out . print ( i + " ▁ " ) ; } } } static long __gcd ( long a , long b ) { if ( a == 0 ) return b ; return __gcd ( b % a , a ) ; } public static void main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int a = 6 , b = 12 ; common_prime ( a , b ) ; } }

from math import gcd , sqrt NEW_LINE prime = [ True ] * 100001 NEW_LINE def SieveOfEratosthenes ( ) : NEW_LINE INDENT prime [ 0 ] = False NEW_LINE prime [ 1 ] = False NEW_LINE for p in range ( 2 , int ( sqrt ( 100001 ) ) + 1 ) : NEW_LINE INDENT if prime [ p ] == True : NEW_LINE INDENT for i in range ( p ** 2 , 100001 , p ) : NEW_LINE INDENT prime [ i ] = False NEW_LINE DEDENT DEDENT DEDENT DEDENT def common_prime ( a , b ) : NEW_LINE INDENT __gcd = gcd ( a , b ) NEW_LINE for i in range ( 2 , __gcd + 1 ) : NEW_LINE INDENT if prime [ i ] and __gcd % i == 0 : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT SieveOfEratosthenes ( ) NEW_LINE a , b = 6 , 12 NEW_LINE common_prime ( a , b ) NEW_LINE DEDENT


class GFG { static String smallestPoss ( String s , int n ) { String ans = " " ; int arr [ ] = new int [ 10 ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ s . charAt ( i ) - 48 ] ++ ; } for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < arr [ i ] ; j ++ ) ans = ans + String . valueOf ( i ) ; } return ans ; } public static void main ( String [ ] args ) { int N = 15 ; String K = "325343273113434" ; System . out . print ( smallestPoss ( K , N ) ) ; } }

def smallestPoss ( s , n ) : NEW_LINE INDENT ans = " " ; NEW_LINE arr = [ 0 ] * 10 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr [ ord ( s [ i ] ) - 48 ] += 1 ; NEW_LINE DEDENT for i in range ( 10 ) : NEW_LINE INDENT for j in range ( arr [ i ] ) : NEW_LINE INDENT ans = ans + str ( i ) ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 15 ; NEW_LINE K = "325343273113434" ; NEW_LINE print ( smallestPoss ( K , N ) ) ; NEW_LINE DEDENT


class GFG { static String maximumNum ( String curr_num , String res ) { int len1 = curr_num . length ( ) ; int len2 = res . length ( ) ; if ( len1 == len2 ) { int i = 0 ; while ( curr_num . charAt ( i ) == res . charAt ( i ) ) i ++ ; if ( curr_num . charAt ( i ) < res . charAt ( i ) ) return res ; else return curr_num ; } return len1 < len2 ? res : curr_num ; } static String extractMaximum ( String str ) { int n = str . length ( ) ; String curr_num = " " ; String res = " " ; for ( int i = 0 ; i < n ; i ++ ) { while ( i < n && str . charAt ( i ) == '0' ) i ++ ; while ( i < n && Character . isDigit ( str . charAt ( i ) ) ) { curr_num = curr_num + str . charAt ( i ) ; i ++ ; } if ( i == n ) break ; if ( curr_num . length ( ) > 0 ) i -- ; res = maximumNum ( curr_num , res ) ; curr_num = " " ; } if ( curr_num . length ( ) == 0 && res . length ( ) == 0 ) res = res + '0' ; return maximumNum ( curr_num , res ) ; } public static void main ( String [ ] args ) { String str = "100klh564abc365bg " ; System . out . println ( extractMaximum ( str ) ) ; } }

def maximumNum ( curr_num , res ) : NEW_LINE INDENT len1 = len ( curr_num ) ; NEW_LINE len2 = len ( res ) ; NEW_LINE if ( len1 == len2 ) : NEW_LINE INDENT i = 0 ; NEW_LINE while ( curr_num [ i ] == res [ i ] ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT if ( curr_num [ i ] < res [ i ] ) : NEW_LINE INDENT return res ; NEW_LINE DEDENT else : NEW_LINE INDENT return curr_num ; NEW_LINE DEDENT DEDENT return res if ( len1 < len2 ) else curr_num ; NEW_LINE DEDENT def extractMaximum ( str ) : NEW_LINE INDENT n = len ( str ) ; NEW_LINE curr_num = " " ; NEW_LINE res = " " ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT while ( i < n and str [ i ] == '0' ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT while ( i < n and str [ i ] >= '0' and str [ i ] <= '9' ) : NEW_LINE INDENT curr_num += str [ i ] ; NEW_LINE i += 1 ; NEW_LINE DEDENT if ( i == n ) : NEW_LINE INDENT break ; NEW_LINE DEDENT if ( len ( curr_num ) > 0 ) : NEW_LINE INDENT i -= 1 ; NEW_LINE DEDENT res = maximumNum ( curr_num , res ) ; NEW_LINE curr_num = " " ; NEW_LINE DEDENT if ( len ( curr_num ) == 0 and len ( res ) == 0 ) : NEW_LINE INDENT res += '0' ; NEW_LINE DEDENT return maximumNum ( curr_num , res ) ; NEW_LINE DEDENT str = "100klh564abc365bg " ; NEW_LINE print ( extractMaximum ( str ) ) ; NEW_LINE


public class GFG { static int add ( int x , int y ) { while ( y > 0 && y != 0 ) { x ++ ; y -- ; } while ( y < 0 && y != 0 ) { x -- ; y ++ ; } return x ; } public static void main ( String args [ ] ) { System . out . println ( add ( 43 , 23 ) ) ; System . out . println ( add ( 43 , - 23 ) ) ; } }

INDENT while ( y > 0 and y ) : NEW_LINE INDENT x = x + 1 NEW_LINE y = y - 1 NEW_LINE DEDENT while ( y < 0 and y ) : NEW_LINE INDENT x = x - 1 NEW_LINE y = y + 1 NEW_LINE DEDENT return x NEW_LINE DEDENT print ( add ( 43 , 23 ) ) NEW_LINE print ( add ( 43 , - 23 ) ) NEW_LINE


class GFG { static int CHAR_BIT = 8 ; static int min ( int x , int y ) { return y + ( ( x - y ) & ( ( x - y ) >> ( ( Integer . SIZE / 8 ) * CHAR_BIT - 1 ) ) ) ; } static int smallest ( int x , int y , int z ) { return Math . min ( x , Math . min ( y , z ) ) ; } public static void main ( String [ ] args ) { int x = 12 , y = 15 , z = 5 ; System . out . println ( " Minimum ▁ of ▁ 3 ▁ numbers ▁ is ▁ " + smallest ( x , y , z ) ) ; } }

CHAR_BIT = 8 NEW_LINE def min ( x , y ) : NEW_LINE INDENT return y + ( ( x - y ) &   \ ( ( x - y ) >> ( 32 * CHAR_BIT - 1 ) ) ) NEW_LINE DEDENT def smallest ( x , y , z ) : NEW_LINE INDENT return min ( x , min ( y , z ) ) NEW_LINE DEDENT x = 12 NEW_LINE y = 15 NEW_LINE z = 5 NEW_LINE print ( " Minimum ▁ of ▁ 3 ▁ numbers ▁ is ▁ " , smallest ( x , y , z ) ) NEW_LINE


import java . util . Vector ; class Test { static final int MAX_SIZE = 1000001 ; static Vector < Boolean > isprime = new Vector < > ( MAX_SIZE ) ; static Vector < Integer > prime = new Vector < > ( ) ; static Vector < Integer > SPF = new Vector < > ( MAX_SIZE ) ; static void manipulated_seive ( int N ) { isprime . set ( 0 , false ) ; isprime . set ( 1 , false ) ; for ( int i = 2 ; i < N ; i ++ ) { if ( isprime . get ( i ) ) { prime . add ( i ) ; SPF . set ( i , i ) ; } for ( int j = 0 ; j < prime . size ( ) && i * prime . get ( j ) < N && prime . get ( j ) <= SPF . get ( i ) ; j ++ ) { isprime . set ( i * prime . get ( j ) , false ) ; SPF . set ( i * prime . get ( j ) , prime . get ( j ) ) ; } } } public static void main ( String args [ ] ) { int N = 13 ; for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { isprime . add ( true ) ; SPF . add ( 2 ) ; } manipulated_seive ( N ) ; for ( int i = 0 ; i < prime . size ( ) && prime . get ( i ) <= N ; i ++ ) System . out . print ( prime . get ( i ) + " ▁ " ) ; } }

MAX_SIZE = 1000001 NEW_LINE isprime = [ True ] * MAX_SIZE NEW_LINE prime = [ ] NEW_LINE SPF = [ None ] * ( MAX_SIZE ) NEW_LINE def manipulated_seive ( N ) : NEW_LINE INDENT isprime [ 0 ] = isprime [ 1 ] = False NEW_LINE for i in range ( 2 , N ) : NEW_LINE INDENT if isprime [ i ] == True : NEW_LINE INDENT prime . append ( i ) NEW_LINE SPF [ i ] = i NEW_LINE DEDENT j = 0 NEW_LINE while ( j < len ( prime ) and i * prime [ j ] < N and prime [ j ] <= SPF [ i ] ) : NEW_LINE INDENT isprime [ i * prime [ j ] ] = False NEW_LINE SPF [ i * prime [ j ] ] = prime [ j ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 13 NEW_LINE manipulated_seive ( N ) NEW_LINE i = 0 NEW_LINE while i < len ( prime ) and prime [ i ] <= N : NEW_LINE INDENT print ( prime [ i ] , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static boolean checkPerfectcube ( int n ) { int d = ( int ) Math . cbrt ( n ) ; if ( d * d * d == n ) return true ; return false ; } static int largestNonPerfectcubeNumber ( int [ ] a , int n ) { int maxi = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! checkPerfectcube ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } public static void main ( String [ ] args ) { int a [ ] = { 16 , 64 , 25 , 2 , 3 , 10 } ; int n = a . length ; System . out . print ( largestNonPerfectcubeNumber ( a , n ) ) ; } }

import math NEW_LINE def checkPerfectcube ( n ) : NEW_LINE INDENT cube_root = n ** ( 1. / 3. ) NEW_LINE if round ( cube_root ) ** 3 == n : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def largestNonPerfectcubeNumber ( a , n ) : NEW_LINE INDENT maxi = - 1 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( checkPerfectcube ( a [ i ] ) == False ) : NEW_LINE INDENT maxi = max ( a [ i ] , maxi ) NEW_LINE DEDENT DEDENT return maxi NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 16 , 64 , 25 , 2 , 3 , 10 ] NEW_LINE n = len ( a ) NEW_LINE print ( largestNonPerfectcubeNumber ( a , n ) ) NEW_LINE DEDENT


class GFG { static void findPair ( int arr [ ] , int n ) { if ( n < 2 ) { System . out . print ( " - 1" ) ; return ; } int maximum = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) maximum = Math . max ( maximum , arr [ i ] ) ; int temp = 10000001 , r = 0 , middle = maximum / 2 ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( middle - arr [ i ] ) < temp && n % 2 == 0 ) { temp = Math . abs ( middle - arr [ i ] ) ; r = arr [ i ] ; } else if ( Math . min ( Math . abs ( middle - arr [ i ] ) , Math . abs ( middle + 1 - arr [ i ] ) ) < temp && n % 2 == 1 ) { temp = Math . min ( Math . abs ( middle - arr [ i ] ) , Math . abs ( middle + 1 - arr [ i ] ) ) ; r = arr [ i ] ; } } System . out . print ( " n ▁ = ▁ " + maximum + " ▁ and ▁ r ▁ = ▁ " + r ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 } ; int n = arr . length ; findPair ( arr , n ) ; } }

def findPair ( arr , n ) : NEW_LINE INDENT if ( n < 2 ) : NEW_LINE INDENT print ( " - 1" , end = " ▁ " ) ; NEW_LINE return ; NEW_LINE DEDENT maximum = max ( arr ) ; NEW_LINE temp = 10000001 ; r = 0 ; middle = maximum // 2 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( abs ( middle - arr [ i ] ) < temp and n % 2 == 0 ) : NEW_LINE INDENT temp = abs ( middle - arr [ i ] ) ; NEW_LINE r = arr [ i ] ; NEW_LINE DEDENT elif ( min ( abs ( middle - arr [ i ] ) , abs ( middle + 1 - arr [ i ] ) ) < temp and n % 2 == 1 ) : NEW_LINE INDENT temp = min ( abs ( middle - arr [ i ] ) , abs ( middle + 1 - arr [ i ] ) ) ; NEW_LINE r = arr [ i ] ; NEW_LINE DEDENT DEDENT print ( " n ▁ = " , maximum , " and ▁ r ▁ = " , r ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 0 , 2 , 3 , 4 , 1 , 6 , 8 , 9 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE findPair ( arr , n ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int countEvenSum ( int arr [ ] , int n ) { int temp [ ] = { 1 , 0 } ; int result = 0 , sum = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { sum = ( ( sum + arr [ i ] ) % 2 + 2 ) % 2 ; temp [ sum ] ++ ; } result = result + ( temp [ 0 ] * ( temp [ 0 ] - 1 ) / 2 ) ; result = result + ( temp [ 1 ] * ( temp [ 1 ] - 1 ) / 2 ) ; return ( result ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 3 , 4 , 1 } ; int n = arr . length ; System . out . println ( " The ▁ Number ▁ of ▁ Subarrays " + " ▁ with ▁ even ▁ sum ▁ is ▁ " + countEvenSum ( arr , n ) ) ; } }

def countEvenSum ( arr , n ) : NEW_LINE INDENT temp = [ 1 , 0 ] NEW_LINE result = 0 NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum = ( ( sum + arr [ i ] ) % 2 + 2 ) % 2 NEW_LINE temp [ sum ] += 1 NEW_LINE DEDENT result = result + ( temp [ 0 ] * ( temp [ 0 ] - 1 ) // 2 ) NEW_LINE result = result + ( temp [ 1 ] * ( temp [ 1 ] - 1 ) // 2 ) NEW_LINE return ( result ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 2 , 3 , 4 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " The ▁ Number ▁ of ▁ Subarrays ▁ with ▁ even " " ▁ sum ▁ is " , countEvenSum ( arr , n ) ) NEW_LINE DEDENT


class GFG { static String reverseWord ( String str ) { int len = str . length ( ) ; int i = 1 ; int j = str . length ( ) - 2 ; char [ ] strchar = str . toCharArray ( ) ; while ( i < j ) { char temp = strchar [ i ] ; strchar [ i ] = strchar [ j ] ; strchar [ j ] = temp ; i ++ ; j -- ; } str = new String ( strchar ) ; return str ; } static void reverseWords ( String str ) { String [ ] tok = str . split ( " \\ s " ) ; for ( String w : tok ) { System . out . print ( reverseWord ( w ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { String str = " geeks ▁ for ▁ geeks " ; reverseWords ( str ) ; } }

def reverseWord ( Str ) : NEW_LINE INDENT i = 1 NEW_LINE j = len ( Str ) - 2 NEW_LINE while ( i < j ) : NEW_LINE INDENT temp = Str [ i ] NEW_LINE Str [ i ] = Str [ j ] NEW_LINE Str [ j ] = temp NEW_LINE i += 1 NEW_LINE j -= 1 NEW_LINE DEDENT return " " . join ( Str ) NEW_LINE DEDENT def reverseWords ( Str ) : NEW_LINE INDENT Str = Str . split ( ) NEW_LINE for i in Str : NEW_LINE INDENT j = [ h for h in i ] NEW_LINE print ( reverseWord ( j ) , end = " ▁ " ) NEW_LINE DEDENT DEDENT Str = " geeks ▁ for ▁ geeks " NEW_LINE reverseWords ( Str ) NEW_LINE


import java . io . * ; class GFG { static void checkEVENodd ( int arr [ ] , int n , int l , int r ) { if ( arr [ r ] == 1 ) System . out . println ( " odd " ) ; else System . out . println ( " even " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 0 , 1 } ; int n = arr . length ; checkEVENodd ( arr , n , 1 , 3 ) ; } }

def checkEVENodd ( arr , n , l , r ) : NEW_LINE INDENT if ( arr [ r ] == 1 ) : NEW_LINE INDENT print ( " odd " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " even " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 1 , 0 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE checkEVENodd ( arr , n , 1 , 3 ) NEW_LINE


class GFG { static int INT_SIZE = 32 ; static int Right_most_setbit ( int num ) { int pos = 1 ; for ( int i = 0 ; i < INT_SIZE ; i ++ ) { if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ; else break ; } return pos ; } static int findValueAtK ( int n , int m , int k ) { int positionOfRightmostSetbit = Right_most_setbit ( k ) ; return ( ( m - 1 ) + positionOfRightmostSetbit ) ; } public static void main ( String [ ] args ) { int k = 100 , n = 9 , m = 74 ; System . out . println ( findValueAtK ( n , m , k ) ) ; } }

import math NEW_LINE def findValueAtK ( n , m , k ) : NEW_LINE INDENT positionOfRightmostSetbit = math . log2 ( k & - k ) + 1 NEW_LINE return ( ( m - 1 ) + positionOfRightmostSetbit ) NEW_LINE DEDENT k = 100 NEW_LINE n = 9 NEW_LINE m = 74 NEW_LINE print ( findValueAtK ( n , m , k ) ) NEW_LINE


class Main { static boolean checkForSorting ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) { if ( arr [ i ] - arr [ i + 1 ] == 1 ) { int temp = arr [ i ] ; arr [ i ] = arr [ i + 1 ] ; arr [ i + 1 ] = temp ; } else return false ; } } return true ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 0 , 3 , 2 } ; int n = arr . length ; if ( checkForSorting ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def checkForSorting ( arr , n ) : NEW_LINE INDENT for i in range ( 0 , n - 1 ) : NEW_LINE INDENT if ( arr [ i ] > arr [ i + 1 ] ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i + 1 ] == 1 ) : NEW_LINE INDENT arr [ i ] , arr [ i + 1 ] = arr [ i + 1 ] , arr [ i ] NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT return True NEW_LINE DEDENT arr = [ 1 , 0 , 3 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE if ( checkForSorting ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int slopeOfNum ( String num , int n ) { int slope = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( num . charAt ( i ) > num . charAt ( i - 1 ) && num . charAt ( i ) > num . charAt ( i + 1 ) ) slope ++ ; else if ( num . charAt ( i ) < num . charAt ( i - 1 ) && num . charAt ( i ) < num . charAt ( i + 1 ) ) slope ++ ; } return slope ; } public static void main ( String [ ] args ) { String num = "1213321" ; int n = num . length ( ) ; System . out . println ( " Slope ▁ = ▁ " + slopeOfNum ( num , n ) ) ; } }

def slopeOfNum ( num , n ) : NEW_LINE INDENT slope = 0 NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( num [ i ] > num [ i - 1 ] and num [ i ] > num [ i + 1 ] ) : NEW_LINE INDENT slope += 1 NEW_LINE DEDENT elif ( num [ i ] < num [ i - 1 ] and num [ i ] < num [ i + 1 ] ) : NEW_LINE INDENT slope += 1 NEW_LINE DEDENT DEDENT return slope NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT num = "1213321" NEW_LINE n = len ( num ) NEW_LINE print ( " Slpoe ▁ = " , slopeOfNum ( num , n ) ) NEW_LINE DEDENT


class GFG { static boolean isCyclic ( long N ) { long num = N ; int count = 0 ; int digit = ( int ) ( num % 10 ) ; boolean allSame = true ; while ( num > 0 ) { count ++ ; if ( num % 10 != digit ) allSame = false ; num = num / 10 ; } if ( allSame == true ) return false ; if ( count % 2 == 0 ) { long halfPower = ( long ) Math . pow ( 10 , count / 2 ) ; long firstHalf = N % halfPower ; long secondHalf = N / halfPower ; if ( firstHalf == firstHalf && isCyclic ( firstHalf ) ) return false ; } num = N ; while ( true ) { long rem = num % 10 ; long div = num / 10 ; num = ( long ) ( Math . pow ( 10 , count - 1 ) ) * rem + div ; if ( num == N ) break ; if ( num % N != 0 ) return false ; } return true ; } public static void main ( String [ ] args ) { long N = 142857 ; if ( isCyclic ( N ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

def isCyclic ( N ) : NEW_LINE INDENT num = N NEW_LINE count = 0 NEW_LINE digit = ( num % 10 ) NEW_LINE allSame = True NEW_LINE while ( num > 0 ) : NEW_LINE INDENT count += 1 NEW_LINE if ( num % 10 != digit ) : NEW_LINE INDENT allSame = False NEW_LINE DEDENT num = num // 10 NEW_LINE DEDENT if ( allSame == True ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( count % 2 == 0 ) : NEW_LINE INDENT halfPower = pow ( 10 , count // 2 ) NEW_LINE firstHalf = N % halfPower NEW_LINE secondHalf = N / halfPower NEW_LINE if ( firstHalf == firstHalf and isCyclic ( firstHalf ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT num = N NEW_LINE while ( True ) : NEW_LINE INDENT rem = num % 10 NEW_LINE div = num // 10 NEW_LINE num = pow ( 10 , count - 1 ) * rem + div NEW_LINE if ( num == N ) : NEW_LINE INDENT break NEW_LINE DEDENT if ( num % N != 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT N = 142857 NEW_LINE if ( isCyclic ( N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


class GFG { static int countOfLetters ( String str ) { int letter = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) || ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) ) letter ++ ; } return letter ; } static int countOfNumbers ( String str ) { int number = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) number ++ ; } return number ; } static void check ( String str ) { if ( countOfLetters ( str ) == countOfNumbers ( str ) ) System . out . print ( " Yes \n " ) ; else System . out . print ( " No \n " ) ; } public static void main ( String [ ] args ) { String str = " GeeKs01324" ; check ( str ) ; } }

def countOfLetters ( string ) : NEW_LINE INDENT letter = 0 ; NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if ( ( string [ i ] >= ' A ' and string [ i ] <= ' Z ' ) or ( string [ i ] >= ' a ' and string [ i ] <= ' z ' ) ) : NEW_LINE INDENT letter += 1 ; NEW_LINE DEDENT DEDENT return letter ; NEW_LINE DEDENT def countOfNumbers ( string ) : NEW_LINE INDENT number = 0 ; NEW_LINE for i in range ( len ( string ) ) : NEW_LINE INDENT if ( string [ i ] >= '0' and string [ i ] <= '9' ) : NEW_LINE INDENT number += 1 ; NEW_LINE DEDENT DEDENT return number ; NEW_LINE DEDENT def check ( string ) : NEW_LINE INDENT if ( countOfLetters ( string ) == countOfNumbers ( string ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " GeeKs01324" ; NEW_LINE check ( string ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int findMaximum ( int l , int p , int q , int r ) { int dp [ ] = new int [ l + 1 ] ; for ( int i = 0 ; i < l + 1 ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; for ( int i = 0 ; i <= l ; i ++ ) { if ( dp [ i ] == - 1 ) continue ; if ( i + p <= l ) dp [ i + p ] = Math . max ( dp [ i + p ] , dp [ i ] + 1 ) ; if ( i + q <= l ) dp [ i + q ] = Math . max ( dp [ i + q ] , dp [ i ] + 1 ) ; if ( i + r <= l ) dp [ i + r ] = Math . max ( dp [ i + r ] , dp [ i ] + 1 ) ; } return dp [ l ] ; } public static void main ( String [ ] args ) { int l = 11 , p = 2 , q = 3 , r = 5 ; int ans = findMaximum ( l , p , q , r ) ; System . out . println ( ans ) ; } }

def findMaximum ( l , p , q , r ) : NEW_LINE INDENT dp = [ - 1 ] * ( l + 1 ) NEW_LINE dp [ 0 ] = 0 NEW_LINE for i in range ( l + 1 ) : NEW_LINE INDENT if ( dp [ i ] == - 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT if ( i + p <= l ) : NEW_LINE INDENT dp [ i + p ] = ( max ( dp [ i + p ] , dp [ i ] + 1 ) ) NEW_LINE DEDENT if ( i + q <= l ) : NEW_LINE INDENT dp [ i + q ] = ( max ( dp [ i + q ] , dp [ i ] + 1 ) ) NEW_LINE DEDENT if ( i + r <= l ) : NEW_LINE INDENT dp [ i + r ] = ( max ( dp [ i + r ] , dp [ i ] + 1 ) ) NEW_LINE DEDENT DEDENT return dp [ l ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l = 11 NEW_LINE p = 2 NEW_LINE q = 3 NEW_LINE r = 5 NEW_LINE ans = findMaximum ( l , p , q , r ) NEW_LINE print ( ans ) NEW_LINE DEDENT


class GFG { static int maxAbsDiff ( int arr [ ] , int n ) { int minEle = arr [ 0 ] ; int maxEle = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { minEle = Math . min ( minEle , arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } return ( maxEle - minEle ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 5 , 3 } ; int n = arr . length ; System . out . print ( maxAbsDiff ( arr , n ) ) ; } }

def maxAbsDiff ( arr , n ) : NEW_LINE INDENT minEle = arr [ 0 ] NEW_LINE maxEle = arr [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT minEle = min ( minEle , arr [ i ] ) NEW_LINE maxEle = max ( maxEle , arr [ i ] ) NEW_LINE DEDENT return ( maxEle - minEle ) NEW_LINE DEDENT arr = [ 2 , 1 , 5 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxAbsDiff ( arr , n ) ) NEW_LINE


class cfg { static int subarrayCount ( int arr [ ] , int n ) { int result = 0 ; int fast = 0 , slow = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] == 1 ) { fast ++ ; } else { int len = fast - slow + 1 ; result += len * ( len - 1 ) / 2 ; fast = i ; slow = i ; } } if ( fast != slow ) { int len = fast - slow + 1 ; result += len * ( len - 1 ) / 2 ; } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 5 , 6 , 7 } ; int n = arr . length ; System . out . println ( subarrayCount ( arr , n ) ) ; } }

def subarrayCount ( arr , n ) : NEW_LINE INDENT result = 0 NEW_LINE fast , slow = 0 , 0 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( arr [ i ] - arr [ i - 1 ] == 1 ) : NEW_LINE INDENT fast += 1 NEW_LINE DEDENT else : NEW_LINE INDENT length = fast - slow + 1 NEW_LINE result += length * ( length - 1 ) // 2 ; NEW_LINE fast = i NEW_LINE slow = i NEW_LINE DEDENT DEDENT if ( fast != slow ) : NEW_LINE INDENT length = fast - slow + 1 NEW_LINE result += length * ( length - 1 ) // 2 ; NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( subarrayCount ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int findSplitPoint ( int arr [ ] , int n ) { int leftSum = 0 ; for ( int i = 0 ; i < n ; i ++ ) leftSum += arr [ i ] ; int rightSum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { rightSum += arr [ i ] ; leftSum -= arr [ i ] ; if ( rightSum == leftSum ) return i ; } return - 1 ; } static void printTwoParts ( int arr [ ] , int n ) { int splitPoint = findSplitPoint ( arr , n ) ; if ( splitPoint == - 1 || splitPoint == n ) { System . out . println ( " Not ▁ Possible " ) ; return ; } for ( int i = 0 ; i < n ; i ++ ) { if ( splitPoint == i ) System . out . println ( ) ; System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 5 } ; int n = arr . length ; printTwoParts ( arr , n ) ; } }

def findSplitPoint ( arr , n ) : NEW_LINE INDENT leftSum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT leftSum += arr [ i ] NEW_LINE DEDENT rightSum = 0 NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT rightSum += arr [ i ] NEW_LINE leftSum -= arr [ i ] NEW_LINE if ( rightSum == leftSum ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT def printTwoParts ( arr , n ) : NEW_LINE INDENT splitPoint = findSplitPoint ( arr , n ) NEW_LINE if ( splitPoint == - 1 or splitPoint == n ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT for i in range ( 0 , n ) : NEW_LINE INDENT if ( splitPoint == i ) : NEW_LINE INDENT print ( " " ) NEW_LINE DEDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE printTwoParts ( arr , n ) NEW_LINE


import java . util . * ; class GFG { static void solve ( String s , int k ) { int count = 0 , length = 0 , pos = 0 ; HashMap < Character , Integer > m = new HashMap < Character , Integer > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( m . containsKey ( s . charAt ( i ) ) ) m . put ( s . charAt ( i ) , m . get ( s . charAt ( i ) ) + 1 ) ; else m . put ( s . charAt ( i ) , 1 ) ; length ++ ; if ( length > k ) { m . put ( s . charAt ( pos ) , m . get ( s . charAt ( pos ) ) - 1 ) ; pos ++ ; length -- ; } if ( length == k && m . get ( s . charAt ( i ) ) == length ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { String s = " aaaabbbccdddd " ; int k = 4 ; solve ( s , k ) ; } }

def solve ( s , k ) : NEW_LINE INDENT count , length , pos = 0 , 0 , 0 NEW_LINE m = dict . fromkeys ( s , 0 ) NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT m [ s [ i ] ] += 1 NEW_LINE length += 1 NEW_LINE if length > k : NEW_LINE INDENT m [ s [ pos ] ] -= 1 NEW_LINE pos += 1 NEW_LINE length -= 1 NEW_LINE DEDENT if length == k and m [ s [ i ] ] == length : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = " aaaabbbccdddd " NEW_LINE k = 4 NEW_LINE solve ( s , k ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int findMissingUtil ( int arr [ ] , int low , int high , int diff ) { if ( high <= low ) return Integer . MAX_VALUE ; int mid = low + ( high - low ) / 2 ; if ( arr [ mid + 1 ] - arr [ mid ] != diff ) return ( arr [ mid ] + diff ) ; if ( mid > 0 && arr [ mid ] - arr [ mid - 1 ] != diff ) return ( arr [ mid - 1 ] + diff ) ; if ( arr [ mid ] == arr [ 0 ] + mid * diff ) return findMissingUtil ( arr , mid + 1 , high , diff ) ; return findMissingUtil ( arr , low , mid - 1 , diff ) ; } static int findMissing ( int arr [ ] , int n ) { int diff = ( arr [ n - 1 ] - arr [ 0 ] ) / n ; return findMissingUtil ( arr , 0 , n - 1 , diff ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 8 , 10 , 12 , 14 } ; int n = arr . length ; System . out . println ( " The ▁ missing ▁ element ▁ is ▁ " + findMissing ( arr , n ) ) ; } }

import sys NEW_LINE def findMissingUtil ( arr , low , high , diff ) : NEW_LINE INDENT if ( high <= low ) : NEW_LINE INDENT return sys . maxsize ; NEW_LINE DEDENT mid = int ( low + ( high - low ) / 2 ) ; NEW_LINE if ( arr [ mid + 1 ] - arr [ mid ] != diff ) : NEW_LINE INDENT return ( arr [ mid ] + diff ) ; NEW_LINE DEDENT if ( mid > 0 and arr [ mid ] - arr [ mid - 1 ] != diff ) : NEW_LINE INDENT return ( arr [ mid - 1 ] + diff ) ; NEW_LINE DEDENT if ( arr [ mid ] == arr [ 0 ] + mid * diff ) : NEW_LINE INDENT return findMissingUtil ( arr , mid + 1 , high , diff ) ; NEW_LINE DEDENT return findMissingUtil ( arr , low , mid - 1 , diff ) ; NEW_LINE DEDENT def findMissing ( arr , n ) : NEW_LINE INDENT diff = int ( ( arr [ n - 1 ] - arr [ 0 ] ) / n ) ; NEW_LINE return findMissingUtil ( arr , 0 , n - 1 , diff ) ; NEW_LINE DEDENT arr = [ 2 , 4 , 8 , 10 , 12 , 14 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( " The ▁ missing ▁ element ▁ is " , findMissing ( arr , n ) ) ; NEW_LINE


import java . util . * ; class GFG { static String findSum ( String str1 , String str2 ) { if ( str1 . length ( ) > str2 . length ( ) ) { String t = str1 ; str1 = str2 ; str2 = t ; } String str = " " ; int n1 = str1 . length ( ) , n2 = str2 . length ( ) ; int diff = n2 - n1 ; int carry = 0 ; for ( int i = n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( int ) ( str1 . charAt ( i ) - '0' ) + ( int ) ( str2 . charAt ( i + diff ) - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } for ( int i = n2 - n1 - 1 ; i >= 0 ; i -- ) { int sum = ( ( int ) ( str2 . charAt ( i ) - '0' ) + carry ) ; str += ( char ) ( sum % 10 + '0' ) ; carry = sum / 10 ; } if ( carry > 0 ) str += ( char ) ( carry + '0' ) ; return new StringBuilder ( str ) . reverse ( ) . toString ( ) ; } public static void main ( String [ ] args ) { String str1 = "12" ; String str2 = "198111" ; System . out . println ( findSum ( str1 , str2 ) ) ; } }

def findSum ( str1 , str2 ) : NEW_LINE INDENT if len ( str1 ) > len ( str2 ) : NEW_LINE INDENT temp = str1 NEW_LINE str1 = str2 NEW_LINE str2 = temp NEW_LINE DEDENT str3 = " " NEW_LINE n1 = len ( str1 ) NEW_LINE n2 = len ( str2 ) NEW_LINE diff = n2 - n1 NEW_LINE carry = 0 NEW_LINE for i in range ( n1 - 1 , - 1 , - 1 ) : NEW_LINE INDENT sum = ( ( ord ( str1 [ i ] ) - ord ( '0' ) ) + int ( ( ord ( str2 [ i + diff ] ) - ord ( '0' ) ) ) + carry ) NEW_LINE str3 = str3 + str ( sum % 10 ) NEW_LINE carry = sum // 10 NEW_LINE DEDENT for i in range ( n2 - n1 - 1 , - 1 , - 1 ) : NEW_LINE INDENT sum = ( ( ord ( str2 [ i ] ) - ord ( '0' ) ) + carry ) NEW_LINE str3 = str3 + str ( sum % 10 ) NEW_LINE carry = sum // 10 NEW_LINE DEDENT if ( carry ) : NEW_LINE INDENT str3 + str ( carry + '0' ) NEW_LINE DEDENT str3 = str3 [ : : - 1 ] NEW_LINE return str3 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = "12" NEW_LINE str2 = "198111" NEW_LINE print ( findSum ( str1 , str2 ) ) NEW_LINE DEDENT


class GFG { static int MAX = 11 ; static boolean isMultipleof5 ( int n ) { char str [ ] = new char [ MAX ] ; int len = str . length ; if ( str [ len - 1 ] == '5' || str [ len - 1 ] == '0' ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 19 ; if ( isMultipleof5 ( n ) == true ) System . out . println ( n + " ▁ is ▁ multiple ▁ " + " of ▁ 5" ) ; else System . out . println ( n + " ▁ is ▁ not ▁ a ▁ " + " multiple ▁ of ▁ 5" ) ; } }

MAX = 11 ; NEW_LINE def isMultipleof5 ( n ) : NEW_LINE INDENT s = str ( n ) ; NEW_LINE l = len ( s ) ; NEW_LINE if ( s [ l - 1 ] == '5' or s [ l - 1 ] == '0' ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT n = 19 ; NEW_LINE if ( isMultipleof5 ( n ) == True ) : NEW_LINE INDENT print ( n , " is ▁ multiple ▁ of ▁ 5" ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( n , " is ▁ not ▁ a ▁ multiple ▁ of ▁ 5" ) ; NEW_LINE DEDENT


class GfG { static void breakLine ( ) { System . out . print ( " \n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n " ) ; } static int MAX = 10 ; static int arr [ ] = new int [ MAX ] , no ; static void nQueens ( int k , int n ) { for ( int i = 1 ; i <= n ; i ++ ) { if ( canPlace ( k , i ) ) { arr [ k ] = i ; if ( k == n ) { display ( n ) ; } else { nQueens ( k + 1 , n ) ; } } } } static boolean canPlace ( int k , int i ) { for ( int j = 1 ; j <= k - 1 ; j ++ ) { if ( arr [ j ] == i || ( Math . abs ( arr [ j ] - i ) == Math . abs ( j - k ) ) ) { return false ; } } return true ; } static void display ( int n ) { breakLine ( ) ; System . out . print ( " Arrangement ▁ No . ▁ " + ++ no ) ; breakLine ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( arr [ i ] != j ) { System . out . print ( " \t _ " ) ; } else { System . out . print ( " \tQ " ) ; } } System . out . println ( " " ) ; } breakLine ( ) ; } public static void main ( String [ ] args ) { int n = 4 ; nQueens ( 1 , n ) ; } }

class GfG : NEW_LINE INDENT def __init__ ( self ) : NEW_LINE INDENT self . MAX = 10 NEW_LINE self . arr = [ 0 ] * self . MAX NEW_LINE self . no = 0 NEW_LINE DEDENT def breakLine ( self ) : NEW_LINE INDENT print ( " \n - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - " ) NEW_LINE DEDENT def canPlace ( self , k , i ) : NEW_LINE INDENT for j in range ( 1 , k ) : NEW_LINE INDENT if ( self . arr [ j ] == i or ( abs ( self . arr [ j ] - i ) == abs ( j - k ) ) ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def display ( self , n ) : NEW_LINE INDENT self . breakLine ( ) NEW_LINE self . no += 1 NEW_LINE print ( " Arrangement ▁ No . " , self . no , end = " ▁ " ) NEW_LINE self . breakLine ( ) NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if self . arr [ i ] != j : NEW_LINE INDENT print ( " \t _ " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " \tQ " , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT self . breakLine ( ) NEW_LINE DEDENT def nQueens ( self , k , n ) : NEW_LINE INDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if self . canPlace ( k , i ) : NEW_LINE INDENT self . arr [ k ] = i NEW_LINE if k == n : NEW_LINE INDENT self . display ( n ) NEW_LINE DEDENT else : NEW_LINE INDENT self . nQueens ( k + 1 , n ) NEW_LINE DEDENT DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE obj = GfG ( ) NEW_LINE obj . nQueens ( 1 , n ) NEW_LINE DEDENT


import java . util . Scanner ; public class GFG { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int a , b , i , j , flag ; System . out . printf ( " Enter ▁ lower ▁ bound ▁ of ▁ the ▁ interval : ▁ " ) ; a = sc . nextInt ( ) ; System . out . printf ( " \n Enter ▁ upper ▁ bound ▁ of ▁ the ▁ interval : ▁ " ) ; b = sc . nextInt ( ) ; System . out . printf ( " \n Prime ▁ numbers ▁ between ▁ % d ▁ and ▁ % d ▁ are : ▁ " , a , b ) ; for ( i = a ; i <= b ; i ++ ) { if ( i == 1 || i == 0 ) continue ; flag = 1 ; for ( j = 2 ; j <= i / 2 ; ++ j ) { if ( i % j == 0 ) { flag = 0 ; break ; } } if ( flag == 1 ) System . out . println ( i ) ; } } }

if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a , b , i , j , flag = 0 , 0 , 0 , 0 , 0 NEW_LINE print ( " Enter ▁ lower ▁ bound ▁ of ▁ the ▁ interval : " , end = " " ) NEW_LINE a = int ( input ( ) ) NEW_LINE print ( a ) NEW_LINE print ( " Enter ▁ upper ▁ bound ▁ of ▁ the ▁ interval : " , end = " " ) NEW_LINE b = int ( input ( ) ) NEW_LINE print ( b ) NEW_LINE print ( " Prime ▁ numbers ▁ between " , a , " and " , b , " are : " , end = " " ) NEW_LINE for i in range ( a , b + 1 ) : NEW_LINE INDENT if ( i == 1 ) : NEW_LINE INDENT continue NEW_LINE DEDENT flag = 1 NEW_LINE for j in range ( 2 , i // 2 + 1 ) : NEW_LINE INDENT if ( i % j == 0 ) : NEW_LINE INDENT flag = 0 NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == 1 ) : NEW_LINE INDENT print ( i , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT


import java . util . * ; class GFG { static final int N = 100005 ; static void createHash ( HashSet < Integer > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } static int longestFibonacciSubsequence ( int arr [ ] , int n ) { HashSet < Integer > hash = new HashSet < Integer > ( ) ; createHash ( hash , Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ) ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . contains ( arr [ i ] ) ) { answer ++ ; } } return answer ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 11 , 2 , 9 , 21 } ; int n = arr . length ; System . out . print ( longestFibonacciSubsequence ( arr , n ) + " \n " ) ; } }

N = 100005 NEW_LINE def createHash ( hash , maxElement ) : NEW_LINE INDENT prev = 0 NEW_LINE curr = 1 NEW_LINE hash . add ( prev ) NEW_LINE hash . add ( curr ) NEW_LINE while ( curr <= maxElement ) : NEW_LINE INDENT temp = curr + prev NEW_LINE hash . add ( temp ) NEW_LINE prev = curr NEW_LINE curr = temp NEW_LINE DEDENT DEDENT def longestFibonacciSubsequence ( arr , n ) : NEW_LINE INDENT hash = set ( ) NEW_LINE createHash ( hash , max ( arr ) ) NEW_LINE answer = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] in hash ) : NEW_LINE INDENT answer += 1 NEW_LINE DEDENT DEDENT return answer NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 4 , 11 , 2 , 9 , 21 ] NEW_LINE n = len ( arr ) NEW_LINE print ( longestFibonacciSubsequence ( arr , n ) ) NEW_LINE DEDENT


class GFG { static int countConsecutive ( String s ) { int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == s . charAt ( i + 1 ) ) { i ++ ; } else { count ++ ; } } return count ; } public static void main ( String args [ ] ) { String str = "44522255" ; System . out . println ( countConsecutive ( str ) ) ; } }

def countConsecutive ( s ) : NEW_LINE INDENT count = - 1 NEW_LINE for i in range ( len ( s ) - 1 ) : NEW_LINE INDENT if ( i <= len ( s ) ) : NEW_LINE INDENT if ( s [ i ] is s [ i + 1 ] ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str = "44522255" NEW_LINE print ( countConsecutive ( str ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void sortArray ( int a [ ] , int n ) { Vector < Integer > ans = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) ans . add ( a [ i ] ) ; } Collections . sort ( ans ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) { a [ i ] = ans . get ( j ) ; j ++ ; } } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( a [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , - 6 , - 3 , 8 , 4 , 1 } ; int n = arr . length ; sortArray ( arr , n ) ; } }

def sortArray ( a , n ) : NEW_LINE INDENT ans = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] >= 0 ) : NEW_LINE INDENT ans . append ( a [ i ] ) NEW_LINE DEDENT DEDENT ans = sorted ( ans ) NEW_LINE j = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] >= 0 ) : NEW_LINE INDENT a [ i ] = ans [ j ] NEW_LINE j += 1 NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 2 , - 6 , - 3 , 8 , 4 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE sortArray ( arr , n ) NEW_LINE


class GFG { static boolean checkSubarraySum ( int arr [ ] , int n , int k , int sum ) { for ( int i = 0 ; i < n - k + 1 ; i ++ ) { int current_sum = 0 ; for ( int j = 0 ; j < k ; j ++ ) current_sum = current_sum + arr [ i + j ] ; if ( current_sum == sum ) return true ; } return false ; } public static void main ( String args [ ] ) { int arr [ ] = new int [ ] { 1 , 4 , 2 , 10 , 2 , 3 , 1 , 0 , 20 } ; int k = 4 ; int sum = 18 ; int n = arr . length ; if ( checkSubarraySum ( arr , n , k , sum ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

def checkSubarraySum ( arr , n , k , sum ) : NEW_LINE INDENT for i in range ( n - k + 1 ) : NEW_LINE INDENT current_sum = 0 ; NEW_LINE for j in range ( k ) : NEW_LINE INDENT current_sum = ( current_sum + arr [ i + j ] ) ; NEW_LINE DEDENT if ( current_sum == sum ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT arr = [ 1 , 4 , 2 , 10 , 2 , 3 , 1 , 0 , 20 ] ; NEW_LINE k = 4 ; NEW_LINE sum = 18 ; NEW_LINE n = len ( arr ) ; NEW_LINE if ( checkSubarraySum ( arr , n , k , sum ) ) : NEW_LINE INDENT print ( " YES " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) ; NEW_LINE DEDENT


class GFG { static boolean isPossible ( int arr [ ] , int n , int dist , int k ) { int req = 0 ; int curr = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( curr != n && arr [ curr ] - arr [ prev ] <= dist ) { curr ++ ; } req ++ ; if ( curr == n ) { break ; } prev = curr - 1 ; } if ( curr != n ) { return false ; } if ( req <= k ) { return true ; } return false ; } static int minDistance ( int arr [ ] , int n , int k ) { int l = 0 ; int h = arr [ n - 1 ] ; int ans = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( isPossible ( arr , n , m , k ) ) { ans = m ; h = m - 1 ; } else { l = m + 1 ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 15 , 36 , 43 } ; int n = arr . length ; int k = 2 ; System . out . println ( minDistance ( arr , n , k ) ) ; } }

def isPossible ( arr , n , dist , k ) : NEW_LINE INDENT req = 0 NEW_LINE curr = 0 NEW_LINE prev = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT while ( curr != n and ( arr [ curr ] - arr [ prev ] ) <= dist ) : NEW_LINE INDENT curr = curr + 1 NEW_LINE DEDENT req = req + 1 NEW_LINE if ( curr == n ) : NEW_LINE INDENT break NEW_LINE DEDENT prev = curr - 1 NEW_LINE DEDENT if ( curr != n ) : NEW_LINE INDENT return False NEW_LINE DEDENT if ( req <= k ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT def minDistance ( arr , n , k ) : NEW_LINE INDENT l = 0 NEW_LINE h = arr [ n - 1 ] NEW_LINE ans = 0 NEW_LINE while ( l <= h ) : NEW_LINE INDENT m = ( l + h ) // 2 ; NEW_LINE if ( isPossible ( arr , n , m , k ) ) : NEW_LINE INDENT ans = m NEW_LINE h = m - 1 NEW_LINE DEDENT else : NEW_LINE INDENT l = m + 1 NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT arr = [ 2 , 15 , 36 , 43 ] NEW_LINE n = len ( arr ) NEW_LINE k = 2 NEW_LINE print ( minDistance ( arr , n , k ) ) NEW_LINE


import java . util . * ; class GFG { static final int MAX = 10000 ; static int prefix [ ] = new int [ MAX + 1 ] ; static void buildPrefix ( ) { boolean prime [ ] = new boolean [ MAX + 1 ] ; Arrays . fill ( prime , true ) ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( int p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] ) prefix [ p ] ++ ; } } static int query ( int L , int R ) { return prefix [ R ] - prefix [ L - 1 ] ; } public static void main ( String [ ] args ) { buildPrefix ( ) ; int L = 5 , R = 10 ; System . out . println ( query ( L , R ) ) ; L = 1 ; R = 10 ; System . out . println ( query ( L , R ) ) ; } }

MAX = 10000 NEW_LINE prefix = [ 0 ] * ( MAX + 1 ) NEW_LINE def buildPrefix ( ) : NEW_LINE INDENT prime = [ 1 ] * ( MAX + 1 ) NEW_LINE p = 2 NEW_LINE while ( p * p <= MAX ) : NEW_LINE INDENT if ( prime [ p ] == 1 ) : NEW_LINE INDENT i = p * 2 NEW_LINE while ( i <= MAX ) : NEW_LINE INDENT prime [ i ] = 0 NEW_LINE i += p NEW_LINE DEDENT DEDENT p += 1 NEW_LINE DEDENT for p in range ( 2 , MAX + 1 ) : NEW_LINE INDENT prefix [ p ] = prefix [ p - 1 ] NEW_LINE if ( prime [ p ] == 1 ) : NEW_LINE INDENT prefix [ p ] += 1 NEW_LINE DEDENT DEDENT DEDENT def query ( L , R ) : NEW_LINE INDENT return prefix [ R ] - prefix [ L - 1 ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT buildPrefix ( ) NEW_LINE L = 5 NEW_LINE R = 10 NEW_LINE print ( query ( L , R ) ) NEW_LINE L = 1 NEW_LINE R = 10 NEW_LINE print ( query ( L , R ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int MAX = 100000 ; static ArrayList < Integer > primes = new ArrayList < Integer > ( ) ; static void sieve ( ) { boolean [ ] isComposite = new boolean [ MAX + 1 ] ; for ( int i = 2 ; i * i <= MAX ; i ++ ) { if ( isComposite [ i ] == false ) for ( int j = 2 ; j * i <= MAX ; j ++ ) isComposite [ i * j ] = true ; } for ( int i = 2 ; i <= MAX ; i ++ ) if ( isComposite [ i ] == false ) primes . add ( i ) ; } static long LCM ( int n ) { long lcm = 1 ; for ( int i = 0 ; i < primes . size ( ) && primes . get ( i ) <= n ; i ++ ) { int pp = primes . get ( i ) ; while ( pp * primes . get ( i ) <= n ) pp = pp * primes . get ( i ) ; lcm *= pp ; lcm %= 1000000007 ; } return lcm ; } public static void main ( String [ ] args ) { sieve ( ) ; int N = 7 ; System . out . println ( LCM ( N ) ) ; } }

MAX = 100000 ; NEW_LINE primes = [ ] ; NEW_LINE def sieve ( ) : NEW_LINE INDENT isComposite = [ False ] * ( MAX + 1 ) ; NEW_LINE i = 2 ; NEW_LINE while ( i * i <= MAX ) : NEW_LINE INDENT if ( isComposite [ i ] == False ) : NEW_LINE INDENT j = 2 ; NEW_LINE while ( j * i <= MAX ) : NEW_LINE INDENT isComposite [ i * j ] = True ; NEW_LINE j += 1 ; NEW_LINE DEDENT DEDENT i += 1 ; NEW_LINE DEDENT for i in range ( 2 , MAX + 1 ) : NEW_LINE INDENT if ( isComposite [ i ] == False ) : NEW_LINE INDENT primes . append ( i ) ; NEW_LINE DEDENT DEDENT DEDENT def LCM ( n ) : NEW_LINE INDENT lcm = 1 ; NEW_LINE i = 0 ; NEW_LINE while ( i < len ( primes ) and primes [ i ] <= n ) : NEW_LINE INDENT pp = primes [ i ] ; NEW_LINE while ( pp * primes [ i ] <= n ) : NEW_LINE INDENT pp = pp * primes [ i ] ; NEW_LINE DEDENT lcm *= pp ; NEW_LINE lcm %= 1000000007 ; NEW_LINE i += 1 ; NEW_LINE DEDENT return lcm ; NEW_LINE DEDENT sieve ( ) ; NEW_LINE N = 7 ; NEW_LINE print ( LCM ( N ) ) ; NEW_LINE


import java . io . * ; class GFG { static void getElements ( int a , int arr [ ] , int n ) { int elements [ ] = new int [ n + 1 ] ; elements [ 0 ] = a ; for ( int i = 0 ; i < n ; i ++ ) { elements [ i + 1 ] = arr [ i ] ^ elements [ i ] ; } for ( int i = 0 ; i < n + 1 ; i ++ ) System . out . print ( elements [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 13 , 2 , 6 , 1 } ; int n = arr . length ; int a = 5 ; getElements ( a , arr , n ) ; } }

def getElements ( a , arr , n ) : NEW_LINE INDENT elements = [ 1 for i in range ( n + 1 ) ] NEW_LINE elements [ 0 ] = a NEW_LINE for i in range ( n ) : NEW_LINE INDENT elements [ i + 1 ] = arr [ i ] ^ elements [ i ] NEW_LINE DEDENT for i in range ( n + 1 ) : NEW_LINE INDENT print ( elements [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 13 , 2 , 6 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE a = 5 NEW_LINE getElements ( a , arr , n ) NEW_LINE


class GFG { static int N = 1000005 ; static void sumOddDigit ( int digitSum [ ] ) { for ( int i = 1 ; i < N ; i ++ ) { digitSum [ i ] = digitSum [ i / 10 ] + ( i & 1 ) * ( i % 10 ) ; } } static void sumFactor ( int digitSum [ ] , int factorDigitSum [ ] ) { for ( int i = 1 ; i < N ; i ++ ) { for ( int j = i ; j < N ; j += i ) { factorDigitSum [ j ] += digitSum [ i ] ; } } } static void wrapper ( int q , int n [ ] ) { int digitSum [ ] = new int [ N ] ; int factorDigitSum [ ] = new int [ N ] ; sumOddDigit ( digitSum ) ; sumFactor ( digitSum , factorDigitSum ) ; for ( int i = 0 ; i < q ; i ++ ) System . out . print ( factorDigitSum [ n [ i ] ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int q = 2 ; int n [ ] = new int [ ] { 10 , 36 } ; wrapper ( q , n ) ; } }

N = 100 NEW_LINE digitSum = [ 0 ] * N NEW_LINE factorDigitSum = [ 0 ] * N NEW_LINE def sumOddDigit ( ) : NEW_LINE INDENT global N , digitSum , factorDigitSum NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT digitSum [ i ] = ( digitSum [ int ( i / 10 ) ] + int ( i & 1 ) * ( i % 10 ) ) NEW_LINE DEDENT DEDENT def sumFactor ( ) : NEW_LINE INDENT global N , digitSum , factorDigitSum NEW_LINE j = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT j = i NEW_LINE while ( j < N ) : NEW_LINE INDENT factorDigitSum [ j ] = ( factorDigitSum [ j ] + digitSum [ i ] ) NEW_LINE j = j + i NEW_LINE DEDENT DEDENT DEDENT def wrapper ( q , n ) : NEW_LINE INDENT global N , digitSum , factorDigitSum NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT digitSum [ i ] = 0 NEW_LINE factorDigitSum [ i ] = 0 NEW_LINE DEDENT sumOddDigit ( ) NEW_LINE sumFactor ( ) NEW_LINE for i in range ( 0 , q ) : NEW_LINE INDENT print ( " { } ▁ " . format ( factorDigitSum [ n [ i ] ] ) , end = " " ) NEW_LINE DEDENT DEDENT q = 2 NEW_LINE n = [ 10 , 36 ] NEW_LINE wrapper ( q , n ) NEW_LINE


import java . lang . * ; class GFG { static double PI = 3.14159265 ; public static double area_leaf ( double a ) { return ( a * a * ( PI / 2 - 1 ) ) ; } public static void main ( String [ ] args ) { double a = 7 ; System . out . println ( area_leaf ( a ) ) ; } }

PI = 3.14159265 NEW_LINE def area_leaf ( a ) : NEW_LINE INDENT return ( a * a * ( PI / 2 - 1 ) ) NEW_LINE DEDENT a = 7 NEW_LINE print ( area_leaf ( a ) ) NEW_LINE