import java . io . * ; class GFG { static int lenghtOfLongestAP ( int set [ ] , int n ) { if ( n <= 2 ) return n ; int L [ ] [ ] = new int [ n ] [ n ] ; int llap = 2 ; for ( int i = 0 ; i < n ; i ++ ) L [ i ] [ n - 1 ] = 2 ; for ( int j = n - 2 ; j >= 1 ; j -- ) { int i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] < 2 * set [ j ] ) k ++ ; else if ( set [ i ] + set [ k ] > 2 * set [ j ] ) { L [ i ] [ j ] = 2 ; i -- ; } else { L [ i ] [ j ] = L [ j ] [ k ] + 1 ; llap = Math . max ( llap , L [ i ] [ j ] ) ; i -- ; k ++ ; } } while ( i >= 0 ) { L [ i ] [ j ] = 2 ; i -- ; } } return llap ; } public static void main ( String [ ] args ) { int set1 [ ] = { 1 , 7 , 10 , 13 , 14 , 19 } ; int n1 = set1 . length ; System . out . println ( lenghtOfLongestAP ( set1 , n1 ) ) ; int set2 [ ] = { 1 , 7 , 10 , 15 , 27 , 29 } ; int n2 = set2 . length ; System . out . println ( lenghtOfLongestAP ( set2 , n2 ) ) ; int set3 [ ] = { 2 , 4 , 6 , 8 , 10 } ; int n3 = set3 . length ; System . out . println ( lenghtOfLongestAP ( set3 , n3 ) ) ; } }

def lenghtOfLongestAP ( set , n ) : NEW_LINE INDENT if ( n <= 2 ) : NEW_LINE INDENT return n NEW_LINE DEDENT L = [ [ 0 for x in range ( n ) ] for y in range ( n ) ] NEW_LINE llap = 2 NEW_LINE for i in range ( n ) : NEW_LINE INDENT L [ i ] [ n - 1 ] = 2 NEW_LINE DEDENT for j in range ( n - 2 , 0 , - 1 ) : NEW_LINE INDENT i = j - 1 NEW_LINE k = j + 1 NEW_LINE while ( i >= 0 and k <= n - 1 ) : NEW_LINE INDENT if ( set [ i ] + set [ k ] < 2 * set [ j ] ) : NEW_LINE INDENT k += 1 NEW_LINE DEDENT elif ( set [ i ] + set [ k ] > 2 * set [ j ] ) : NEW_LINE INDENT L [ i ] [ j ] = 2 NEW_LINE i -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT L [ i ] [ j ] = L [ j ] [ k ] + 1 NEW_LINE llap = max ( llap , L [ i ] [ j ] ) NEW_LINE i -= 1 NEW_LINE k += 1 NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT L [ i ] [ j ] = 2 NEW_LINE i -= 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return llap NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT set1 = [ 1 , 7 , 10 , 13 , 14 , 19 ] NEW_LINE n1 = len ( set1 ) NEW_LINE print ( lenghtOfLongestAP ( set1 , n1 ) ) NEW_LINE set2 = [ 1 , 7 , 10 , 15 , 27 , 29 ] NEW_LINE n2 = len ( set2 ) NEW_LINE print ( lenghtOfLongestAP ( set2 , n2 ) ) NEW_LINE set3 = [ 2 , 4 , 6 , 8 , 10 ] NEW_LINE n3 = len ( set3 ) NEW_LINE print ( lenghtOfLongestAP ( set3 , n3 ) ) NEW_LINE DEDENT


import java . util . Stack ; class Test { static Stack < Character > st = new Stack < > ( ) ; static void insert_at_bottom ( char x ) { if ( st . isEmpty ( ) ) st . push ( x ) ; else { char a = st . peek ( ) ; st . pop ( ) ; insert_at_bottom ( x ) ; st . push ( a ) ; } } static void reverse ( ) { if ( st . size ( ) > 0 ) { char x = st . peek ( ) ; st . pop ( ) ; reverse ( ) ; insert_at_bottom ( x ) ; } } public static void main ( String [ ] args ) { st . push ( '1' ) ; st . push ( '2' ) ; st . push ( '3' ) ; st . push ( '4' ) ; System . out . println ( " Original ▁ Stack " ) ; System . out . println ( st ) ; reverse ( ) ; System . out . println ( " Reversed ▁ Stack " ) ; System . out . println ( st ) ; } }

def insertAtBottom ( stack , item ) : NEW_LINE INDENT if isEmpty ( stack ) : NEW_LINE INDENT push ( stack , item ) NEW_LINE DEDENT else : NEW_LINE INDENT temp = pop ( stack ) NEW_LINE insertAtBottom ( stack , item ) NEW_LINE push ( stack , temp ) NEW_LINE DEDENT DEDENT def reverse ( stack ) : NEW_LINE INDENT if not isEmpty ( stack ) : NEW_LINE INDENT temp = pop ( stack ) NEW_LINE reverse ( stack ) NEW_LINE insertAtBottom ( stack , temp ) NEW_LINE DEDENT DEDENT def createStack ( ) : NEW_LINE INDENT stack = [ ] NEW_LINE return stack NEW_LINE DEDENT def isEmpty ( stack ) : NEW_LINE INDENT return len ( stack ) == 0 NEW_LINE DEDENT def push ( stack , item ) : NEW_LINE INDENT stack . append ( item ) NEW_LINE DEDENT def pop ( stack ) : NEW_LINE INDENT if ( isEmpty ( stack ) ) : NEW_LINE INDENT print ( " Stack ▁ Underflow ▁ " ) NEW_LINE exit ( 1 ) NEW_LINE DEDENT return stack . pop ( ) NEW_LINE DEDENT def prints ( stack ) : NEW_LINE INDENT for i in range ( len ( stack ) - 1 , - 1 , - 1 ) : NEW_LINE INDENT print ( stack [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT stack = createStack ( ) NEW_LINE push ( stack , str ( 4 ) ) NEW_LINE push ( stack , str ( 3 ) ) NEW_LINE push ( stack , str ( 2 ) ) NEW_LINE push ( stack , str ( 1 ) ) NEW_LINE print ( " Original ▁ Stack ▁ " ) NEW_LINE prints ( stack ) NEW_LINE reverse ( stack ) NEW_LINE print ( " Reversed ▁ Stack ▁ " ) NEW_LINE prints ( stack ) NEW_LINE


class GFG { static void half ( int arr [ ] , int n ) { int i ; int flag = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) System . out . print ( arr [ i ] / 2 + " ▁ " ) ; else { if ( flag == 0 ) { System . out . print ( arr [ i ] / 2 - 1 + " ▁ " ) ; flag = 1 ; } else { int q = arr [ i ] / 2 ; System . out . print ( q + " ▁ " ) ; flag = 0 ; } } } } public static void main ( String [ ] args ) { int arr [ ] = { - 7 , 14 , - 7 } ; int len = arr . length ; half ( arr , len ) ; } }

def half ( arr , n ) : NEW_LINE INDENT flag = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if arr [ i ] % 2 == 0 : NEW_LINE INDENT print ( arr [ i ] // 2 , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT if flag == 0 : NEW_LINE INDENT print ( arr [ i ] // 2 , end = " ▁ " ) NEW_LINE flag = 1 NEW_LINE DEDENT else : NEW_LINE INDENT q = arr [ i ] // 2 NEW_LINE q += 1 NEW_LINE print ( q , end = " ▁ " ) NEW_LINE flag = 0 NEW_LINE DEDENT DEDENT DEDENT DEDENT arr = [ - 7 , 14 , - 7 ] NEW_LINE half ( arr , len ( arr ) ) NEW_LINE


import java . util . * ; class GFG { static void EvenOddLength ( int arr [ ] , int n ) { int even = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String x = Integer . toString ( arr [ i ] ) ; if ( x . length ( ) % 2 == 0 ) even ++ ; } System . out . println ( " Number ▁ of ▁ even ▁ length ▁ elements ▁ = ▁ " + even ) ; System . out . println ( " Number ▁ of ▁ odd ▁ length ▁ elements ▁ = ▁ " + ( n - even ) ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 12 , 44 , 213 , 232 , 3433 } ; int n = arr . length ; EvenOddLength ( arr , n ) ; } }

def EvenOddLength ( arr , n ) : NEW_LINE INDENT even = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = str ( arr [ i ] ) NEW_LINE if ( len ( x ) % 2 == 0 ) : NEW_LINE INDENT even += 1 NEW_LINE DEDENT DEDENT print ( " Number ▁ of ▁ even ▁ length ▁ elements ▁ = ▁ " , even ) NEW_LINE print ( " Number ▁ of ▁ odd ▁ length ▁ elements ▁ = ▁ " , n - even ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 12 , 44 , 213 , 232 , 3433 ] NEW_LINE n = len ( arr ) NEW_LINE EvenOddLength ( arr , n ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int mod = ( int ) ( 1e9 + 7 ) ; static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int findCount ( int N ) { int count = power ( 2 , N , mod ) ; return count ; } public static void main ( String [ ] args ) { int N = 25 ; System . out . println ( findCount ( N ) ) ; } }

mod = 1000000007 NEW_LINE def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def findCount ( N ) : NEW_LINE INDENT count = power ( 2 , N , mod ) NEW_LINE return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 25 NEW_LINE print ( findCount ( N ) ) NEW_LINE DEDENT


import static java . lang . Math . pow ; class Test { static int sumOfTermsInNthRow ( int n ) { int sum = ( int ) ( n * ( 2 * pow ( n , 2 ) + 1 ) ) ; return sum ; } public static void main ( String args [ ] ) { int n = 4 ; System . out . println ( " Sum ▁ of ▁ all ▁ the ▁ terms ▁ in ▁ nth ▁ row ▁ = ▁ " + sumOfTermsInNthRow ( n ) ) ; } }

from math import pow NEW_LINE def sumOfTermsInNthRow ( n ) : NEW_LINE INDENT sum = n * ( 2 * pow ( n , 2 ) + 1 ) NEW_LINE return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE print ( " Sum ▁ of ▁ all ▁ the ▁ terms ▁ in ▁ nth ▁ row ▁ = " , int ( sumOfTermsInNthRow ( n ) ) ) NEW_LINE DEDENT


import java . util . Stack ; public class GFG { static long smallestNumber ( int n ) { if ( n >= 0 && n <= 9 ) { return n ; } Stack < Integer > digits = new Stack < > ( ) ; for ( int i = 9 ; i >= 2 && n > 1 ; i -- ) { while ( n % i == 0 ) { digits . push ( i ) ; n = n / i ; } } if ( n != 1 ) { return - 1 ; } long k = 0 ; while ( ! digits . empty ( ) ) { k = k * 10 + digits . peek ( ) ; digits . pop ( ) ; } return k ; } static public void main ( String [ ] args ) { int n = 100 ; System . out . println ( smallestNumber ( n ) ) ; } }

import math as mt NEW_LINE def smallestNumber ( n ) : NEW_LINE INDENT if ( n >= 0 and n <= 9 ) : NEW_LINE INDENT return n NEW_LINE DEDENT digits = list ( ) NEW_LINE for i in range ( 9 , 1 , - 1 ) : NEW_LINE INDENT while ( n % i == 0 ) : NEW_LINE INDENT digits . append ( i ) NEW_LINE n = n // i NEW_LINE DEDENT DEDENT if ( n != 1 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT k = 0 NEW_LINE while ( len ( digits ) != 0 ) : NEW_LINE INDENT k = k * 10 + digits [ - 1 ] NEW_LINE digits . pop ( ) NEW_LINE DEDENT return k NEW_LINE DEDENT n = 100 NEW_LINE print ( smallestNumber ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int sumOfDigitsFrom1ToN ( int n ) { int result = 0 ; for ( int x = 1 ; x <= n ; x ++ ) result += sumOfDigits ( x ) ; return result ; } static int sumOfDigits ( int x ) { int sum = 0 ; while ( x != 0 ) { sum += x % 10 ; x = x / 10 ; } return sum ; } public static void main ( String args [ ] ) { int n = 328 ; System . out . println ( " Sum ▁ of ▁ digits ▁ in ▁ numbers " + " ▁ from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

def sumOfDigitsFrom1ToN ( n ) : NEW_LINE INDENT result = 0 NEW_LINE for x in range ( 1 , n + 1 ) : NEW_LINE INDENT result = result + sumOfDigits ( x ) NEW_LINE DEDENT return result NEW_LINE DEDENT def sumOfDigits ( x ) : NEW_LINE INDENT sum = 0 NEW_LINE while ( x != 0 ) : NEW_LINE INDENT sum = sum + x % 10 NEW_LINE x = x // 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 328 NEW_LINE print ( " Sum ▁ of ▁ digits ▁ in ▁ numbers ▁ from ▁ 1 ▁ to " , n , " is " , sumOfDigitsFrom1ToN ( n ) ) NEW_LINE


import java . io . * ; class GFG { static float trianglearea ( float r ) { if ( r < 0 ) return - 1 ; return r * r ; } public static void main ( String [ ] args ) { float r = 5 ; System . out . println ( trianglearea ( r ) ) ; } }

def trianglearea ( r ) : NEW_LINE INDENT if r < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT return r * r NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT r = 5 NEW_LINE print ( trianglearea ( r ) ) NEW_LINE DEDENT


class GFG { static public int LongestSubarray ( int arr [ ] , int n , int k ) { int count = 1 ; int max_length = 1 ; int prev_mod = arr [ 0 ] % k ; for ( int i = 1 ; i < n ; i ++ ) { int curr_mod = arr [ i ] % k ; if ( curr_mod == prev_mod ) { count ++ ; } else { max_length = Math . max ( max_length , count ) ; count = 1 ; prev_mod = curr_mod ; } } return max_length ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 9 , 7 , 18 , 29 , 11 } ; int n = arr . length ; int k = 11 ; System . out . print ( LongestSubarray ( arr , n , k ) ) ; } }

def LongestSubarray ( arr , n , k ) : NEW_LINE INDENT count = 1 NEW_LINE max_lenght = 1 NEW_LINE prev_mod = arr [ 0 ] % k NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT curr_mod = arr [ i ] % k NEW_LINE if curr_mod == prev_mod : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT max_lenght = max ( max_lenght , count ) NEW_LINE count = 1 NEW_LINE prev_mod = curr_mod NEW_LINE DEDENT DEDENT return max_lenght NEW_LINE DEDENT arr = [ 4 , 9 , 7 , 18 , 29 , 11 ] NEW_LINE n = len ( arr ) NEW_LINE k = 11 NEW_LINE print ( LongestSubarray ( arr , n , k ) ) NEW_LINE


class GFG { static int N = 3 ; static int M = 7 ; static void printOriginalMatrix ( int a [ ] , int b [ ] , int [ ] [ ] mat ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) System . out . print ( Math . min ( a [ i ] , b [ j ] ) + " ▁ " ) ; else System . out . print ( "0" + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int a [ ] = { 2 , 1 , 3 } ; int b [ ] = { 2 , 3 , 0 , 0 , 2 , 0 , 1 } ; int [ ] [ ] mat = { { 1 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 1 , 1 , 0 , 0 , 0 , 0 , 0 } } ; printOriginalMatrix ( a , b , mat ) ; } }

N = 3 NEW_LINE M = 7 NEW_LINE def printOriginalMatrix ( a , b , mat ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT for j in range ( M ) : NEW_LINE INDENT if ( mat [ i ] [ j ] == 1 ) : NEW_LINE INDENT print ( min ( a [ i ] , b [ j ] ) , end = " ▁ " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( 0 , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 2 , 1 , 3 ] NEW_LINE b = [ 2 , 3 , 0 , 0 , 2 , 0 , 1 ] NEW_LINE mat = [ [ 1 , 0 , 0 , 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 , 0 , 1 ] , [ 1 , 1 , 0 , 0 , 0 , 0 , 0 ] ] ; NEW_LINE printOriginalMatrix ( a , b , mat ) ; NEW_LINE DEDENT


class Xor { static int maxXORInRange ( int L , int R ) { int LXR = L ^ R ; int msbPos = 0 ; while ( LXR > 0 ) { msbPos ++ ; LXR >>= 1 ; } int maxXOR = 0 ; int two = 1 ; while ( msbPos -- > 0 ) { maxXOR += two ; two <<= 1 ; } return maxXOR ; } public static void main ( String [ ] args ) { int L = 8 ; int R = 20 ; System . out . println ( maxXORInRange ( L , R ) ) ; } }

def maxXORInRange ( L , R ) : NEW_LINE INDENT LXR = L ^ R NEW_LINE msbPos = 0 NEW_LINE while ( LXR ) : NEW_LINE INDENT msbPos += 1 NEW_LINE LXR >>= 1 NEW_LINE DEDENT maxXOR , two = 0 , 1 NEW_LINE while ( msbPos ) : NEW_LINE INDENT maxXOR += two NEW_LINE two <<= 1 NEW_LINE msbPos -= 1 NEW_LINE DEDENT return maxXOR NEW_LINE DEDENT L , R = 8 , 20 NEW_LINE print ( maxXORInRange ( L , R ) ) NEW_LINE


class GFG { static int printKDistinct ( int arr [ ] , int n , int k ) { int dist_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < n ; j ++ ) if ( i != j && arr [ j ] == arr [ i ] ) break ; if ( j == n ) dist_count ++ ; if ( dist_count == k ) return arr [ i ] ; } return - 1 ; } public static void main ( String [ ] args ) { int ar [ ] = { 1 , 2 , 1 , 3 , 4 , 2 } ; int n = ar . length ; int k = 2 ; System . out . print ( printKDistinct ( ar , n , k ) ) ; } }

def printKDistinct ( arr , n , k ) : NEW_LINE INDENT dist_count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT j = 0 NEW_LINE while j < n : NEW_LINE INDENT if ( i != j and arr [ j ] == arr [ i ] ) : NEW_LINE INDENT break NEW_LINE DEDENT j += 1 NEW_LINE DEDENT if ( j == n ) : NEW_LINE INDENT dist_count += 1 NEW_LINE DEDENT if ( dist_count == k ) : NEW_LINE INDENT return arr [ i ] NEW_LINE DEDENT DEDENT return - 1 NEW_LINE DEDENT ar = [ 1 , 2 , 1 , 3 , 4 , 2 ] NEW_LINE n = len ( ar ) NEW_LINE k = 2 NEW_LINE print ( printKDistinct ( ar , n , k ) ) NEW_LINE


class GFG { static int [ ] [ ] [ ] dp = new int [ 100 ] [ 100 ] [ 100 ] ; static int countString ( int m , int n , String [ ] arr , int i ) { if ( m < 0 || n < 0 ) { return Integer . MIN_VALUE ; } if ( i >= arr . length ) { return 0 ; } if ( dp [ m ] [ n ] [ i ] != - 1 ) { return dp [ m ] [ n ] [ i ] ; } int zero = 0 , one = 0 ; for ( char c : arr [ i ] . toCharArray ( ) ) { if ( c == '0' ) { zero ++ ; } else { one ++ ; } } int x = 1 + countString ( m - zero , n - one , arr , i + 1 ) ; int y = countString ( m , n , arr , i + 1 ) ; return dp [ m ] [ n ] [ i ] = Math . max ( x , y ) ; } public static void main ( String [ ] args ) { String [ ] arr = { "10" , "0001" , "1" , "111001" , "0" } ; int N = 3 , M = 5 ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) { for ( int l = 0 ; l < 100 ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } System . out . print ( countString ( M , N , arr , 0 ) ) ; } }

import sys NEW_LINE dp = [ [ [ - 1 for i in range ( 100 ) ] for j in range ( 100 ) ] for k in range ( 100 ) ] NEW_LINE def countString ( m , n , arr , i ) : NEW_LINE INDENT if ( m < 0 or n < 0 ) : NEW_LINE INDENT return - sys . maxsize - 1 NEW_LINE DEDENT if ( i >= len ( arr ) ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( dp [ m ] [ n ] [ i ] != - 1 ) : NEW_LINE INDENT return dp [ m ] [ n ] [ i ] NEW_LINE DEDENT zero = 0 NEW_LINE one = 0 NEW_LINE for c in arr [ i ] : NEW_LINE INDENT if ( c == '0' ) : NEW_LINE INDENT zero += 1 NEW_LINE DEDENT else : NEW_LINE INDENT one += 1 NEW_LINE DEDENT DEDENT x = 1 + countString ( m - zero , n - one , arr , i + 1 ) NEW_LINE y = countString ( m , n , arr , i + 1 ) NEW_LINE dp [ m ] [ n ] [ i ] = max ( x , y ) NEW_LINE return dp [ m ] [ n ] [ i ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ "10" , "0001" , "1" , "111001" , "0" ] NEW_LINE N = 3 NEW_LINE M = 5 NEW_LINE print ( countString ( M , N , arr , 0 ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void checksum ( int n ) { if ( n == 0 ) { System . out . println ( " - 2 ▁ - 1 ▁ 0 ▁ 1 ▁ 2" ) ; return ; } int inc ; if ( n > 0 ) inc = 1 ; else inc = - 1 ; for ( int i = 0 ; i <= n - 4 ; i += inc ) { if ( i + i + 1 + i + 2 + i + 3 + i + 4 == n ) { System . out . print ( ( i ) + " ▁ " + ( i + 1 ) + " ▁ " + ( i + 2 ) + " ▁ " + ( i + 3 ) + " ▁ " + ( i + 4 ) ) ; return ; } } System . out . println ( " - 1" ) ; } public static void main ( String [ ] args ) { int n = 15 ; checksum ( n ) ; } }

def checksum ( n ) : NEW_LINE INDENT if n == 0 : NEW_LINE INDENT print ( " - 2 ▁ - 1 ▁ 0 ▁ 1 ▁ 2" ) NEW_LINE return 0 NEW_LINE DEDENT inc = 0 NEW_LINE if n > 0 : NEW_LINE INDENT inc = 1 NEW_LINE DEDENT else : NEW_LINE INDENT inc = - 1 NEW_LINE DEDENT for i in range ( 0 , n - 3 , inc ) : NEW_LINE INDENT if i + i + 1 + i + 2 + i + 3 + i + 4 == n : NEW_LINE INDENT print ( i , " ▁ " , i + 1 , " ▁ " , i + 2 , " ▁ " , i + 3 , " ▁ " , i + 4 ) NEW_LINE return 0 NEW_LINE DEDENT DEDENT print ( " - 1" ) NEW_LINE DEDENT n = 15 NEW_LINE checksum ( n ) NEW_LINE


import java . util . * ; class GFG { static int maxValue ( int arr [ ] , int n , int moves ) { for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > 0 ) { int distance = n - 1 - i ; if ( moves < distance ) break ; int can_take = moves / distance ; int take = Math . min ( arr [ i ] , can_take ) ; arr [ n - 1 ] += take ; moves -= take * distance ; } } return arr [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 0 , 1 } ; int M = 5 ; int N = arr . length ; System . out . print ( maxValue ( arr , N , M ) ) ; } }

def maxValue ( arr , n , moves ) : NEW_LINE INDENT for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT distance = n - 1 - i NEW_LINE if ( moves < distance ) : NEW_LINE INDENT break NEW_LINE DEDENT can_take = moves // distance NEW_LINE take = min ( arr [ i ] , can_take ) NEW_LINE arr [ n - 1 ] += take NEW_LINE moves -= take * distance NEW_LINE DEDENT DEDENT return arr [ n - 1 ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 0 , 1 ] NEW_LINE M = 5 NEW_LINE N = len ( arr ) NEW_LINE print ( maxValue ( arr , N , M ) ) NEW_LINE DEDENT


class GFG { static int firstDigit ( int n ) { int fact = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { fact = fact * i ; while ( fact % 10 == 0 ) fact = fact / 10 ; } while ( fact >= 10 ) fact = fact / 10 ; return fact ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( firstDigit ( n ) ) ; } }

import math NEW_LINE def firstDigit ( n ) : NEW_LINE INDENT fact = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT fact = fact * i NEW_LINE while ( fact % 10 == 0 ) : NEW_LINE INDENT fact = int ( fact / 10 ) NEW_LINE DEDENT DEDENT while ( fact >= 10 ) : NEW_LINE INDENT fact = int ( fact / 10 ) NEW_LINE DEDENT return math . floor ( fact ) NEW_LINE DEDENT n = 5 NEW_LINE print ( firstDigit ( n ) ) NEW_LINE


import java . util . * ; class solution { static void checkIfPossibleRec ( int x , int a , int b , boolean isPossible [ ] , int n ) { if ( x > n ) return ; if ( isPossible [ x ] ) return ; isPossible [ x ] = true ; checkIfPossibleRec ( x + a , a , b , isPossible , n ) ; checkIfPossibleRec ( x + b , a , b , isPossible , n ) ; } static boolean checkPossible ( int n , int a , int b ) { boolean isPossible [ ] = new boolean [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) isPossible [ i ] = false ; checkIfPossibleRec ( 0 , a , b , isPossible , n ) ; return isPossible [ n ] ; } public static void main ( String args [ ] ) { int a = 3 , b = 7 , n = 8 ; if ( checkPossible ( a , b , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

def checkIfPossibleRec ( x , a , b , isPossible , n ) : NEW_LINE INDENT if x > n : NEW_LINE INDENT return NEW_LINE DEDENT if isPossible [ x ] : NEW_LINE INDENT return NEW_LINE DEDENT isPossible [ x ] = True NEW_LINE checkIfPossibleRec ( x + a , a , b , isPossible , n ) NEW_LINE checkIfPossibleRec ( x + b , a , b , isPossible , n ) NEW_LINE DEDENT def checkPossible ( n , a , b ) : NEW_LINE INDENT isPossible = [ False ] * ( n + 1 ) NEW_LINE checkIfPossibleRec ( 0 , a , b , isPossible , n ) NEW_LINE return isPossible [ n ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a , b , n = 3 , 7 , 8 NEW_LINE if checkPossible ( a , b , n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . util . Random ; class GFG { static int lehmann ( int n , int t ) { Random rand = new Random ( ) ; int a = rand . nextInt ( n - 3 ) + 2 ; float e = ( n - 1 ) / 2 ; while ( t > 0 ) { int result = ( ( int ) ( Math . pow ( a , e ) ) ) % n ; if ( ( result % n ) == 1 || ( result % n ) == ( n - 1 ) ) { a = rand . nextInt ( n - 3 ) + 2 ; t -= 1 ; } else return - 1 ; } return 1 ; } public static void main ( String [ ] args ) { int n = 13 ; int t = 10 ; if ( n == 2 ) System . out . println ( " ▁ 2 ▁ is ▁ Prime . " ) ; if ( n % 2 == 0 ) System . out . println ( n + " ▁ is ▁ Composite " ) ; else { long flag = lehmann ( n , t ) ; if ( flag == 1 ) System . out . println ( n + " ▁ may ▁ be ▁ Prime . " ) ; else System . out . println ( n + " ▁ is ▁ Composite . " ) ; } } }

import random NEW_LINE def lehmann ( n , t ) : NEW_LINE INDENT a = random . randint ( 2 , n - 1 ) NEW_LINE e = ( n - 1 ) / 2 NEW_LINE while ( t > 0 ) : NEW_LINE INDENT result = ( ( int ) ( a ** e ) ) % n NEW_LINE if ( ( result % n ) == 1 or ( result % n ) == ( n - 1 ) ) : NEW_LINE INDENT a = random . randint ( 2 , n - 1 ) NEW_LINE t -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT return 1 NEW_LINE DEDENT n = 13 NEW_LINE t = 10 NEW_LINE if ( n is 2 ) : NEW_LINE INDENT print ( "2 ▁ is ▁ Prime . " ) NEW_LINE DEDENT if ( n % 2 == 0 ) : NEW_LINE INDENT print ( n , " is ▁ Composite " ) NEW_LINE DEDENT else : NEW_LINE INDENT flag = lehmann ( n , t ) NEW_LINE if ( flag is 1 ) : NEW_LINE INDENT print ( n , " may ▁ be ▁ Prime . " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( n , " is ▁ Composite . " ) NEW_LINE DEDENT DEDENT


class GFG { static int ans ; static class Node { int val ; Node left , right ; } ; static int length ( Node node ) { if ( node == null ) return 0 ; int left = length ( node . left ) ; int right = length ( node . right ) ; int Leftmax = 0 , Rightmax = 0 ; if ( node . left != null && node . left . val == node . val ) Leftmax += left + 1 ; if ( node . right != null && node . right . val == node . val ) Rightmax += right + 1 ; ans = Math . max ( ans , Leftmax + Rightmax ) ; return Math . max ( Leftmax , Rightmax ) ; } static int longestSameValuePath ( Node root ) { ans = 0 ; length ( root ) ; return ans ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . val = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root = null ; root = newNode ( 4 ) ; root . left = newNode ( 4 ) ; root . right = newNode ( 4 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 9 ) ; root . right . right = newNode ( 5 ) ; System . out . print ( longestSameValuePath ( root ) ) ; } }

class newNode : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . val = data NEW_LINE self . left = self . right = None NEW_LINE DEDENT DEDENT def length ( node , ans ) : NEW_LINE INDENT if ( not node ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT left = length ( node . left , ans ) NEW_LINE right = length ( node . right , ans ) NEW_LINE Leftmax = 0 NEW_LINE Rightmax = 0 NEW_LINE if ( node . left and node . left . val == node . val ) : NEW_LINE INDENT Leftmax += left + 1 NEW_LINE DEDENT if ( node . right and node . right . val == node . val ) : NEW_LINE INDENT Rightmax += right + 1 NEW_LINE DEDENT ans [ 0 ] = max ( ans [ 0 ] , Leftmax + Rightmax ) NEW_LINE return max ( Leftmax , Rightmax ) NEW_LINE DEDENT def longestSameValuePath ( root ) : NEW_LINE INDENT ans = [ 0 ] NEW_LINE length ( root , ans ) NEW_LINE return ans [ 0 ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT root = None NEW_LINE root = newNode ( 4 ) NEW_LINE root . left = newNode ( 4 ) NEW_LINE root . right = newNode ( 4 ) NEW_LINE root . left . left = newNode ( 4 ) NEW_LINE root . left . right = newNode ( 9 ) NEW_LINE root . right . right = newNode ( 5 ) NEW_LINE print ( longestSameValuePath ( root ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int binomialCoeffSum ( int n ) { return ( 1 << n ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( binomialCoeffSum ( n ) ) ; } }

import math NEW_LINE def binomialCoeffSum ( n ) : NEW_LINE INDENT return ( 1 << n ) ; NEW_LINE DEDENT n = 4 NEW_LINE print ( binomialCoeffSum ( n ) ) NEW_LINE


import java . util . * ; class GFG { static int Distinct_Prime_factors ( Vector < Integer > a ) { HashSet < Integer > m = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < a . size ( ) ; i ++ ) { int sq = ( int ) Math . sqrt ( a . get ( i ) ) ; for ( int j = 2 ; j <= sq ; j ++ ) { if ( a . get ( i ) % j == 0 ) { m . add ( j ) ; while ( a . get ( i ) % j == 0 ) { a . set ( i , a . get ( i ) / j ) ; } } } if ( a . get ( i ) > 1 ) { m . add ( a . get ( i ) ) ; } } return m . size ( ) ; } public static void main ( String args [ ] ) { Vector < Integer > a = new Vector < Integer > ( ) ; a . add ( 1 ) ; a . add ( 2 ) ; a . add ( 3 ) ; a . add ( 4 ) ; a . add ( 5 ) ; System . out . println ( Distinct_Prime_factors ( a ) ) ; } }

import math NEW_LINE def Distinct_Prime_factors ( a ) : NEW_LINE INDENT m = [ ] NEW_LINE for i in range ( len ( a ) ) : NEW_LINE INDENT sq = int ( math . sqrt ( a [ i ] ) ) NEW_LINE for j in range ( 2 , sq + 1 ) : NEW_LINE INDENT if ( a [ i ] % j == 0 ) : NEW_LINE INDENT m . append ( j ) NEW_LINE while ( a [ i ] % j == 0 ) : NEW_LINE INDENT a [ i ] //= j NEW_LINE DEDENT DEDENT DEDENT if ( a [ i ] > 2 ) : NEW_LINE INDENT m . append ( a [ i ] ) NEW_LINE DEDENT DEDENT return len ( m ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE print ( Distinct_Prime_factors ( a ) ) NEW_LINE DEDENT


import java . util . Arrays ; public class GFG { static void shufleArray ( int a [ ] , int f , int l ) { if ( l > f ) return ; if ( l - f == 1 ) return ; int mid = ( f + l ) / 2 ; int temp = mid + 1 ; int mmid = ( f + mid ) / 2 ; for ( int i = mmid + 1 ; i <= mid ; i ++ ) { int temp1 = a [ i ] ; a [ i ] = a [ temp ] ; a [ temp ++ ] = temp1 ; } shufleArray ( a , f , mid ) ; shufleArray ( a , mid + 1 , l ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 } ; shufleArray ( a , 0 , a . length - 1 ) ; System . out . println ( Arrays . toString ( a ) ) ; } }

def shufleArray ( a , f , l ) : NEW_LINE INDENT if ( l > f ) : NEW_LINE INDENT return NEW_LINE DEDENT if ( l - f == 1 ) : NEW_LINE INDENT return NEW_LINE DEDENT mid = int ( ( f + l ) / 2 ) NEW_LINE temp = mid + 1 NEW_LINE mmid = int ( ( f + mid ) / 2 ) NEW_LINE for i in range ( mmid + 1 , mid + 1 ) : NEW_LINE INDENT ( a [ i ] , a [ temp ] ) = ( a [ temp ] , a [ i ] ) NEW_LINE temp += 1 NEW_LINE DEDENT shufleArray ( a , f , mid ) NEW_LINE shufleArray ( a , mid + 1 , l ) NEW_LINE DEDENT a = [ 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 ] NEW_LINE n = len ( a ) NEW_LINE shufleArray ( a , 0 , n - 1 ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static String solveEquation ( String equation ) { int n = equation . length ( ) , sign = 1 , coeff = 0 ; int total = 0 , i = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( equation . charAt ( j ) == ' + ' || equation . charAt ( j ) == ' - ' ) { if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; i = j ; } else if ( equation . charAt ( j ) == ' x ' ) { if ( ( i == j ) || equation . charAt ( j - 1 ) == ' + ' ) coeff += sign ; else if ( equation . charAt ( j - 1 ) == ' - ' ) coeff -= sign ; else coeff += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; i = j + 1 ; } else if ( equation . charAt ( j ) == ' = ' ) { if ( j > i ) total += sign * Integer . parseInt ( equation . substring ( i , j ) ) ; sign = - 1 ; i = j + 1 ; } } if ( i < n ) total = total + sign * Integer . parseInt ( equation . substring ( i ) ) ; if ( coeff == 0 && total == 0 ) return " Infinite ▁ solutions " ; if ( coeff == 0 && total != 0 ) return " No ▁ solution " ; int ans = - total / coeff ; return ( Integer . toString ( ans ) ) ; } public static void main ( String args [ ] ) { String equation = new String ( " x + 5-3 + x = 6 + x - 2" ) ; System . out . print ( " x ▁ = ▁ " + solveEquation ( equation ) ) ; } }

def solveEquation ( equation ) : NEW_LINE INDENT n = len ( equation ) NEW_LINE sign = 1 NEW_LINE coeff = 0 NEW_LINE total = 0 NEW_LINE i = 0 NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT if ( equation [ j ] == ' + ' or equation [ j ] == ' - ' ) : NEW_LINE INDENT if ( j > i ) : NEW_LINE INDENT total = ( total + sign * int ( equation [ i : j ] ) ) NEW_LINE DEDENT i = j NEW_LINE DEDENT elif ( equation [ j ] == ' x ' ) : NEW_LINE INDENT if ( ( i == j ) or equation [ j - 1 ] == ' + ' ) : NEW_LINE INDENT coeff += sign NEW_LINE DEDENT elif ( equation [ j - 1 ] == ' - ' ) : NEW_LINE INDENT coeff = coeff - sign NEW_LINE DEDENT else : NEW_LINE INDENT coeff = ( coeff + sign * int ( equation [ i : j ] ) ) NEW_LINE DEDENT i = j + 1 NEW_LINE DEDENT elif ( equation [ j ] == ' = ' ) : NEW_LINE INDENT if ( j > i ) : NEW_LINE INDENT total = ( total + sign * int ( equation [ i : j ] ) ) NEW_LINE DEDENT sign = - 1 NEW_LINE i = j + 1 NEW_LINE DEDENT DEDENT if ( i < n ) : NEW_LINE INDENT total = ( total + sign * int ( equation [ i : len ( equation ) ] ) ) NEW_LINE DEDENT if ( coeff == 0 and total == 0 ) : NEW_LINE INDENT return " Infinite ▁ solutions " NEW_LINE DEDENT if ( coeff == 0 and total ) : NEW_LINE INDENT return " No ▁ solution " NEW_LINE DEDENT ans = - total / coeff NEW_LINE return int ( ans ) NEW_LINE DEDENT equation = " x + 5-3 + x = 6 + x - 2" NEW_LINE print ( " x ▁ = ▁ { } " . format ( solveEquation ( equation ) ) ) NEW_LINE


public class GFG { static int N = 1000 ; static long dp [ ] = new long [ N + 1 ] ; static void sieve ( ) { int arr [ ] = new int [ N + 1 ] ; arr [ 0 ] = 1 ; arr [ 1 ] = 1 ; for ( int i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) if ( arr [ i ] == 0 ) for ( int j = i * i ; j <= N ; j += i ) arr [ j ] = 1 ; long runningPrimeSum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( arr [ i ] == 0 ) runningPrimeSum += i ; dp [ i ] = runningPrimeSum ; } } public static void main ( String [ ] args ) { int l = 4 , r = 13 ; sieve ( ) ; System . out . println ( dp [ r ] - dp [ l - 1 ] ) ; } }

import math NEW_LINE N = 1000 NEW_LINE dp = [ 0 ] * ( N + 1 ) NEW_LINE def seive ( ) : NEW_LINE INDENT array = [ 0 ] * ( N + 1 ) NEW_LINE array [ 0 ] = 1 NEW_LINE array [ 1 ] = 1 NEW_LINE for i in range ( 2 , math . ceil ( math . sqrt ( N ) + 1 ) ) : NEW_LINE INDENT if array [ i ] == 0 : NEW_LINE INDENT for j in range ( i * i , N + 1 , i ) : NEW_LINE INDENT array [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT runningPrimeSum = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if array [ i ] == 0 : NEW_LINE INDENT runningPrimeSum += i NEW_LINE DEDENT dp [ i ] = runningPrimeSum NEW_LINE DEDENT DEDENT l = 4 NEW_LINE r = 13 NEW_LINE seive ( ) NEW_LINE print ( dp [ r ] - dp [ l - 1 ] ) NEW_LINE


import java . io . * ; class GFG { public static void main ( String [ ] args ) { int n = 5 ; printPascal ( n ) ; } public static void printPascal ( int n ) { int [ ] [ ] arr = new int [ n ] [ n ] ; for ( int line = 0 ; line < n ; line ++ ) { for ( int i = 0 ; i <= line ; i ++ ) { if ( line == i || i == 0 ) arr [ line ] [ i ] = 1 ; else arr [ line ] [ i ] = arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ; System . out . print ( arr [ line ] [ i ] ) ; } System . out . println ( " " ) ; } } }

def printPascal ( n : int ) : NEW_LINE INDENT arr = [ [ 0 for x in range ( n ) ] for y in range ( n ) ] NEW_LINE for line in range ( 0 , n ) : NEW_LINE INDENT for i in range ( 0 , line + 1 ) : NEW_LINE INDENT if ( i is 0 or i is line ) : NEW_LINE INDENT arr [ line ] [ i ] = 1 NEW_LINE print ( arr [ line ] [ i ] , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT arr [ line ] [ i ] = ( arr [ line - 1 ] [ i - 1 ] + arr [ line - 1 ] [ i ] ) NEW_LINE print ( arr [ line ] [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( " \n " , end = " " ) NEW_LINE DEDENT DEDENT n = 5 NEW_LINE printPascal ( n ) NEW_LINE


class GFG { static void findNumbers ( String s ) { int n = s . length ( ) ; int count = 1 ; int result = 0 ; int left = 0 ; int right = 1 ; while ( right < n ) { if ( s . charAt ( left ) == s . charAt ( right ) ) { count ++ ; } else { result += count * ( count + 1 ) / 2 ; left = right ; count = 1 ; } right ++ ; } result += count * ( count + 1 ) / 2 ; System . out . println ( result ) ; } public static void main ( String [ ] args ) { String s = " bbbcbb " ; findNumbers ( s ) ; } }

def findNumbers ( s ) : NEW_LINE INDENT n = len ( s ) NEW_LINE count = 1 NEW_LINE result = 0 NEW_LINE left = 0 NEW_LINE right = 1 NEW_LINE while ( right < n ) : NEW_LINE INDENT if ( s [ left ] == s [ right ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT result += count * ( count + 1 ) // 2 NEW_LINE left = right NEW_LINE count = 1 NEW_LINE DEDENT right += 1 NEW_LINE DEDENT result += count * ( count + 1 ) // 2 NEW_LINE print ( result ) NEW_LINE DEDENT s = " bbbcbb " NEW_LINE findNumbers ( s ) NEW_LINE


class GFG { public static char flip ( char ch ) { return ( ch == '0' ) ? '1' : '0' ; } public static int getFlipWithStartingCharcter ( String str , char expected ) { int flipCount = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) != expected ) flipCount ++ ; expected = flip ( expected ) ; } return flipCount ; } public static int minFlipToMakeStringAlternate ( String str ) { return Math . min ( getFlipWithStartingCharcter ( str , '0' ) , getFlipWithStartingCharcter ( str , '1' ) ) ; } public static void main ( String args [ ] ) { String str = "0001010111" ; System . out . println ( minFlipToMakeStringAlternate ( str ) ) ; } }

def flip ( ch ) : NEW_LINE INDENT return '1' if ( ch == '0' ) else '0' NEW_LINE DEDENT def getFlipWithStartingCharcter ( str , expected ) : NEW_LINE INDENT flipCount = 0 NEW_LINE for i in range ( len ( str ) ) : NEW_LINE INDENT if ( str [ i ] != expected ) : NEW_LINE INDENT flipCount += 1 NEW_LINE DEDENT expected = flip ( expected ) NEW_LINE DEDENT return flipCount NEW_LINE DEDENT def minFlipToMakeStringAlternate ( str ) : NEW_LINE INDENT return min ( getFlipWithStartingCharcter ( str , '0' ) , getFlipWithStartingCharcter ( str , '1' ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = "0001010111" NEW_LINE print ( minFlipToMakeStringAlternate ( str ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static long countTriplets ( int A , int B , int C ) { long ans = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { for ( int j = 1 ; j <= B ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { if ( i * k > j * j ) ans ++ ; } } } return ans ; } public static void main ( String [ ] args ) { int A = 3 , B = 2 , C = 2 ; System . out . println ( countTriplets ( A , B , C ) ) ; } }

def countTriplets ( A , B , C ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , A + 1 ) : NEW_LINE INDENT for j in range ( 1 , B + 1 ) : NEW_LINE INDENT for k in range ( 1 , C + 1 ) : NEW_LINE INDENT if ( i * k > j * j ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT A = 3 NEW_LINE B = 2 NEW_LINE C = 2 NEW_LINE print ( countTriplets ( A , B , C ) ) NEW_LINE


class GFG { static int getMaxValue ( int arr [ ] , int arr_size ) { int i , first , second ; if ( arr_size < 2 ) { return 0 ; } first = second = Integer . MIN_VALUE ; for ( i = 0 ; i < arr_size ; i ++ ) { if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second && arr [ i ] != first ) { second = arr [ i ] ; } } if ( second == Integer . MIN_VALUE ) { return 0 ; } else { return second ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 1 , 8 } ; int n = arr . length ; System . out . println ( getMaxValue ( arr , n ) ) ; } }

import sys NEW_LINE def getMaxValue ( arr , arr_size ) : NEW_LINE INDENT if ( arr_size < 2 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT first = - sys . maxsize - 1 NEW_LINE second = - sys . maxsize - 1 NEW_LINE for i in range ( arr_size ) : NEW_LINE INDENT if ( arr [ i ] > first ) : NEW_LINE INDENT second = first NEW_LINE first = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] > second and arr [ i ] != first ) : NEW_LINE INDENT second = arr [ i ] NEW_LINE DEDENT DEDENT if ( second == - sys . maxsize - 1 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT else : NEW_LINE INDENT return second NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 5 , 1 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( getMaxValue ( arr , n ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int steps ( int source , int step , int dest ) { if ( Math . abs ( source ) > ( dest ) ) return Integer . MAX_VALUE ; if ( source == dest ) return step ; int pos = steps ( source + step + 1 , step + 1 , dest ) ; int neg = steps ( source - step - 1 , step + 1 , dest ) ; return Math . min ( pos , neg ) ; } public static void main ( String [ ] args ) { int dest = 11 ; System . out . println ( " No . ▁ of ▁ steps ▁ required " + " ▁ to ▁ reach ▁ " + dest + " ▁ is ▁ " + steps ( 0 , 0 , dest ) ) ; } }

import sys NEW_LINE def steps ( source , step , dest ) : NEW_LINE INDENT if ( abs ( source ) > ( dest ) ) : NEW_LINE INDENT return sys . maxsize NEW_LINE DEDENT if ( source == dest ) : NEW_LINE INDENT return step NEW_LINE DEDENT pos = steps ( source + step + 1 , step + 1 , dest ) NEW_LINE neg = steps ( source - step - 1 , step + 1 , dest ) NEW_LINE return min ( pos , neg ) NEW_LINE DEDENT dest = 11 ; NEW_LINE print ( " No . ▁ of ▁ steps ▁ required " , " ▁ to ▁ reach ▁ " , dest , " ▁ is ▁ " , steps ( 0 , 0 , dest ) ) ; NEW_LINE


import java . util . * ; class GFG { static int missingNumber ( int a [ ] , int n ) { Map < Integer , Integer > mp = new LinkedHashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > 0 ) { mp . put ( a [ i ] , mp . get ( a [ i ] ) == null ? 1 : mp . get ( a [ i ] ) + 1 ) ; } } int index = 1 ; while ( true ) { if ( ! mp . containsKey ( index ) ) { return index ; } index ++ ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 1 , 1 , 0 , - 1 , - 2 } ; int size = a . length ; System . out . println ( " Smallest ▁ positive ▁ missing ▁ number ▁ is ▁ : ▁ " + missingNumber ( a , size ) ) ; } }

def missingNumber ( a , n ) : NEW_LINE INDENT mp = dict ( ) ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] > 0 ) : NEW_LINE INDENT if a [ i ] not in mp . keys ( ) : NEW_LINE INDENT mp [ a [ i ] ] = 0 NEW_LINE DEDENT mp [ a [ i ] ] += 1 NEW_LINE DEDENT DEDENT index = 1 ; NEW_LINE while ( 1 ) : NEW_LINE INDENT if ( index not in mp . keys ( ) ) : NEW_LINE INDENT return index ; NEW_LINE DEDENT index += 1 ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 1 , 1 , 1 , 0 , - 1 , - 2 ] ; NEW_LINE size = len ( a ) ; NEW_LINE print ( " Smallest ▁ positive ▁ missing ▁ number ▁ is ▁ : ▁ " , missingNumber ( a , size ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static void printPath ( Vector < Integer > res , int nThNode , int kThNode ) { if ( kThNode > nThNode ) return ; res . add ( kThNode ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; System . out . print ( " \n " ) ; printPath ( res , nThNode , kThNode * 2 ) ; printPath ( res , nThNode , kThNode * 2 + 1 ) ; res . remove ( res . size ( ) - 1 ) ; } static void printPathToCoverAllNodeUtil ( int nThNode ) { Vector < Integer > res = new Vector < Integer > ( ) ; printPath ( res , nThNode , 1 ) ; } public static void main ( String args [ ] ) { int nThNode = 7 ; printPathToCoverAllNodeUtil ( nThNode ) ; } }

def printPath ( res , nThNode , kThNode ) : NEW_LINE INDENT if kThNode > nThNode : NEW_LINE INDENT return NEW_LINE DEDENT res . append ( kThNode ) NEW_LINE for i in range ( 0 , len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE printPath ( res [ : ] , nThNode , kThNode * 2 ) NEW_LINE printPath ( res [ : ] , nThNode , kThNode * 2 + 1 ) NEW_LINE DEDENT def printPathToCoverAllNodeUtil ( nThNode ) : NEW_LINE INDENT res = [ ] NEW_LINE printPath ( res , nThNode , 1 ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT nThNode = 7 NEW_LINE printPathToCoverAllNodeUtil ( nThNode ) NEW_LINE DEDENT


public class GFG { public static void SubString ( String str , int n ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j <= n ; j ++ ) System . out . println ( str . substring ( i , j ) ) ; } public static void main ( String [ ] args ) { String str = " abcd " ; SubString ( str , str . length ( ) ) ; } }

def subString ( s , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT for len in range ( i + 1 , n + 1 ) : NEW_LINE INDENT print ( s [ i : len ] ) ; NEW_LINE DEDENT DEDENT DEDENT s = " abcd " ; NEW_LINE subString ( s , len ( s ) ) ; NEW_LINE


class GFG { public static int Valid ( int a , int b , int c ) { if ( a + b + c == 180 && a != 0 && b != 0 && c != 0 ) return 1 ; else return 0 ; } public static void main ( String args [ ] ) { int a = 60 , b = 40 , c = 80 ; if ( ( Valid ( a , b , c ) ) == 1 ) System . out . print ( " Valid " ) ; else System . out . print ( " Invalid " ) ; } }

def Valid ( a , b , c ) : NEW_LINE INDENT if ( ( a + b + c == 180 ) and a != 0 and b != 0 and c != 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 60 NEW_LINE b = 40 NEW_LINE c = 80 NEW_LINE if ( Valid ( a , b , c ) ) : NEW_LINE INDENT print ( " Valid " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Invalid " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class Directed { int V = 4 ; void multiply ( int A [ ] [ ] , int B [ ] [ ] , int C [ ] [ ] ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { C [ i ] [ j ] = 0 ; for ( int k = 0 ; k < V ; k ++ ) { C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] ; } } } } int getTrace ( int graph [ ] [ ] ) { int trace = 0 ; for ( int i = 0 ; i < V ; i ++ ) { trace += graph [ i ] [ i ] ; } return trace ; } int triangleInGraph ( int graph [ ] [ ] ) { int [ ] [ ] aux2 = new int [ V ] [ V ] ; int [ ] [ ] aux3 = new int [ V ] [ V ] ; for ( int i = 0 ; i < V ; ++ i ) { for ( int j = 0 ; j < V ; ++ j ) { aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0 ; } } multiply ( graph , graph , aux2 ) ; multiply ( graph , aux2 , aux3 ) ; int trace = getTrace ( aux3 ) ; return trace / 6 ; } public static void main ( String args [ ] ) { Directed obj = new Directed ( ) ; int graph [ ] [ ] = { { 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 1 , 0 } } ; System . out . println ( " Total ▁ number ▁ of ▁ Triangle ▁ in ▁ Graph ▁ : ▁ " + obj . triangleInGraph ( graph ) ) ; } }

def multiply ( A , B , C ) : NEW_LINE INDENT global V NEW_LINE for i in range ( V ) : NEW_LINE INDENT for j in range ( V ) : NEW_LINE INDENT C [ i ] [ j ] = 0 NEW_LINE for k in range ( V ) : NEW_LINE INDENT C [ i ] [ j ] += A [ i ] [ k ] * B [ k ] [ j ] NEW_LINE DEDENT DEDENT DEDENT DEDENT def getTrace ( graph ) : NEW_LINE INDENT global V NEW_LINE trace = 0 NEW_LINE for i in range ( V ) : NEW_LINE INDENT trace += graph [ i ] [ i ] NEW_LINE DEDENT return trace NEW_LINE DEDENT def triangleInGraph ( graph ) : NEW_LINE INDENT global V NEW_LINE aux2 = [ [ None ] * V for i in range ( V ) ] NEW_LINE aux3 = [ [ None ] * V for i in range ( V ) ] NEW_LINE for i in range ( V ) : NEW_LINE INDENT for j in range ( V ) : NEW_LINE INDENT aux2 [ i ] [ j ] = aux3 [ i ] [ j ] = 0 NEW_LINE DEDENT DEDENT multiply ( graph , graph , aux2 ) NEW_LINE multiply ( graph , aux2 , aux3 ) NEW_LINE trace = getTrace ( aux3 ) NEW_LINE return trace // 6 NEW_LINE DEDENT V = 4 NEW_LINE graph = [ [ 0 , 1 , 1 , 0 ] , [ 1 , 0 , 1 , 1 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] ] NEW_LINE print ( " Total ▁ number ▁ of ▁ Triangle ▁ in ▁ Graph ▁ : " , triangleInGraph ( graph ) ) NEW_LINE


import java . io . * ; class GFG { static int minMoves ( int arr [ ] , int n ) { int expectedItem = n ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == expectedItem ) expectedItem -- ; } return expectedItem ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 3 , 2 , 1 } ; int n = arr . length ; System . out . println ( minMoves ( arr , n ) ) ; } }

def minMoves ( arr , n ) : NEW_LINE INDENT expectedItem = n NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] == expectedItem ) : NEW_LINE INDENT expectedItem -= 1 NEW_LINE DEDENT DEDENT return expectedItem NEW_LINE DEDENT arr = [ 4 , 3 , 2 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( minMoves ( arr , n ) ) NEW_LINE


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

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


import java . io . * ; class GFG { static int countSolutions ( int n ) { int x = 0 , yCount , res = 0 ; for ( yCount = 0 ; yCount * yCount < n ; yCount ++ ) ; while ( yCount != 0 ) { res += yCount ; x ++ ; while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount -- ; } return res ; } public static void main ( String args [ ] ) { System . out . println ( " Total ▁ Number ▁ of ▁ distinct ▁ Non - Negative ▁ pairs ▁ is ▁ " + countSolutions ( 6 ) ) ; } }

def countSolutions ( n ) : NEW_LINE INDENT x = 0 NEW_LINE res = 0 NEW_LINE yCount = 0 NEW_LINE while ( yCount * yCount < n ) : NEW_LINE INDENT yCount = yCount + 1 NEW_LINE DEDENT while ( yCount != 0 ) : NEW_LINE INDENT res = res + yCount NEW_LINE x = x + 1 NEW_LINE while ( yCount != 0 and ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) : NEW_LINE INDENT yCount = yCount - 1 NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT print ( " Total ▁ Number ▁ of ▁ distinct ▁ " , , countSolutions ( 6 ) )


import java . util . * ; class GFG { public static int repUnitValue ( int n ) { if ( n % 2 == 0 || n % 5 == 0 ) return 0 ; int rem = 1 ; int power = 1 ; int k = 1 ; while ( rem % n != 0 ) { k ++ ; power = power * 10 % n ; rem = ( rem + power ) % n ; } return k ; } public static void main ( String [ ] args ) { int n = 13 ; System . out . println ( repUnitValue ( n ) ) ; } }

def repUnitValue ( n ) : NEW_LINE INDENT if ( n % 2 == 0 or n % 5 == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT rem = 1 NEW_LINE power = 1 NEW_LINE k = 1 NEW_LINE while ( rem % n != 0 ) : NEW_LINE INDENT k += 1 NEW_LINE power = power * 10 % n NEW_LINE rem = ( rem + power ) % n NEW_LINE DEDENT return k NEW_LINE DEDENT n = 13 NEW_LINE print ( repUnitValue ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int angle ( int n ) { return 2 * n ; } public static void main ( String [ ] args ) { int n = 30 ; System . out . println ( angle ( n ) ) ; } }

def angle ( n ) : NEW_LINE INDENT return 2 * n NEW_LINE DEDENT n = 30 NEW_LINE print ( angle ( n ) ) NEW_LINE


class GFG { public static boolean isEven ( int n ) { return ( n % 2 == 0 ) ; } public static void main ( String [ ] args ) { int n = 101 ; if ( isEven ( n ) == true ) System . out . print ( " Even " ) ; else System . out . print ( " Odd " ) ; } }

def isEven ( n ) : NEW_LINE INDENT return ( n % 2 == 0 ) NEW_LINE DEDENT n = 101 NEW_LINE print ( " Even " if isEven ( n ) else " Odd " ) NEW_LINE


class Main { static void sortArray ( int arr [ ] , int n , int A , int B , int C ) { for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ; int index = - 1 ; int maximum = - 999999 ; for ( int i = 0 ; i < n ; i ++ ) { if ( maximum < arr [ i ] ) { index = i ; maximum = arr [ i ] ; } } int i = 0 , j = n - 1 ; int [ ] new_arr = new int [ n ] ; int k = 0 ; while ( i < index && j > index ) { if ( arr [ i ] < arr [ j ] ) new_arr [ k ++ ] = arr [ i ++ ] ; else new_arr [ k ++ ] = arr [ j -- ] ; } while ( i < index ) new_arr [ k ++ ] = arr [ i ++ ] ; while ( j > index ) new_arr [ k ++ ] = arr [ j -- ] ; new_arr [ n - 1 ] = maximum ; for ( int p = 0 ; p < n ; p ++ ) arr [ p ] = new_arr [ p ] ; } public static void main ( String [ ] args ) { int arr [ ] = { - 21 , - 15 , 12 , 13 , 14 } ; int n = arr . length ; int A = - 6 , B = - 7 , C = 2 ; sortArray ( arr , n , A , B , C ) ; System . out . println ( " Array ▁ after ▁ sorting ▁ is ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

import sys NEW_LINE def sortArray ( arr , n , A , B , C ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT arr [ i ] = ( A * arr [ i ] * arr [ i ] + B * arr [ i ] + C ) NEW_LINE DEDENT index = - ( sys . maxsize - 1 ) NEW_LINE maximum = - ( sys . maxsize - 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if maximum < arr [ i ] : NEW_LINE INDENT index = i NEW_LINE maximum = arr [ i ] NEW_LINE DEDENT DEDENT i = 0 ; j = n - 1 ; NEW_LINE new_arr = [ 0 ] * n NEW_LINE k = 0 NEW_LINE while i < index and j > index : NEW_LINE INDENT if arr [ i ] < arr [ j ] : NEW_LINE INDENT new_arr [ k ] = arr [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT else : NEW_LINE INDENT new_arr [ k ] = arr [ j ] NEW_LINE k += 1 NEW_LINE j -= 1 NEW_LINE DEDENT DEDENT while i < index : NEW_LINE INDENT new_arr [ k ] = arr [ i ] NEW_LINE k += 1 NEW_LINE i += 1 NEW_LINE DEDENT while j > index : NEW_LINE INDENT new_arr [ k ] = arr [ j ] NEW_LINE k += 1 NEW_LINE j -= 1 NEW_LINE new_arr [ n - 1 ] = maximum NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT arr [ i ] = new_arr [ i ] NEW_LINE DEDENT DEDENT arr = [ - 21 , - 15 , 12 , 13 , 14 ] NEW_LINE n = len ( arr ) NEW_LINE A = - 6 NEW_LINE B = - 7 NEW_LINE C = 2 NEW_LINE sortArray ( arr , n , A , B , C ) NEW_LINE print ( " Array ▁ after ▁ sorting ▁ is : " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT


class RotateArray { void leftRotate ( int arr [ ] , int d , int n ) { for ( int i = 0 ; i < d ; i ++ ) leftRotatebyOne ( arr , n ) ; } void leftRotatebyOne ( int arr [ ] , int n ) { int i , temp ; temp = arr [ 0 ] ; for ( i = 0 ; i < n - 1 ; i ++ ) arr [ i ] = arr [ i + 1 ] ; arr [ i ] = temp ; } void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { RotateArray rotate = new RotateArray ( ) ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; rotate . leftRotate ( arr , 2 , 7 ) ; rotate . printArray ( arr , 7 ) ; } }

def leftRotate ( arr , d , n ) : NEW_LINE INDENT for i in range ( d ) : NEW_LINE INDENT leftRotatebyOne ( arr , n ) NEW_LINE DEDENT DEDENT def leftRotatebyOne ( arr , n ) : NEW_LINE INDENT temp = arr [ 0 ] NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT arr [ i ] = arr [ i + 1 ] NEW_LINE DEDENT arr [ n - 1 ] = temp NEW_LINE DEDENT def printArray ( arr , size ) : NEW_LINE INDENT for i in range ( size ) : NEW_LINE INDENT print ( " % ▁ d " % arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] NEW_LINE leftRotate ( arr , 2 , 7 ) NEW_LINE printArray ( arr , 7 ) NEW_LINE


public class GFG { static boolean allOddDigits ( int n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 == 0 ) return false ; n /= 10 ; } return true ; } static int largestNumber ( int n ) { if ( n % 2 == 0 ) n -- ; for ( int i = n ; ; i -= 2 ) if ( allOddDigits ( i ) ) return i ; } public static void main ( String [ ] args ) { int N = 23 ; System . out . println ( largestNumber ( N ) ) ; } }

def allOddDigits ( n ) : NEW_LINE INDENT while ( n ) : NEW_LINE INDENT if ( ( n % 10 ) % 2 == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT n = int ( n / 10 ) NEW_LINE DEDENT return True NEW_LINE DEDENT def largestNumber ( n ) : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT n -= 1 NEW_LINE DEDENT i = n NEW_LINE while ( 1 ) : NEW_LINE INDENT if ( allOddDigits ( i ) ) : NEW_LINE INDENT return i NEW_LINE DEDENT i -= 2 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 23 NEW_LINE print ( largestNumber ( N ) ) NEW_LINE DEDENT


class GFG { static int productAtKthLevel ( String tree , int k ) { int level = - 1 ; int product = 1 ; int n = tree . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( tree . charAt ( i ) == ' ( ' ) level ++ ; else if ( tree . charAt ( i ) == ' ) ' ) level -- ; else { if ( level == k ) product *= ( tree . charAt ( i ) - '0' ) ; } } return product ; } public static void main ( String [ ] args ) { String tree = " ( 0(5(6 ( ) ( ) ) ( 4 ( ) (9 ( ) ( ) ) ) ) ( 7(1 ( ) ( ) ) ( 3 ( ) ( ) ) ) ) " ; int k = 2 ; System . out . println ( productAtKthLevel ( tree , k ) ) ; } }

def productAtKthLevel ( tree , k ) : NEW_LINE INDENT level = - 1 NEW_LINE product = 1 NEW_LINE n = len ( tree ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( tree [ i ] == ' ( ' ) : NEW_LINE INDENT level += 1 NEW_LINE DEDENT elif ( tree [ i ] == ' ) ' ) : NEW_LINE INDENT level -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( level == k ) : NEW_LINE INDENT product *= ( int ( tree [ i ] ) - int ( '0' ) ) NEW_LINE DEDENT DEDENT DEDENT return product NEW_LINE DEDENT tree = " ( 0(5(6 ( ) ( ) ) ( 4 ( ) (9 ( ) ( ) ) ) ) ( 7(1 ( ) ( ) ) ( 3 ( ) ( ) ) ) ) " NEW_LINE k = 2 NEW_LINE print ( productAtKthLevel ( tree , k ) ) NEW_LINE


class GFG { static int count_greater ( int arr [ ] , int n ) { int min = Integer . MAX_VALUE ; int counter = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] > min ) { counter ++ ; } if ( arr [ i ] <= min ) { min = arr [ i ] ; } } return counter ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( count_greater ( arr , n ) ) ; } }

import sys NEW_LINE def count_greater ( arr , n ) : NEW_LINE INDENT min = sys . maxsize ; NEW_LINE counter = 0 ; NEW_LINE for i in range ( n - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] > min ) : NEW_LINE INDENT counter += 1 ; NEW_LINE DEDENT if ( arr [ i ] <= min ) : NEW_LINE INDENT min = arr [ i ] ; NEW_LINE DEDENT DEDENT return counter ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 3 , 2 , 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( count_greater ( arr , n ) ) ; NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class GFG { public static boolean isPossibleToMakeDivisible ( int arr [ ] , int n ) { int remainder = 0 ; for ( int i = 0 ; i < n ; i ++ ) remainder = ( remainder + arr [ i ] ) % 3 ; return ( remainder == 0 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 40 , 50 , 90 } ; int n = 3 ; if ( isPossibleToMakeDivisible ( arr , n ) ) System . out . print ( " Yes \n " ) ; else System . out . print ( " No \n " ) ; } }

def isPossibleToMakeDivisible ( arr , n ) : NEW_LINE INDENT remainder = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT remainder = ( remainder + arr [ i ] ) % 3 NEW_LINE DEDENT return ( remainder == 0 ) NEW_LINE DEDENT arr = [ 40 , 50 , 90 ] ; NEW_LINE n = 3 NEW_LINE if ( isPossibleToMakeDivisible ( arr , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


import java . lang . Math ; class GFG { static int NthArmstrong ( int n ) { int count = 0 ; for ( int i = 1 ; i <= Integer . MAX_VALUE ; i ++ ) { int num = i , rem , digit = 0 , sum = 0 ; num = i ; digit = ( int ) Math . log10 ( num ) + 1 ; while ( num > 0 ) { rem = num % 10 ; sum = sum + ( int ) Math . pow ( rem , digit ) ; num = num / 10 ; } if ( i == sum ) count ++ ; if ( count == n ) return i ; } return n ; } public static void main ( String [ ] args ) { int n = 12 ; System . out . println ( NthArmstrong ( n ) ) ; } }

import math ; NEW_LINE import sys ; NEW_LINE def NthArmstrong ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( 1 , sys . maxsize ) : NEW_LINE INDENT num = i ; NEW_LINE rem = 0 ; NEW_LINE digit = 0 ; NEW_LINE sum = 0 ; NEW_LINE num = i ; NEW_LINE digit = int ( math . log10 ( num ) + 1 ) ; NEW_LINE while ( num > 0 ) : NEW_LINE INDENT rem = num % 10 ; NEW_LINE sum = sum + pow ( rem , digit ) ; NEW_LINE num = num // 10 ; NEW_LINE DEDENT if ( i == sum ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT if ( count == n ) : NEW_LINE INDENT return i ; NEW_LINE DEDENT DEDENT DEDENT n = 12 ; NEW_LINE print ( NthArmstrong ( n ) ) ; NEW_LINE


import java . io . * ; class GFG { static int countEvenOdd ( int n ) { int even_count = 0 ; int odd_count = 0 ; while ( n > 0 ) { int rem = n % 10 ; if ( rem % 2 == 0 ) even_count ++ ; else odd_count ++ ; n = n / 10 ; } System . out . println ( " Even ▁ count ▁ : ▁ " + even_count ) ; System . out . println ( " Odd ▁ count ▁ : ▁ " + odd_count ) ; if ( even_count % 2 == 0 && odd_count % 2 != 0 ) return 1 ; else return 0 ; } public static void main ( String [ ] args ) { int n ; n = 2335453 ; int t = countEvenOdd ( n ) ; if ( t == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

def countEvenOdd ( n ) : NEW_LINE INDENT even_count = 0 NEW_LINE odd_count = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT rem = n % 10 NEW_LINE if ( rem % 2 == 0 ) : NEW_LINE INDENT even_count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT odd_count += 1 NEW_LINE DEDENT n = int ( n / 10 ) NEW_LINE DEDENT print ( " Even ▁ count ▁ : ▁ " , even_count ) NEW_LINE print ( " \n Odd ▁ count ▁ : ▁ " , odd_count ) NEW_LINE if ( even_count % 2 == 0 and odd_count % 2 != 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT n = 2335453 ; NEW_LINE t = countEvenOdd ( n ) ; NEW_LINE if ( t == 1 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT


public class GFG { static char maxRepeating ( String str ) { int len = str . length ( ) ; int count = 0 ; char res = str . charAt ( 0 ) ; for ( int i = 0 ; i < len ; i ++ ) { int cur_count = 1 ; for ( int j = i + 1 ; j < len ; j ++ ) { if ( str . charAt ( i ) != str . charAt ( j ) ) break ; cur_count ++ ; } if ( cur_count > count ) { count = cur_count ; res = str . charAt ( i ) ; } } return res ; } public static void main ( String args [ ] ) { String str = " aaaabbaaccde " ; System . out . println ( maxRepeating ( str ) ) ; } }

def maxRepeating ( str ) : NEW_LINE INDENT l = len ( str ) NEW_LINE count = 0 NEW_LINE res = str [ 0 ] NEW_LINE for i in range ( l ) : NEW_LINE INDENT cur_count = 1 NEW_LINE for j in range ( i + 1 , l ) : NEW_LINE INDENT if ( str [ i ] != str [ j ] ) : NEW_LINE INDENT break NEW_LINE DEDENT cur_count += 1 NEW_LINE DEDENT if cur_count > count : NEW_LINE INDENT count = cur_count NEW_LINE res = str [ i ] NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " aaaabbaaccde " NEW_LINE print ( maxRepeating ( str ) ) NEW_LINE DEDENT


class Solution { static boolean checkPerfectcube ( int n ) { int d = ( int ) Math . cbrt ( n ) ; if ( d * d * d == n ) return true ; return false ; } static int largestPerfectcubeNumber ( 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 ( largestPerfectcubeNumber ( 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 largestPerfectcubeNumber ( a , n ) : NEW_LINE INDENT maxi = - 1 NEW_LINE for i in range ( 0 , n , 1 ) : NEW_LINE INDENT if ( checkPerfectcube ( a [ i ] ) ) : 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 ( largestPerfectcubeNumber ( a , n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean [ ] isPrime = new boolean [ ( int ) ( 1e5 ) + 5 ] ; static int reverse ( int n ) { int temp = n ; int sum = 0 ; while ( temp > 0 ) { int rem = temp % 10 ; sum = sum * 10 + rem ; temp /= 10 ; } return sum ; } static int mirror ( int n ) { int temp = n ; int sum = 0 ; while ( temp > 0 ) { int rem = temp % 10 ; if ( rem == 2 ) { rem = 5 ; } else if ( rem == 5 ) { rem = 2 ; } sum = sum * 10 + rem ; temp /= 10 ; } return sum ; } static void sieve ( ) { Arrays . fill ( isPrime , true ) ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i <= ( int ) 1e5 ; i ++ ) { for ( int j = 2 ; i * j <= ( int ) 1e5 ; j ++ ) { isPrime [ i * j ] = false ; } } } static boolean isDihedralPrime ( int n ) { if ( ! isPrime [ n ] || ! isPrime [ mirror ( n ) ] || ! isPrime [ reverse ( n ) ] || ! isPrime [ reverse ( mirror ( n ) ) ] ) { return false ; } int temp = n ; while ( temp > 0 ) { int rem = temp % 10 ; if ( rem == 3 || rem == 4 || rem == 6 || rem == 7 || rem == 9 ) { return false ; } temp /= 10 ; } return true ; } public static void main ( String [ ] args ) { sieve ( ) ; int n = 18181 ; if ( isDihedralPrime ( n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

isPrime = ( int ( 1e5 ) + 5 ) * [ True ] NEW_LINE def reverse ( n ) : NEW_LINE INDENT temp = n NEW_LINE sum = 0 NEW_LINE while temp > 0 : NEW_LINE INDENT rem = temp % 10 NEW_LINE sum = sum * 10 + rem NEW_LINE temp //= 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def mirror ( n ) : NEW_LINE INDENT temp = n NEW_LINE sum = 0 NEW_LINE while temp > 0 : NEW_LINE INDENT rem = temp % 10 NEW_LINE if rem == 2 : NEW_LINE INDENT rem = 5 NEW_LINE DEDENT elif rem == 5 : NEW_LINE INDENT rem = 2 NEW_LINE DEDENT sum = sum * 10 + rem NEW_LINE temp //= 10 NEW_LINE DEDENT return sum NEW_LINE DEDENT def sieve ( ) : NEW_LINE INDENT isPrime [ 0 ] = isPrime [ 1 ] = False NEW_LINE for i in range ( 2 , int ( 1e5 ) + 1 ) : NEW_LINE INDENT j = 2 NEW_LINE while i * j <= int ( 1e5 ) : NEW_LINE INDENT isPrime [ i * j ] = False NEW_LINE j += 1 NEW_LINE DEDENT DEDENT DEDENT def isDihedralPrime ( n ) : NEW_LINE INDENT if ( not isPrime [ n ] ) or ( not isPrime [ mirror ( n ) ] )   \ NEW_LINE INDENT or ( not isPrime [ reverse ( n ) ] )   \ NEW_LINE or ( not isPrime [ reverse ( mirror ( n ) ) ] ) : NEW_LINE return False NEW_LINE DEDENT temp = n NEW_LINE while temp > 0 : NEW_LINE INDENT rem = temp % 10 ; NEW_LINE if rem == 3 or rem == 4 or   \ NEW_LINE INDENT rem == 6 or rem == 7 or rem == 9 : NEW_LINE return False NEW_LINE DEDENT temp //= 10 NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT sieve ( ) NEW_LINE n = 18181 NEW_LINE if isDihedralPrime ( n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . io . * ; class GFG { static int sumOfDiv ( int x ) { int sum = 1 ; for ( int i = 2 ; i <= Math . sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { sum += i ; if ( x / i != i ) sum += x / i ; } } return sum ; } static boolean isAmicable ( int a , int b ) { return ( sumOfDiv ( a ) == b && sumOfDiv ( b ) == a ) ; } static int countPairs ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( isAmicable ( arr [ i ] , arr [ j ] ) ) count ++ ; return count ; } public static void main ( String args [ ] ) { int arr1 [ ] = { 220 , 284 , 1184 , 1210 , 2 , 5 } ; int n1 = arr1 . length ; System . out . println ( countPairs ( arr1 , n1 ) ) ; int arr2 [ ] = { 2620 , 2924 , 5020 , 5564 , 6232 , 6368 } ; int n2 = arr2 . length ; System . out . println ( countPairs ( arr2 , n2 ) ) ; } }

def sumOfDiv ( x ) : NEW_LINE INDENT sum = 1 NEW_LINE for i in range ( 2 , x ) : NEW_LINE INDENT if x % i == 0 : NEW_LINE INDENT sum += i NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT def isAmicable ( a , b ) : NEW_LINE INDENT if sumOfDiv ( a ) == b and sumOfDiv ( b ) == a : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT def countPairs ( arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if isAmicable ( arr [ i ] , arr [ j ] ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT arr1 = [ 220 , 284 , 1184 , 1210 , 2 , 5 ] NEW_LINE n1 = len ( arr1 ) NEW_LINE print ( countPairs ( arr1 , n1 ) ) NEW_LINE arr2 = [ 2620 , 2924 , 5020 , 5564 , 6232 , 6368 ] NEW_LINE n2 = len ( arr2 ) NEW_LINE print ( countPairs ( arr2 , n2 ) ) NEW_LINE


import java . util . * ; class GFG { static boolean isPossible ( float x , float y , float z ) { float a = x * x + y * y + z * z ; if ( Math . ceil ( a ) == 1 && Math . floor ( a ) == 1 ) return true ; return false ; } public static void main ( String args [ ] ) { float l = 0.70710678f , m = 0.5f , n = 0.5f ; if ( isPossible ( l , m , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

from math import ceil , floor NEW_LINE def isPossible ( x , y , z ) : NEW_LINE INDENT a = x * x + y * y + z * z NEW_LINE a = round ( a , 8 ) NEW_LINE if ( ceil ( a ) == 1 & floor ( a ) == 1 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l = 0.70710678 NEW_LINE m = 0.5 NEW_LINE n = 0.5 NEW_LINE if ( isPossible ( l , m , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


class GFG { static void printBinStr ( int [ ] str , int len ) { for ( int i = 0 ; i < len ; i ++ ) { System . out . print ( str [ i ] ) ; } System . out . println ( ) ; } static void generateBinStr ( int [ ] str , int len , int currlen , int occur , int nextbit ) { if ( currlen == len ) { if ( occur == 2 && nextbit == 0 ) { printBinStr ( str , len ) ; } return ; } if ( currlen == 0 ) { str [ 0 ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else if ( occur < 2 ) { str [ currlen ] = nextbit ; if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { occur += 1 ; } generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } else if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { return ; } else { str [ currlen ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } } public static void main ( String [ ] args ) { int n = 5 ; if ( n < 4 ) { System . out . print ( - 1 ) ; } else { int [ ] str = new int [ n ] ; generateBinStr ( str , n , 0 , 0 , 0 ) ; generateBinStr ( str , n , 0 , 0 , 1 ) ; } } }

def printBinStr ( string , length ) : NEW_LINE INDENT for i in range ( 0 , length ) : NEW_LINE INDENT print ( string [ i ] , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT def generateBinStr ( string , length , currlen , occur , nextbit ) : NEW_LINE INDENT if currlen == length : NEW_LINE INDENT if occur == 2 and nextbit == 0 : NEW_LINE INDENT printBinStr ( string , length ) NEW_LINE DEDENT return NEW_LINE DEDENT if currlen == 0 : NEW_LINE INDENT string [ 0 ] = nextbit NEW_LINE generateBinStr ( string , length , currlen + 1 , occur , 0 ) NEW_LINE generateBinStr ( string , length , currlen + 1 , occur , 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT if occur < 2 : NEW_LINE INDENT string [ currlen ] = nextbit NEW_LINE if string [ currlen - 1 ] == 0 and nextbit == 1 : NEW_LINE INDENT occur += 1 NEW_LINE DEDENT generateBinStr ( string , length , currlen + 1 , occur , 0 ) NEW_LINE generateBinStr ( string , length , currlen + 1 , occur , 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT if string [ currlen - 1 ] == 0 and nextbit == 1 : NEW_LINE INDENT return NEW_LINE DEDENT else : NEW_LINE INDENT string [ currlen ] = nextbit NEW_LINE generateBinStr ( string , length , currlen + 1 , occur , 0 ) NEW_LINE generateBinStr ( string , length , currlen + 1 , occur , 1 ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE if n < 4 : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT string = [ None ] * n NEW_LINE generateBinStr ( string , n , 0 , 0 , 0 ) NEW_LINE generateBinStr ( string , n , 0 , 0 , 1 ) NEW_LINE DEDENT DEDENT


import java . util . * ; class GFG { static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static boolean isProduct ( 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 ; } static void findNumbers ( int N ) { Vector < Integer > vec = new Vector < Integer > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( isProduct ( i ) && ! isPerfectSquare ( i ) ) { vec . add ( i ) ; } } Iterator < Integer > itr = vec . iterator ( ) ; while ( itr . hasNext ( ) ) { System . out . print ( itr . next ( ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 30 ; findNumbers ( N ) ; } }

import math NEW_LINE def isPerfectSquare ( x ) : NEW_LINE INDENT sr = math . sqrt ( x ) NEW_LINE return ( ( sr - math . floor ( sr ) ) == 0 ) NEW_LINE DEDENT def isProduct ( num ) : NEW_LINE INDENT cnt = 0 NEW_LINE i = 2 NEW_LINE while cnt < 2 and i * i <= num : NEW_LINE INDENT while ( num % i == 0 ) : NEW_LINE INDENT num //= i NEW_LINE cnt += 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT if ( num > 1 ) : NEW_LINE INDENT cnt += 1 NEW_LINE DEDENT return cnt == 2 NEW_LINE DEDENT def findNumbers ( N ) : NEW_LINE INDENT vec = [ ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if ( isProduct ( i ) and not isPerfectSquare ( i ) ) : NEW_LINE INDENT vec . append ( i ) NEW_LINE DEDENT DEDENT for i in range ( len ( vec ) ) : NEW_LINE INDENT print ( vec [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 30 NEW_LINE findNumbers ( N ) NEW_LINE DEDENT


import java . util . * ; class GFG { static Vector < Integer > allPrimes = new Vector < Integer > ( ) ; static void sieve ( int n ) { boolean [ ] prime = new boolean [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) allPrimes . add ( p ) ; } static long factorialDivisors ( int n ) { sieve ( n ) ; long result = 1 ; for ( int i = 0 ; i < allPrimes . size ( ) ; i ++ ) { long p = allPrimes . get ( i ) ; long exp = 0 ; while ( p <= n ) { exp = exp + ( n / p ) ; p = p * allPrimes . get ( i ) ; } result = result * ( exp + 1 ) ; } return result ; } public static void main ( String [ ] args ) { System . out . println ( factorialDivisors ( 6 ) ) ; } }

allPrimes = [ ] ; NEW_LINE def sieve ( n ) : NEW_LINE INDENT prime = [ True ] * ( n + 1 ) ; NEW_LINE p = 2 ; NEW_LINE while ( p * p <= n ) : NEW_LINE INDENT if ( prime [ p ] == True ) : NEW_LINE INDENT i = p * 2 ; NEW_LINE while ( i <= n ) : NEW_LINE INDENT prime [ i ] = False ; NEW_LINE i += p ; NEW_LINE DEDENT DEDENT p += 1 ; NEW_LINE DEDENT for p in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( prime [ p ] ) : NEW_LINE INDENT allPrimes . append ( p ) ; NEW_LINE DEDENT DEDENT DEDENT def factorialDivisors ( n ) : NEW_LINE INDENT sieve ( n ) ; NEW_LINE result = 1 ; NEW_LINE for i in range ( len ( allPrimes ) ) : NEW_LINE INDENT p = allPrimes [ i ] ; NEW_LINE exp = 0 ; NEW_LINE while ( p <= n ) : NEW_LINE INDENT exp = exp + int ( n / p ) ; NEW_LINE p = p * allPrimes [ i ] ; NEW_LINE DEDENT result = result * ( exp + 1 ) ; NEW_LINE DEDENT return result ; NEW_LINE DEDENT print ( factorialDivisors ( 6 ) ) ; NEW_LINE


import java . util . * ; class GFG { static int countPairsWithDiffK ( int arr [ ] , int n , int k ) { int count = 0 ; Arrays . sort ( arr ) ; int l = 0 ; int r = 0 ; while ( r < n ) { if ( arr [ r ] - arr [ l ] == k ) { count ++ ; l ++ ; r ++ ; } else if ( arr [ r ] - arr [ l ] > k ) l ++ ; else r ++ ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int n = arr . length ; int k = 3 ; System . out . println ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ diff ▁ is ▁ " + countPairsWithDiffK ( arr , n , k ) ) ; } }

def countPairsWithDiffK ( arr , n , k ) : NEW_LINE INDENT count = 0 NEW_LINE arr . sort ( ) NEW_LINE l = 0 NEW_LINE r = 0 NEW_LINE while r < n : NEW_LINE INDENT if arr [ r ] - arr [ l ] == k : NEW_LINE INDENT count += 1 NEW_LINE l += 1 NEW_LINE r += 1 NEW_LINE DEDENT elif arr [ r ] - arr [ l ] > k : NEW_LINE INDENT l += 1 NEW_LINE DEDENT else : NEW_LINE INDENT r += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 5 , 3 , 4 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE k = 3 NEW_LINE print ( " Count ▁ of ▁ pairs ▁ with ▁ given ▁ diff ▁ is ▁ " , countPairsWithDiffK ( arr , n , k ) ) NEW_LINE DEDENT


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 boolean isStrongPrime ( int n ) { if ( ! isPrime ( n ) || n == 2 ) return false ; int previous_prime = n - 1 ; int next_prime = n + 1 ; while ( ! isPrime ( next_prime ) ) next_prime ++ ; while ( ! isPrime ( previous_prime ) ) previous_prime -- ; int mean = ( previous_prime + next_prime ) / 2 ; if ( n > mean ) return true ; else return false ; } public static void main ( String args [ ] ) { int n = 11 ; if ( isStrongPrime ( n ) ) 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 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 k = int ( sqrt ( n ) ) + 1 NEW_LINE for i in range ( 5 , k , 6 ) : NEW_LINE INDENT if ( n % i == 0 or n % ( i + 2 ) == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT def isStrongPrime ( n ) : NEW_LINE INDENT if ( isPrime ( n ) == False or n == 2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT previous_prime = n - 1 NEW_LINE next_prime = n + 1 NEW_LINE while ( isPrime ( next_prime ) == False ) : NEW_LINE INDENT next_prime += 1 NEW_LINE DEDENT while ( isPrime ( previous_prime ) == False ) : NEW_LINE INDENT previous_prime -= 1 NEW_LINE DEDENT mean = ( previous_prime + next_prime ) / 2 NEW_LINE if ( n > mean ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 11 NEW_LINE if ( isStrongPrime ( n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . math . * ; class GFG { public static boolean possible ( int n ) { if ( n > 3 ) { int sum = ( n * ( n + 1 ) ) / 2 ; if ( sum % 3 == 0 ) { return true ; } } return false ; } public static void main ( String [ ] args ) { int n = 5 ; if ( possible ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def possible ( n ) : NEW_LINE INDENT if ( n > 3 ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) // 2 ; NEW_LINE if ( sum % 3 == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 ; NEW_LINE if ( possible ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT


class GFG { static int count ( int n ) { int x = ( n / 3 ) - 1 ; if ( n % 3 > 0 ) { x ++ ; } return ( 4 * x + 4 * n ) ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . print ( count ( n ) + " \n " ) ; } }

def count ( n ) : NEW_LINE INDENT x = ( n // 3 ) - 1 ; NEW_LINE if ( n % 3 > 0 ) : NEW_LINE INDENT x += 1 ; NEW_LINE DEDENT return ( 4 * x + 4 * n ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 ; NEW_LINE print ( count ( n ) ) ; NEW_LINE DEDENT


public class DeleteN { public static void main ( String args [ ] ) { int in = 1234 ; String inp = Integer . toString ( in ) ; int del = 3 ; System . out . println ( " num _ after _ deleting _ from _ starting ▁ " + fromStart ( inp , del ) ) ; System . out . println ( " num _ after _ deleting _ from _ ending ▁ " + fromEnd ( inp , del ) ) ; } static String fromStart ( String inp , int del ) { try { String inp1 = inp . substring ( 0 , del - 1 ) ; String inp2 = inp . substring ( del , inp . length ( ) ) ; return inp1 + inp2 ; } catch ( Exception e ) { return " Check ▁ Input " ; } } static String fromEnd ( String inp , int del ) { try { String inp1 = inp . substring ( 0 , inp . length ( ) - del ) ; String inp2 = inp . substring ( inp . length ( ) - del + 1 , inp . length ( ) ) ; return inp1 + inp2 ; } catch ( Exception e ) { return " Check ▁ Input " ; } } }

def fromStart ( inp , del11 ) : NEW_LINE INDENT inp1 = inp [ 0 : del1 - 1 ] ; NEW_LINE inp2 = inp [ del1 : len ( inp ) ] ; NEW_LINE return inp1 + inp2 ; NEW_LINE DEDENT def fromEnd ( inp , del1 ) : NEW_LINE INDENT inp1 = inp [ 0 : len ( inp ) - del1 ] ; NEW_LINE inp2 = inp [ len ( inp ) - del1 + 1 : len ( inp ) ] ; NEW_LINE return inp1 + inp2 ; NEW_LINE DEDENT in1 = 1234 ; NEW_LINE inp = str ( in1 ) ; NEW_LINE del1 = 3 ; NEW_LINE print ( " num _ after _ deleting _ from _ starting " , fromStart ( inp , del1 ) ) ; NEW_LINE print ( " num _ after _ deleting _ from _ ending " , fromEnd ( inp , del1 ) ) ; NEW_LINE


import java . io . * ; class GFG { static int N = 4 ; static int stepsRequired ( int arr [ ] [ ] ) { int result = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( j > i + 1 ) result += Math . abs ( arr [ i ] [ j ] ) ; } } return result ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 2 , 3 , 2 } , { 3 , 1 , 0 , 3 } , { 3 , 2 , 1 , 3 } , { - 3 , 4 , 2 , 1 } } ; System . out . println ( stepsRequired ( arr ) ) ; } }

N = 4 NEW_LINE def stepsRequired ( arr ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( j > i + 1 ) : NEW_LINE INDENT result += abs ( arr [ i ] [ j ] ) NEW_LINE DEDENT DEDENT DEDENT return result NEW_LINE DEDENT arr = [ [ 1 , 2 , 3 , 2 ] , [ 3 , 1 , 0 , 3 ] , [ 3 , 2 , 1 , 3 ] , [ - 3 , 4 , 2 , 1 ] ] NEW_LINE print ( stepsRequired ( arr ) ) NEW_LINE


import java . util . * ; class GFG { static int minItems ( int k , int r ) { for ( int i = 1 ; i < 10 ; i ++ ) if ( ( i * k - r ) % 10 == 0 || ( i * k ) % 10 == 0 ) return i ; return 10 ; } public static void main ( String args [ ] ) { int k = 15 ; int r = 2 ; System . out . println ( minItems ( k , r ) ) ; } }

def minItems ( k , r ) : NEW_LINE INDENT for i in range ( 1 , 10 ) : NEW_LINE INDENT if ( ( i * k - r ) % 10 == 0 or ( i * k ) % 10 == 0 ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return 10 ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT k , r = 15 , 2 ; NEW_LINE print ( minItems ( k , r ) ) NEW_LINE DEDENT


class GFG { static double u_cal ( double u , int n ) { double temp = u ; for ( int i = 1 ; i < n ; i ++ ) temp = temp * ( u - i ) ; return temp ; } static int fact ( int n ) { int f = 1 ; for ( int i = 2 ; i <= n ; i ++ ) f *= i ; return f ; } public static void main ( String [ ] args ) { int n = 4 ; double x [ ] = { 45 , 50 , 55 , 60 } ; double y [ ] [ ] = new double [ n ] [ n ] ; y [ 0 ] [ 0 ] = 0.7071 ; y [ 1 ] [ 0 ] = 0.7660 ; y [ 2 ] [ 0 ] = 0.8192 ; y [ 3 ] [ 0 ] = 0.8660 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < n - i ; j ++ ) y [ j ] [ i ] = y [ j + 1 ] [ i - 1 ] - y [ j ] [ i - 1 ] ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( x [ i ] + " \t " ) ; for ( int j = 0 ; j < n - i ; j ++ ) System . out . print ( y [ i ] [ j ] + " \t " ) ; System . out . println ( ) ; } double value = 52 ; double sum = y [ 0 ] [ 0 ] ; double u = ( value - x [ 0 ] ) / ( x [ 1 ] - x [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { sum = sum + ( u_cal ( u , i ) * y [ 0 ] [ i ] ) / fact ( i ) ; } System . out . println ( " \n ▁ Value ▁ at ▁ " + value + " ▁ is ▁ " + String . format ( " % .6g % n " , sum ) ) ; } }

def u_cal ( u , n ) : NEW_LINE INDENT temp = u ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT temp = temp * ( u - i ) ; NEW_LINE DEDENT return temp ; NEW_LINE DEDENT def fact ( n ) : NEW_LINE INDENT f = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT f *= i ; NEW_LINE DEDENT return f ; NEW_LINE DEDENT n = 4 ; NEW_LINE x = [ 45 , 50 , 55 , 60 ] ; NEW_LINE y = [ [ 0 for i in range ( n ) ] for j in range ( n ) ] ; NEW_LINE y [ 0 ] [ 0 ] = 0.7071 ; NEW_LINE y [ 1 ] [ 0 ] = 0.7660 ; NEW_LINE y [ 2 ] [ 0 ] = 0.8192 ; NEW_LINE y [ 3 ] [ 0 ] = 0.8660 ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( n - i ) : NEW_LINE INDENT y [ j ] [ i ] = y [ j + 1 ] [ i - 1 ] - y [ j ] [ i - 1 ] ; NEW_LINE DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT print ( x [ i ] , end = " \t " ) ; NEW_LINE for j in range ( n - i ) : NEW_LINE INDENT print ( y [ i ] [ j ] , end = " \t " ) ; NEW_LINE DEDENT print ( " " ) ; NEW_LINE DEDENT value = 52 ; NEW_LINE sum = y [ 0 ] [ 0 ] ; NEW_LINE u = ( value - x [ 0 ] ) / ( x [ 1 ] - x [ 0 ] ) ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT sum = sum + ( u_cal ( u , i ) * y [ 0 ] [ i ] ) / fact ( i ) ; NEW_LINE DEDENT print ( " \n Value ▁ at " , value , " is " , round ( sum , 6 ) ) ; NEW_LINE


import java . util . * ; class Solution { static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static long powerGCD ( long a , long b , long n ) { long e = power ( a , n , b ) ; return gcd ( e , b ) ; } public static void main ( String args [ ] ) { long a = 5 , b = 4 , n = 2 ; System . out . print ( powerGCD ( a , b , n ) ) ; } }

def power ( x , y , p ) : NEW_LINE INDENT res = 1 NEW_LINE x = x % p NEW_LINE while ( y > 0 ) : NEW_LINE INDENT if ( y & 1 ) : NEW_LINE INDENT res = ( res * x ) % p NEW_LINE DEDENT y = y >> 1 NEW_LINE x = ( x * x ) % p NEW_LINE DEDENT return res NEW_LINE DEDENT def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def powerGCD ( a , b , n ) : NEW_LINE INDENT e = power ( a , n , b ) NEW_LINE return gcd ( e , b ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 5 NEW_LINE b = 4 NEW_LINE n = 2 NEW_LINE print ( powerGCD ( a , b , n ) ) NEW_LINE DEDENT


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

import math NEW_LINE def sumOfSeries ( n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT sum = sum + ( 2 * i - 1 ) * ( 2 * i - 1 ) NEW_LINE DEDENT return sum NEW_LINE DEDENT n = 10 NEW_LINE print ( sumOfSeries ( n ) ) NEW_LINE


class GFG { static void findNumbers ( int n ) { int i = 1 ; while ( i <= n ) { System . out . print ( ( ( 2 * i ) - 1 ) + " ▁ " ) ; i ++ ; } } public static void main ( String args [ ] ) { int n = 3 ; findNumbers ( n ) ; } }

def findNumber ( n ) : NEW_LINE INDENT i = 1 NEW_LINE while i <= n : NEW_LINE INDENT print ( ( 2 * i ) - 1 , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT n = 3 NEW_LINE findNumber ( n ) NEW_LINE


class GFG { static int factorial ( int n ) { if ( n == 0 ) return 1 ; return n * factorial ( n - 1 ) ; } static int countNum ( int n ) { if ( n > 10 ) return 0 ; return ( 9 * factorial ( 9 ) / factorial ( 10 - n ) ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countNum ( n ) ) ; } }

def factorial ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT return n * factorial ( n - 1 ) ; NEW_LINE DEDENT def countNum ( n ) : NEW_LINE INDENT if ( n > 10 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT return ( 9 * factorial ( 9 ) // factorial ( 10 - n ) ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 3 ; NEW_LINE print ( countNum ( n ) ) ; NEW_LINE DEDENT


class GFG { static void complement ( String number1 ) { char [ ] number = number1 . toCharArray ( ) ; for ( int i = 0 ; i < number . length ; i ++ ) if ( number [ i ] != ' . ' ) number [ i ] = ( char ) ( ( int ) ( '9' ) - ( int ) ( number [ i ] ) + ( int ) ( '0' ) ) ; System . out . println ( "9 ' s ▁ complement ▁ is ▁ : ▁ " + String . valueOf ( number ) ) ; } public static void main ( String [ ] args ) { String number = "345.45" ; complement ( number ) ; } }

def complement ( number ) : NEW_LINE INDENT for i in range ( 0 , len ( number ) ) : NEW_LINE INDENT if ( number [ i ] != ' . ' ) : NEW_LINE INDENT a = 9 - int ( number [ i ] ) NEW_LINE number = ( number [ : i ] + str ( a ) + number [ i + 1 : ] ) NEW_LINE DEDENT DEDENT print ( "9 ' s ▁ complement ▁ is ▁ : ▁ " , number ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT number = "345.45" NEW_LINE complement ( number ) NEW_LINE DEDENT


import java . util . * ; class GFG { static boolean checkForElement ( int array [ ] , int n ) { Set < Integer > s = new LinkedHashSet < > ( ) ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += array [ i ] ; s . add ( array [ i ] ) ; } if ( sum % 2 == 0 && s . contains ( sum / 2 ) && ( sum / 2 ) == s . stream ( ) . skip ( s . size ( ) - 1 ) . findFirst ( ) . get ( ) ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int array [ ] = { 1 , 2 , 3 } ; int n = array . length ; System . out . println ( checkForElement ( array , n ) ? " Yes " : " No " ) ; } }

def checkForElement ( array , n ) : NEW_LINE INDENT s = set ( ) NEW_LINE sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += array [ i ] NEW_LINE s . add ( array [ i ] ) NEW_LINE DEDENT f = int ( sum / 2 ) NEW_LINE if ( sum % 2 == 0 and f in s ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT array = [ 1 , 2 , 3 ] NEW_LINE n = len ( array ) NEW_LINE if ( checkForElement ( array , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . util . * ; class GFg { static int MAX = 10000 ; static int [ ] prodDig = new int [ MAX ] ; static int getDigitProduct ( int x ) { if ( x < 10 ) return x ; if ( prodDig [ x ] != 0 ) return prodDig [ x ] ; int prod = ( x % 10 ) * getDigitProduct ( x / 10 ) ; return ( prodDig [ x ] = prod ) ; } static void findSeed ( int n ) { List < Integer > res = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= n / 2 ; i ++ ) if ( i * getDigitProduct ( i ) == n ) res . add ( i ) ; if ( res . size ( ) == 0 ) { System . out . println ( " NO ▁ seed ▁ exists " ) ; return ; } for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 138 ; findSeed ( n ) ; } }

MAX = 10000 ; NEW_LINE prodDig = [ 0 ] * MAX ; NEW_LINE def getDigitProduct ( x ) : NEW_LINE INDENT if ( x < 10 ) : NEW_LINE INDENT return x ; NEW_LINE DEDENT if ( prodDig [ x ] != 0 ) : NEW_LINE INDENT return prodDig [ x ] ; NEW_LINE DEDENT prod = ( int ( x % 10 ) * getDigitProduct ( int ( x / 10 ) ) ) ; NEW_LINE prodDig [ x ] = prod ; NEW_LINE return prod ; NEW_LINE DEDENT def findSeed ( n ) : NEW_LINE INDENT res = [ ] ; NEW_LINE for i in range ( 1 , int ( n / 2 + 2 ) ) : NEW_LINE INDENT if ( i * getDigitProduct ( i ) == n ) : NEW_LINE INDENT res . append ( i ) ; NEW_LINE DEDENT DEDENT if ( len ( res ) == 0 ) : NEW_LINE INDENT print ( " NO ▁ seed ▁ exists " ) ; NEW_LINE return ; NEW_LINE DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT n = 138 ; NEW_LINE findSeed ( n ) ; NEW_LINE


import java . io . * ; class GFG { static int sumOdd ( int n ) { int terms = ( n + 1 ) / 2 ; int sum = terms * terms ; return sum ; } static int suminRange ( int l , int r ) { return sumOdd ( r ) - sumOdd ( l - 1 ) ; } public static void main ( String [ ] args ) { int l = 2 , r = 5 ; System . out . print ( " Sum ▁ of ▁ odd ▁ natural ▁ numbers ▁ from ▁ L ▁ to ▁ R ▁ is ▁ " + suminRange ( l , r ) ) ; } }

def sumOdd ( n ) : NEW_LINE INDENT terms = ( n + 1 ) // 2 NEW_LINE sum1 = terms * terms NEW_LINE return sum1 NEW_LINE DEDENT def suminRange ( l , r ) : NEW_LINE INDENT return sumOdd ( r ) - sumOdd ( l - 1 ) NEW_LINE DEDENT l = 2 ; r = 5 NEW_LINE print ( " Sum ▁ of ▁ odd ▁ natural ▁ number " , " from ▁ L ▁ to ▁ R ▁ is " , suminRange ( l , r ) ) NEW_LINE


class GFG { static boolean isSumOfPowersOfTwo ( int n ) { if ( n % 2 == 1 ) return false ; else return true ; } public static void main ( String args [ ] ) { int n = 10 ; if ( isSumOfPowersOfTwo ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

def isSumOfPowersOfTwo ( n ) : NEW_LINE INDENT if n % 2 == 1 : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT n = 10 NEW_LINE if isSumOfPowersOfTwo ( n ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT


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

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


import java . util . * ; import java . lang . * ; public class GfG { static int evenSum ( int n ) { return ( n * ( n + 1 ) ) ; } public static void main ( String argc [ ] ) { int n = 20 ; System . out . println ( " Sum ▁ of ▁ first ▁ " + n + " ▁ Even ▁ numbers ▁ is : ▁ " + evenSum ( n ) ) ; } }

def evensum ( n ) : NEW_LINE INDENT return n * ( n + 1 ) NEW_LINE DEDENT n = 20 NEW_LINE print ( " sum ▁ of ▁ first " , n , " even ▁ number ▁ is : ▁ " , evensum ( n ) ) NEW_LINE


import java . util . * ; class GFG { static long gcd ( long a , long 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 ) ; } public static long getRounding ( long n , long k ) { long rounding = ( long ) Math . pow ( 10 , k ) ; long result = gcd ( rounding , n ) ; return ( ( rounding * n ) / result ) ; } public static void main ( String [ ] args ) { long n = 375 , k = 4 ; System . out . println ( getRounding ( n , k ) ) ; } }

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 getRounding ( n , k ) : NEW_LINE INDENT rounding = pow ( 10 , k ) ; NEW_LINE result = gcd ( rounding , n ) NEW_LINE return ( ( rounding * n ) / result ) NEW_LINE DEDENT n = 375 NEW_LINE k = 4 NEW_LINE print ( int ( getRounding ( n , k ) ) ) NEW_LINE


import java . util . * ; class GFG { static final int MAX = 200006 ; static final int CONS = 32766 ; static void calc ( int a [ ] , int b [ ] , int lr [ ] , int q , int n ) { int M , m , i , j , k , l , r , suma , sumb , cc ; cc = 0 ; for ( i = 0 ; i < n - 1 ; ++ i ) { a [ i + 1 ] += a [ i ] ; b [ i + 1 ] += b [ i ] ; } while ( q != 0 ) { l = lr [ cc ++ ] ; r = lr [ cc ++ ] ; l -= 2 ; r -= 1 ; suma = a [ r ] ; sumb = b [ r ] ; if ( l >= 0 ) { suma -= a [ l ] ; sumb -= b [ l ] ; } M = Math . max ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; M = Math . max ( M , Math . max ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; m = Math . min ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; m = Math . min ( m , Math . min ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; System . out . println ( ( M - m ) ) ; q -- ; } } public static void main ( String [ ] args ) { int n = 5 , q = 2 ; int [ ] a = { 0 , 7 , 3 , 4 , 5 } ; int [ ] b = { 0 , 3 , 1 , 2 , 3 } ; int [ ] lr = new int [ q * 2 ] ; lr [ 0 ] = 1 ; lr [ 1 ] = 1 ; lr [ 2 ] = 1 ; lr [ 3 ] = 3 ; calc ( a , b , lr , q , n ) ; } }

MAX = 200006 NEW_LINE CONS = 32766 NEW_LINE def calc ( a , b , lr , q , n ) : NEW_LINE INDENT cc = 0 NEW_LINE for i in range ( n - 1 ) : NEW_LINE INDENT a [ i + 1 ] += a [ i ] NEW_LINE b [ i + 1 ] += b [ i ] NEW_LINE DEDENT while ( q > 0 ) : NEW_LINE INDENT l = lr [ cc ] NEW_LINE cc += 1 NEW_LINE r = lr [ cc ] NEW_LINE cc += 1 NEW_LINE l -= 2 NEW_LINE r -= 1 NEW_LINE suma = a [ r ] NEW_LINE sumb = b [ r ] NEW_LINE if ( l >= 0 ) : NEW_LINE INDENT suma -= a [ l ] NEW_LINE sumb -= b [ l ] NEW_LINE DEDENT M = max ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) NEW_LINE M = max ( M , max ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) NEW_LINE m = min ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) NEW_LINE m = min ( m , min ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) NEW_LINE print ( M - m ) NEW_LINE q -= 1 NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE q = 2 NEW_LINE a = [ 0 , 7 , 3 , 4 , 5 ] NEW_LINE b = [ 0 , 3 , 1 , 2 , 3 ] NEW_LINE lr = [ 0 ] * ( q * 2 ) NEW_LINE lr [ 0 ] = 1 NEW_LINE lr [ 1 ] = 1 NEW_LINE lr [ 2 ] = 1 NEW_LINE lr [ 3 ] = 3 NEW_LINE calc ( a , b , lr , q , n ) NEW_LINE DEDENT


class GFG { static boolean digitDividesK ( int num , int k ) { while ( num != 0 ) { int d = num % 10 ; if ( d != 0 && k % d == 0 ) return true ; num = num / 10 ; } return false ; } static int findCount ( int l , int r , int k ) { int count = 0 ; for ( int i = l ; i <= r ; i ++ ) { if ( digitDividesK ( i , k ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int l = 20 , r = 35 ; int k = 45 ; System . out . println ( findCount ( l , r , k ) ) ; } }

def digitDividesK ( num , k ) : NEW_LINE INDENT while ( num ) : NEW_LINE INDENT d = num % 10 NEW_LINE if ( d != 0 and k % d == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT num = num // 10 NEW_LINE DEDENT return False NEW_LINE DEDENT def findCount ( l , r , k ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( l , r + 1 ) : NEW_LINE INDENT if ( digitDividesK ( i , k ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT l = 20 NEW_LINE r = 35 NEW_LINE k = 45 NEW_LINE print ( findCount ( l , r , k ) ) NEW_LINE