import java . util . * ; class solution { static int calculateSum ( int n ) { return n * ( int ) ( Math . pow ( n , 2 ) + 3 * n + 5 ) / 3 ; } public static void main ( String arr [ ] ) { int n = 3 ; System . out . println ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }

from math import pow NEW_LINE def calculateSum ( n ) : NEW_LINE INDENT return n * ( pow ( n , 2 ) + 3 * n + 5 ) / 3 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( " Sum ▁ = " , int ( calculateSum ( n ) ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void printTrib ( int n ) { if ( n < 1 ) return ; int first = 0 , second = 0 ; int third = 1 ; System . out . print ( first + " ▁ " ) ; if ( n > 1 ) System . out . print ( second + " ▁ " ) ; if ( n > 2 ) System . out . print ( second + " ▁ " ) ; for ( int i = 3 ; i < n ; i ++ ) { int curr = first + second + third ; first = second ; second = third ; third = curr ; System . out . print ( curr + " ▁ " ) ; } } public static void main ( String args [ ] ) { int n = 10 ; printTrib ( n ) ; } }

def printTrib ( n ) : NEW_LINE INDENT if ( n < 1 ) : NEW_LINE INDENT return NEW_LINE DEDENT first = 0 NEW_LINE second = 0 NEW_LINE third = 1 NEW_LINE print ( first , " ▁ " , end = " " ) NEW_LINE if ( n > 1 ) : NEW_LINE INDENT print ( second , " ▁ " , end = " " ) NEW_LINE DEDENT if ( n > 2 ) : NEW_LINE INDENT print ( second , " ▁ " , end = " " ) NEW_LINE DEDENT for i in range ( 3 , n ) : NEW_LINE INDENT curr = first + second + third NEW_LINE first = second NEW_LINE second = third NEW_LINE third = curr NEW_LINE print ( curr , " ▁ " , end = " " ) NEW_LINE DEDENT DEDENT n = 10 NEW_LINE printTrib ( n ) NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class KPaths { static final int V = 4 ; int countwalks ( int graph [ ] [ ] , int u , int v , int k ) { if ( k == 0 && u == v ) return 1 ; if ( k == 1 && graph [ u ] [ v ] == 1 ) return 1 ; if ( k <= 0 ) return 0 ; int count = 0 ; for ( int i = 0 ; i < V ; i ++ ) if ( graph [ u ] [ i ] == 1 ) count += countwalks ( graph , i , v , k - 1 ) ; return count ; } public static void main ( String [ ] args ) throws java . lang . Exception { int graph [ ] [ ] = new int [ ] [ ] { { 0 , 1 , 1 , 1 } , { 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 } } ; int u = 0 , v = 3 , k = 2 ; KPaths p = new KPaths ( ) ; System . out . println ( p . countwalks ( graph , u , v , k ) ) ; } }

V = 4 NEW_LINE def countwalks ( graph , u , v , k ) : NEW_LINE INDENT if ( k == 0 and u == v ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( k == 1 and graph [ u ] [ v ] ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( k <= 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT count = 0 NEW_LINE for i in range ( 0 , V ) : NEW_LINE INDENT if ( graph [ u ] [ i ] == 1 ) : NEW_LINE INDENT count += countwalks ( graph , i , v , k - 1 ) NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT graph = [ [ 0 , 1 , 1 , 1 , ] , [ 0 , 0 , 0 , 1 , ] , [ 0 , 0 , 0 , 1 , ] , [ 0 , 0 , 0 , 0 ] ] NEW_LINE u = 0 ; v = 3 ; k = 2 NEW_LINE print ( countwalks ( graph , u , v , k ) ) NEW_LINE


import java . util . * ; class GFG { static void maxProduct ( int arr [ ] , int n ) { if ( n < 2 ) { System . out . println ( " No ▁ pairs ▁ exists " ) ; return ; } if ( n == 2 ) { System . out . println ( arr [ 0 ] + " ▁ " + arr [ 1 ] ) ; return ; } int posa = Integer . MIN_VALUE , posb = Integer . MIN_VALUE ; int nega = Integer . MIN_VALUE , negb = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > posa ) { posb = posa ; posa = arr [ i ] ; } else if ( arr [ i ] > posb ) posb = arr [ i ] ; if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( nega ) ) { negb = nega ; nega = arr [ i ] ; } else if ( arr [ i ] < 0 && Math . abs ( arr [ i ] ) > Math . abs ( negb ) ) negb = arr [ i ] ; } if ( nega * negb > posa * posb ) System . out . println ( " Max ▁ product ▁ pair ▁ is ▁ { " + nega + " , ▁ " + negb + " } " ) ; else System . out . println ( " Max ▁ product ▁ pair ▁ is ▁ { " + posa + " , ▁ " + posb + " } " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 3 , 6 , 7 , 0 } ; int n = arr . length ; maxProduct ( arr , n ) ; } }

def maxProduct ( arr , n ) : NEW_LINE INDENT if ( n < 2 ) : NEW_LINE INDENT print ( " No ▁ pairs ▁ exists " ) NEW_LINE return NEW_LINE DEDENT if ( n == 2 ) : NEW_LINE INDENT print ( arr [ 0 ] , " ▁ " , arr [ 1 ] ) NEW_LINE return NEW_LINE DEDENT posa = 0 NEW_LINE posb = 0 NEW_LINE nega = 0 NEW_LINE negb = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > posa ) : NEW_LINE INDENT posb = posa NEW_LINE posa = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] > posb ) : NEW_LINE INDENT posb = arr [ i ] NEW_LINE DEDENT if ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( nega ) ) : NEW_LINE INDENT negb = nega NEW_LINE nega = arr [ i ] NEW_LINE DEDENT elif ( arr [ i ] < 0 and abs ( arr [ i ] ) > abs ( negb ) ) : NEW_LINE INDENT negb = arr [ i ] NEW_LINE DEDENT DEDENT if ( nega * negb > posa * posb ) : NEW_LINE INDENT print ( " Max ▁ product ▁ pair ▁ is ▁ { " , nega , " , ▁ " , negb , " } " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Max ▁ product ▁ pair ▁ is ▁ { " , posa , " , ▁ " , posb , " } " ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 4 , 3 , 6 , 7 , 0 ] NEW_LINE n = len ( arr ) NEW_LINE maxProduct ( arr , n ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static float ellipse ( float l , float b ) { if ( l < 0 || b < 0 ) return - 1 ; float x = ( float ) ( 3.14 * l * b ) / 4 ; return x ; } public static void main ( String args [ ] ) { float a = 5 , b = 3 ; System . out . println ( ellipse ( a , b ) ) ; } }

def ellipse ( l , b ) : NEW_LINE INDENT if l < 0 or b < 0 : NEW_LINE INDENT return - 1 NEW_LINE DEDENT x = ( 3.14 * l * b ) / 4 NEW_LINE return x NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l , b = 5 , 3 NEW_LINE print ( ellipse ( l , b ) ) NEW_LINE DEDENT


class GFG { static int getHCF ( int x , int y ) { int minimum = Math . min ( x , y ) ; if ( x % minimum == 0 && y % minimum == 0 ) return minimum ; for ( int i = minimum / 2 ; i >= 2 ; i -- ) { if ( x % i == 0 && y % i == 0 ) return i ; } return 1 ; } public static void main ( String [ ] args ) { int x = 16 , y = 32 ; System . out . println ( getHCF ( x , y ) ) ; } }

def getHCF ( x , y ) : NEW_LINE INDENT minimum = min ( x , y ) NEW_LINE if ( x % minimum == 0 and y % minimum == 0 ) : NEW_LINE INDENT return minimum NEW_LINE DEDENT for i in range ( minimum // 2 , 1 , - 1 ) : NEW_LINE INDENT if ( x % i == 0 and y % i == 0 ) : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT return 1 NEW_LINE DEDENT x , y = 16 , 32 NEW_LINE print ( getHCF ( x , y ) ) NEW_LINE


import java . io . * ; class GFG { static int RODS = 3 ; static int N = 3 ; static int [ ] [ ] [ ] dp = new int [ N + 1 ] [ RODS + 1 ] [ RODS + 1 ] ; static void initialize ( ) { for ( int i = 0 ; i <= N ; i += 1 ) { for ( int j = 1 ; j <= RODS ; j ++ ) { for ( int k = 1 ; k <= RODS ; k += 1 ) { dp [ i ] [ j ] [ k ] = Integer . MAX_VALUE ; } } } } static int mincost ( int idx , int src , int dest , int costs [ ] [ ] ) { if ( idx > N ) return 0 ; if ( dp [ idx ] [ src ] [ dest ] != Integer . MAX_VALUE ) return dp [ idx ] [ src ] [ dest ] ; int rem = 6 - ( src + dest ) ; int ans = Integer . MAX_VALUE ; int case1 = costs [ src - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , rem , costs ) + mincost ( idx + 1 , rem , dest , costs ) ; int case2 = costs [ src - 1 ] [ rem - 1 ] + mincost ( idx + 1 , src , dest , costs ) + mincost ( idx + 1 , dest , src , costs ) + costs [ rem - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , dest , costs ) ; ans = Math . min ( case1 , case2 ) ; dp [ idx ] [ src ] [ dest ] = ans ; return ans ; } public static void main ( String [ ] args ) { int [ ] [ ] costs = { { 0 , 1 , 2 } , { 2 , 0 , 1 } , { 3 , 2 , 0 } } ; initialize ( ) ; System . out . print ( mincost ( 1 , 1 , 3 , costs ) ) ; } }

import numpy as np NEW_LINE import sys NEW_LINE RODS = 3 NEW_LINE N = 3 NEW_LINE dp = np . zeros ( ( N + 1 , RODS + 1 , RODS + 1 ) ) ; NEW_LINE def initialize ( ) : NEW_LINE INDENT for i in range ( N + 1 ) : NEW_LINE INDENT for j in range ( 1 , RODS + 1 ) : NEW_LINE INDENT for k in range ( 1 , RODS + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] [ k ] = sys . maxsize ; NEW_LINE DEDENT DEDENT DEDENT DEDENT def mincost ( idx , src , dest , costs ) : NEW_LINE INDENT if ( idx > N ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( dp [ idx ] [ src ] [ dest ] != sys . maxsize ) : NEW_LINE INDENT return dp [ idx ] [ src ] [ dest ] ; NEW_LINE DEDENT rem = 6 - ( src + dest ) ; NEW_LINE ans = sys . maxsize ; NEW_LINE case1 = costs [ src - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , rem , costs ) + mincost ( idx + 1 , rem , dest , costs ) ; NEW_LINE case2 = ( costs [ src - 1 ] [ rem - 1 ] + mincost ( idx + 1 , src , dest , costs ) + mincost ( idx + 1 , dest , src , costs ) + costs [ rem - 1 ] [ dest - 1 ] + mincost ( idx + 1 , src , dest , costs ) ) ; NEW_LINE ans = min ( case1 , case2 ) ; NEW_LINE dp [ idx ] [ src ] [ dest ] = ans ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT costs = [ [ 0 , 1 , 2 ] , [ 2 , 0 , 1 ] , [ 3 , 2 , 0 ] ] ; NEW_LINE initialize ( ) ; NEW_LINE print ( mincost ( 1 , 1 , 3 , costs ) ) ; NEW_LINE DEDENT


import java . io . * ; import java . util . * ; class CountTriangles { static int findNumberOfTriangles ( int arr [ ] ) { int n = arr . length ; Arrays . sort ( arr ) ; int count = 0 ; for ( int i = 0 ; i < n - 2 ; ++ i ) { int k = i + 2 ; for ( int j = i + 1 ; j < n ; ++ j ) { while ( k < n && arr [ i ] + arr [ j ] > arr [ k ] ) ++ k ; if ( k > j ) count += k - j - 1 ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 21 , 22 , 100 , 101 , 200 , 300 } ; System . out . println ( " Total ▁ number ▁ of ▁ triangles ▁ is ▁ " + findNumberOfTriangles ( arr ) ) ; } }

def findnumberofTriangles ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE arr . sort ( ) NEW_LINE count = 0 NEW_LINE for i in range ( 0 , n - 2 ) : NEW_LINE INDENT k = i + 2 NEW_LINE for j in range ( i + 1 , n ) : NEW_LINE INDENT while ( k < n and arr [ i ] + arr [ j ] > arr [ k ] ) : NEW_LINE INDENT k += 1 NEW_LINE DEDENT if ( k > j ) : NEW_LINE INDENT count += k - j - 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT arr = [ 10 , 21 , 22 , 100 , 101 , 200 , 300 ] NEW_LINE print " Number ▁ of ▁ Triangles : " , findnumberofTriangles ( arr ) NEW_LINE


class GFG { static String addZeros ( String str , int n ) { for ( int i = 0 ; i < n ; i ++ ) { str = "0" + str ; } return str ; } static String getXOR ( String a , String b ) { int aLen = a . length ( ) ; int bLen = b . length ( ) ; if ( aLen > bLen ) { a = addZeros ( b , aLen - bLen ) ; } else if ( bLen > aLen ) { a = addZeros ( a , bLen - aLen ) ; } int len = Math . max ( aLen , bLen ) ; String res = " " ; for ( int i = 0 ; i < len ; i ++ ) { if ( a . charAt ( i ) == b . charAt ( i ) ) res += "0" ; else res += "1" ; } return res ; } public static void main ( String [ ] args ) { String a = "11001" , b = "111111" ; System . out . println ( getXOR ( a , b ) ) ; } }

def addZeros ( strr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT strr = "0" + strr NEW_LINE DEDENT return strr NEW_LINE DEDENT def getXOR ( a , b ) : NEW_LINE INDENT aLen = len ( a ) NEW_LINE bLen = len ( b ) NEW_LINE if ( aLen > bLen ) : NEW_LINE INDENT b = addZeros ( b , aLen - bLen ) NEW_LINE DEDENT elif ( bLen > aLen ) : NEW_LINE INDENT a = addZeros ( a , bLen - aLen ) NEW_LINE DEDENT lenn = max ( aLen , bLen ) ; NEW_LINE res = " " NEW_LINE for i in range ( lenn ) : NEW_LINE INDENT if ( a [ i ] == b [ i ] ) : NEW_LINE INDENT res += "0" NEW_LINE DEDENT else : NEW_LINE INDENT res += "1" NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT a = "11001" NEW_LINE b = "111111" NEW_LINE print ( getXOR ( a , b ) ) NEW_LINE


class GFG { public static long SubArraySum ( int arr [ ] , int n ) { long result = 0 , temp = 0 ; for ( int i = 0 ; i < n ; i ++ ) { temp = 0 ; for ( int j = i ; j < n ; j ++ ) { temp += arr [ j ] ; result += temp ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 } ; int n = arr . length ; System . out . println ( " Sum ▁ of ▁ SubArray ▁ : ▁ " + SubArraySum ( arr , n ) ) ; } }

def SubArraySum ( arr , n ) : NEW_LINE INDENT temp , result = 0 , 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT temp = 0 ; NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT temp += arr [ j ] NEW_LINE result += temp NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ 1 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Sum ▁ of ▁ SubArray ▁ : " , SubArraySum ( arr , n ) ) NEW_LINE


import java . io . * ; class GFG { static int countSubarray ( int arr [ ] , int n , int k ) { int start = 0 , end = 0 ; int count = 0 , sum = arr [ 0 ] ; while ( start < n && end < n ) { if ( sum < k ) { end ++ ; if ( end >= start ) count += end - start ; if ( end < n ) sum += arr [ end ] ; } else { sum -= arr [ start ] ; start ++ ; } } return count ; } public static void main ( String [ ] args ) { int array [ ] = { 1 , 11 , 2 , 3 , 15 } ; int k = 10 ; int size = array . length ; int count = countSubarray ( array , size , k ) ; System . out . println ( count ) ; } }

def countSubarrays ( arr , n , k ) : NEW_LINE INDENT start = 0 NEW_LINE end = 0 NEW_LINE count = 0 NEW_LINE sum = arr [ 0 ] NEW_LINE while ( start < n and end < n ) : NEW_LINE INDENT if ( sum < k ) : NEW_LINE INDENT end += 1 NEW_LINE if ( end >= start ) : NEW_LINE INDENT count += end - start NEW_LINE DEDENT if ( end < n ) : NEW_LINE INDENT sum += arr [ end ] NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT sum -= arr [ start ] NEW_LINE start += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT array = [ 1 , 11 , 2 , 3 , 15 ] NEW_LINE k = 10 NEW_LINE size = len ( array ) NEW_LINE print ( countSubarrays ( array , size , k ) ) NEW_LINE DEDENT


import java . io . * ; class ring { public static boolean checkcircle ( int r , int R , int r1 , int x1 , int y1 ) { int dis = ( int ) Math . sqrt ( x1 * x1 + y1 * y1 ) ; return ( dis - r1 >= R && dis + r1 <= r ) ; } public static void main ( String args [ ] ) { int r = 8 , R = 4 , r1 = 2 , x1 = 6 , y1 = 0 ; if ( checkcircle ( r , R , r1 , x1 , y1 ) ) System . out . println ( " yes " ) ; else System . out . println ( " no " ) ; } }

import math NEW_LINE def checkcircle ( r , R , r1 , x1 , y1 ) : NEW_LINE INDENT dis = int ( math . sqrt ( x1 * x1 + y1 * y1 ) ) NEW_LINE return ( dis - r1 >= R and dis + r1 <= r ) NEW_LINE DEDENT r = 8 ; R = 4 ; r1 = 2 ; x1 = 6 ; y1 = 0 NEW_LINE if ( checkcircle ( r , R , r1 , x1 , y1 ) ) : NEW_LINE INDENT print ( " yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " no " ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int solve ( int n , int m , int obstacles , double range [ ] ) { double val = Math . min ( n , m ) ; Arrays . sort ( range ) ; int c = 1 ; for ( int i = obstacles - 1 ; i >= 0 ; i -- ) { range [ i ] = 2 * range [ i ] ; val -= range [ i ] ; if ( val <= 0 ) { return c ; } else { c ++ ; } } if ( val > 0 ) { return - 1 ; } return 0 ; } public static void main ( String [ ] args ) { int n = 4 , m = 5 , obstacles = 3 ; double range [ ] = { 1.0 , 1.25 , 1.15 } ; System . out . print ( solve ( n , m , obstacles , range ) + " \n " ) ; } }

def solve ( n , m , obstacles , rangee ) : NEW_LINE INDENT val = min ( n , m ) NEW_LINE rangee = sorted ( rangee ) NEW_LINE c = 1 NEW_LINE for i in range ( obstacles - 1 , - 1 , - 1 ) : NEW_LINE INDENT rangee [ i ] = 2 * rangee [ i ] NEW_LINE val -= rangee [ i ] NEW_LINE if ( val <= 0 ) : NEW_LINE INDENT return c NEW_LINE DEDENT else : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT if ( val > 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT DEDENT n = 4 NEW_LINE m = 5 NEW_LINE obstacles = 3 NEW_LINE rangee = [ 1.0 , 1.25 , 1.15 ] NEW_LINE print ( solve ( n , m , obstacles , rangee ) ) NEW_LINE


import java . io . * ; class GFG { static int maxSubArraySumRepeated ( int a [ ] , int n , int k ) { int max_so_far = 0 ; int INT_MIN , max_ending_here = 0 ; for ( int i = 0 ; i < n * k ; i ++ ) { max_ending_here = max_ending_here + a [ i % n ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } public static void main ( String [ ] args ) { int a [ ] = { 10 , 20 , - 30 , - 1 } ; int n = a . length ; int k = 3 ; System . out . println ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ " + maxSubArraySumRepeated ( a , n , k ) ) ; } }

def maxSubArraySumRepeated ( a , n , k ) : NEW_LINE INDENT max_so_far = - 2147483648 NEW_LINE max_ending_here = 0 NEW_LINE for i in range ( n * k ) : NEW_LINE INDENT max_ending_here = max_ending_here + a [ i % n ] NEW_LINE if ( max_so_far < max_ending_here ) : NEW_LINE INDENT max_so_far = max_ending_here NEW_LINE DEDENT if ( max_ending_here < 0 ) : NEW_LINE INDENT max_ending_here = 0 NEW_LINE DEDENT DEDENT return max_so_far NEW_LINE DEDENT a = [ 10 , 20 , - 30 , - 1 ] NEW_LINE n = len ( a ) NEW_LINE k = 3 NEW_LINE print ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ " , maxSubArraySumRepeated ( a , n , k ) ) NEW_LINE


class GFG { static void binaryRightAngleTriangle ( int n ) { int row , col ; for ( row = 0 ; row < n ; row ++ ) { for ( col = 0 ; col <= row ; col ++ ) { if ( ( ( row + col ) % 2 ) == 0 ) System . out . print ( "0" ) ; else System . out . print ( "1" ) ; System . out . print ( " \t " ) ; } System . out . print ( " \n " ) ; } } public static void main ( String [ ] args ) { int n = 4 ; binaryRightAngleTriangle ( n ) ; } }

def binaryRightAngleTriangle ( n ) : NEW_LINE INDENT for row in range ( 0 , n ) : NEW_LINE INDENT for col in range ( 0 , row + 1 ) : NEW_LINE INDENT if ( ( ( row + col ) % 2 ) == 0 ) : NEW_LINE INDENT print ( "0" , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( "1" , end = " " ) NEW_LINE DEDENT print ( " \t " , end = " " ) NEW_LINE DEDENT print ( " " ) NEW_LINE DEDENT DEDENT n = 4 NEW_LINE binaryRightAngleTriangle ( n ) NEW_LINE


class GFG { static final int INT_SIZE = 32 ; static int getSingle ( int arr [ ] , int n ) { int result = 0 ; int x , sum ; for ( int i = 0 ; i < INT_SIZE ; i ++ ) { sum = 0 ; x = ( 1 << i ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( arr [ j ] & x ) == 0 ) sum ++ ; } if ( ( sum % 3 ) == 0 ) result |= x ; } return result ; } public static void main ( String args [ ] ) { int arr [ ] = { 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 } ; int n = arr . length ; System . out . println ( " The ▁ element ▁ with ▁ single ▁ occurrence ▁ is ▁ " + getSingle ( arr , n ) ) ; } }

INT_SIZE = 32 NEW_LINE def getSingle ( arr , n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( 0 , INT_SIZE ) : NEW_LINE INDENT sm = 0 NEW_LINE x = ( 1 << i ) NEW_LINE for j in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ j ] & x ) : NEW_LINE INDENT sm = sm + 1 NEW_LINE DEDENT DEDENT if ( sm % 3 ) : NEW_LINE INDENT result = result | x NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ 12 , 1 , 12 , 3 , 12 , 1 , 1 , 2 , 3 , 2 , 2 , 3 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " The ▁ element ▁ with ▁ single ▁ occurrence ▁ is ▁ " , getSingle ( arr , n ) ) NEW_LINE


def hut_pattern ( n ) : NEW_LINE INDENT if n % 2 == 0 : NEW_LINE INDENT n = n + 1 NEW_LINE DEDENT for i in range ( 0 , n - n // 3 + 1 , 1 ) : NEW_LINE INDENT for j in range ( 0 , n , 1 ) : NEW_LINE INDENT t = 2 * n / 5 NEW_LINE if t % 2 != 0 : NEW_LINE INDENT t = t - 1 NEW_LINE DEDENT if ( ( i == n / 5 ) or ( i == n - n / 3 ) or ( j == n - 1 and i >= n / 5 ) or ( j >= n / 5 and j < n - n / 5 and i == 0 ) or ( j == 0 and i >= n / 5 ) or ( j == t and i > n / 5 ) or ( i <= n / 5 and ( i + j == n / 5 or j - i == n / 5 ) ) or ( j - i == n - n / 5 ) ) : NEW_LINE INDENT print ( " * " , end = " ▁ " ) NEW_LINE DEDENT elif ( ( i == n // 5 + n // 7 ) and ( j >= n // 7 and j <= t - n // 7 ) ) : NEW_LINE INDENT print ( " _ " , end = " ▁ " ) NEW_LINE DEDENT elif ( ( i >= n // 5 + n // 7 ) and ( j == n // 7 or j == t - n // 7 ) ) : NEW_LINE INDENT print ( " | " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ▁ " , end = " ▁ " ) NEW_LINE DEDENT DEDENT print ( " \n " ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 15 NEW_LINE hut_pattern ( n ) NEW_LINE DEDENT


import java . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int largestGCD1Subset ( int A [ ] , int n ) { int currentGCD = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { currentGCD = gcd ( currentGCD , A [ i ] ) ; if ( currentGCD == 1 ) return n ; } return 0 ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 18 , 6 , 3 } ; int n = A . length ; System . out . println ( largestGCD1Subset ( A , n ) ) ; } }

def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b NEW_LINE DEDENT return gcd ( b % a , a ) NEW_LINE DEDENT def largestGCD1Subset ( A , n ) : NEW_LINE INDENT currentGCD = A [ 0 ] ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT currentGCD = gcd ( currentGCD , A [ i ] ) NEW_LINE if ( currentGCD == 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT DEDENT return 0 NEW_LINE DEDENT A = [ 2 , 18 , 6 , 3 ] NEW_LINE n = len ( A ) NEW_LINE print ( largestGCD1Subset ( A , n ) ) NEW_LINE


class GFG { static boolean isPalindrome ( String str , int l , int r ) { while ( l < r ) { if ( str . charAt ( l ) != str . charAt ( r ) ) return false ; l ++ ; r -- ; } return true ; } static int CyclicShifts ( String str ) { int n = str . length ( ) ; int left = 0 ; int right = n - 1 ; str = str + str ; int cnt = 0 ; while ( right < 2 * n - 1 ) { if ( isPalindrome ( str , left , right ) ) break ; cnt ++ ; left ++ ; right ++ ; } return cnt ; } public static void main ( String [ ] args ) { String str = " bccbbaab " ; System . out . println ( CyclicShifts ( str ) ) ; } }

def isPalindrome ( str , l , r ) : NEW_LINE INDENT while ( l < r ) : NEW_LINE INDENT if ( str [ l ] != str [ r ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT l += 1 NEW_LINE r -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT def CyclicShifts ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE left = 0 NEW_LINE right = n - 1 NEW_LINE str = str + str NEW_LINE cnt = 0 NEW_LINE while ( right < 2 * n - 1 ) : NEW_LINE INDENT if ( isPalindrome ( str , left , right ) ) : NEW_LINE INDENT break NEW_LINE DEDENT cnt += 1 NEW_LINE left += 1 NEW_LINE right += 1 NEW_LINE DEDENT return cnt NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = " bccbbaab " ; NEW_LINE print ( CyclicShifts ( str ) ) NEW_LINE DEDENT


import java . lang . * ; import java . util . * ; class GFG { static int findNum ( int N , int K ) { int rem = N % K ; if ( rem == 0 ) return N ; else return N - rem ; } public static void main ( String args [ ] ) { int N = 45 , K = 6 ; System . out . print ( " Largest ▁ number ▁ smaller ▁ " + " than ▁ or ▁ equal ▁ to ▁ " + N + " \n that ▁ is ▁ divisible ▁ by ▁ " + K + " ▁ is ▁ " + findNum ( N , K ) ) ; } }

def findNum ( N , K ) : NEW_LINE INDENT rem = N % K NEW_LINE if ( rem == 0 ) : NEW_LINE INDENT return N NEW_LINE DEDENT else : NEW_LINE INDENT return N - rem NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 45 NEW_LINE K = 6 NEW_LINE print ( " Largest ▁ number ▁ smaller ▁ than ▁ or ▁ equal ▁ to " + str ( N ) + " that ▁ is ▁ divisible ▁ by " + str ( K ) + " is " , findNum ( N , K ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int fib ( int n ) { if ( n <= 1 ) return n ; return fib ( n - 1 ) + fib ( n - 2 ) ; } public static void main ( String [ ] args ) { int n = 6 ; System . out . println ( fib ( n ) ) ; } }

def fib ( n ) : NEW_LINE INDENT if ( n <= 1 ) : NEW_LINE INDENT return n NEW_LINE DEDENT return fib ( n - 1 ) + fib ( n - 2 ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 6 NEW_LINE print ( fib ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static void findSubSeq ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int count [ ] = new int [ n ] ; int prev [ ] = new int [ n ] ; int i , j ; for ( i = 0 ; i < n ; i ++ ) count [ i ] = 1 ; for ( j = 0 ; j < n ; j ++ ) prev [ j ] = - 1 ; int max = 0 ; int maxprev = - 1 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = i - 1 ; j >= 0 ; j -- ) { if ( arr [ i ] % arr [ j ] == 0 && count [ j ] + 1 > count [ i ] ) { count [ i ] = count [ j ] + 1 ; prev [ i ] = j ; } } if ( max < count [ i ] ) { max = count [ i ] ; maxprev = i ; } } i = maxprev ; while ( i >= 0 ) { if ( arr [ i ] != - 1 ) System . out . print ( arr [ i ] + " ▁ " ) ; i = prev [ i ] ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; findSubSeq ( arr , n ) ; } }

def findSubSeq ( arr , n ) : NEW_LINE INDENT arr . sort ( ) ; NEW_LINE count = [ 1 ] * n ; NEW_LINE prev = [ - 1 ] * n ; NEW_LINE max = 0 ; NEW_LINE maxprev = - 1 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( arr [ i ] % arr [ j ] == 0 and count [ j ] + 1 > count [ i ] ) : NEW_LINE INDENT count [ i ] = count [ j ] + 1 ; NEW_LINE prev [ i ] = j ; NEW_LINE DEDENT DEDENT if ( max < count [ i ] ) : NEW_LINE INDENT max = count [ i ] ; NEW_LINE maxprev = i ; NEW_LINE DEDENT DEDENT i = maxprev ; NEW_LINE while ( i >= 0 ) : NEW_LINE INDENT if ( arr [ i ] != - 1 ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT i = prev [ i ] ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE findSubSeq ( arr , n ) ; NEW_LINE DEDENT


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

def print_asterisk ( asterisk ) : NEW_LINE INDENT if ( asterisk == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print ( " * ▁ " , end = " " ) ; NEW_LINE print_asterisk ( asterisk - 1 ) ; NEW_LINE DEDENT def print_space ( space ) : NEW_LINE INDENT if ( space == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print ( " ▁ " , end = " " ) ; NEW_LINE print ( " ▁ " , end = " " ) ; NEW_LINE print_space ( space - 1 ) ; NEW_LINE DEDENT def pattern_upper ( n , num ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return ; NEW_LINE DEDENT print_asterisk ( n ) ; NEW_LINE print_space ( 2 * ( num - n ) + 1 ) ; NEW_LINE 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_space ( 2 * n - 1 ) ; NEW_LINE 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


class geeks { public static int firstSetBit ( int n ) { int x = n & ( n - 1 ) ; return ( n ^ x ) ; } public static void main ( String [ ] args ) { int n = 12 ; System . out . println ( firstSetBit ( n ) ) ; } }

def firstSetBit ( n ) : NEW_LINE INDENT x = n & ( n - 1 ) NEW_LINE return ( n ^ x ) NEW_LINE DEDENT n = 12 NEW_LINE print ( firstSetBit ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int sumcommDiv ( int a , int b ) { int n = gcd ( a , b ) ; int sum = 0 ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) sum += i ; else sum += ( n / i ) + i ; } } return sum ; } public static void main ( String [ ] args ) { int a = 10 , b = 15 ; System . out . println ( " Sum ▁ = ▁ " + sumcommDiv ( a , b ) ) ; } }

from math import gcd , sqrt NEW_LINE def sumcommDiv ( a , b ) : NEW_LINE INDENT n = gcd ( a , b ) NEW_LINE sum = 0 NEW_LINE N = int ( sqrt ( n ) ) + 1 NEW_LINE for i in range ( 1 , N , 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT if ( n / i == i ) : NEW_LINE INDENT sum += i NEW_LINE DEDENT else : NEW_LINE INDENT sum += ( n / i ) + i NEW_LINE DEDENT DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 10 NEW_LINE b = 15 NEW_LINE print ( " Sum ▁ = " , int ( sumcommDiv ( a , b ) ) ) NEW_LINE DEDENT


class cfg { static float squareSide ( float a ) { if ( a < 0 ) return - 1 ; float x = ( 0.423f * a ) ; return x ; } public static void main ( String [ ] args ) { float a = 8 ; System . out . println ( squareSide ( a ) ) ; } }

def squareSide ( a ) : NEW_LINE INDENT if ( a < 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT x = 0.423 * a NEW_LINE return x NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 8 NEW_LINE print ( squareSide ( a ) ) NEW_LINE DEDENT


class GFG { static int MAX = 100 ; static int check ( int i , int sum , int n , int k , int a [ ] , int dp [ ] [ ] ) { if ( sum <= 0 ) { return 0 ; } if ( i >= n ) { if ( sum == k ) { return 1 ; } return 0 ; } if ( dp [ i ] [ sum ] != - 1 ) { return dp [ i ] [ sum ] ; } dp [ i ] [ sum ] = check ( i + 1 , sum - 2 * a [ i ] , n , k , a , dp ) | check ( i + 1 , sum , n , k , a , dp ) ; dp [ i ] [ sum ] = check ( i + 1 , sum - ( i + 1 ) , n , k , a , dp ) | dp [ i ] [ sum ] ; dp [ i ] [ sum ] = check ( i + 1 , sum + i + 1 , n , k , a , dp ) | dp [ i ] [ sum ] ; return dp [ i ] [ sum ] ; } static int wrapper ( int n , int k , int a [ ] ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; } int [ ] [ ] dp = new int [ MAX ] [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return check ( 0 , sum , n , k , a , dp ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 , 4 } ; int n = 4 , k = 5 ; if ( wrapper ( n , k , a ) == 1 ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

MAX = 100 NEW_LINE def check ( i , add , n , k , a , dp ) : NEW_LINE INDENT if add <= 0 : NEW_LINE INDENT return False NEW_LINE DEDENT if i >= n : NEW_LINE INDENT if add == k : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if dp [ i ] [ add ] != - 1 : NEW_LINE INDENT return dp [ i ] [ add ] NEW_LINE DEDENT dp [ i ] [ add ] = ( check ( i + 1 , add - 2 * a [ i ] , n , k , a , dp ) or check ( i + 1 , add , n , k , a , dp ) ) NEW_LINE dp [ i ] [ add ] = ( check ( i + 1 , add - ( i + 1 ) , n , k , a , dp ) or dp [ i ] [ add ] ) NEW_LINE dp [ i ] [ add ] = ( check ( i + 1 , add + i + 1 , n , k , a , dp ) or dp [ i ] [ add ] ) NEW_LINE return dp [ i ] [ add ] NEW_LINE DEDENT def wrapper ( n , k , a ) : NEW_LINE INDENT add = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT add += a [ i ] NEW_LINE DEDENT dp = [ - 1 ] * MAX NEW_LINE for i in range ( MAX ) : NEW_LINE INDENT dp [ i ] = [ - 1 ] * MAX NEW_LINE DEDENT return check ( 0 , add , n , k , a , dp ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = [ 1 , 2 , 3 , 4 ] NEW_LINE n = 4 NEW_LINE k = 5 NEW_LINE print ( " Yes " ) if wrapper ( n , k , a ) else print ( " No " ) NEW_LINE DEDENT


class GFG { static int AVLnodes ( int height ) { if ( height == 0 ) return 1 ; else if ( height == 1 ) return 2 ; return ( 1 + AVLnodes ( height - 1 ) + AVLnodes ( height - 2 ) ) ; } public static void main ( String args [ ] ) { int H = 3 ; System . out . println ( AVLnodes ( H ) ) ; } }

def AVLnodes ( height ) : NEW_LINE INDENT if ( height == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif ( height == 1 ) : NEW_LINE INDENT return 2 NEW_LINE DEDENT return ( 1 + AVLnodes ( height - 1 ) + AVLnodes ( height - 2 ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT H = 3 NEW_LINE print ( AVLnodes ( H ) ) NEW_LINE DEDENT


import java . util . * ; class Fibonacci { public static int min ( int x , int y ) { return ( x <= y ) ? x : y ; } public static int fibMonaccianSearch ( int arr [ ] , int x , int n ) { int fibMMm2 = 0 ; int fibMMm1 = 1 ; int fibM = fibMMm2 + fibMMm1 ; while ( fibM < n ) { fibMMm2 = fibMMm1 ; fibMMm1 = fibM ; fibM = fibMMm2 + fibMMm1 ; } int offset = - 1 ; while ( fibM > 1 ) { int i = min ( offset + fibMMm2 , n - 1 ) ; if ( arr [ i ] < x ) { fibM = fibMMm1 ; fibMMm1 = fibMMm2 ; fibMMm2 = fibM - fibMMm1 ; offset = i ; } else if ( arr [ i ] > x ) { fibM = fibMMm2 ; fibMMm1 = fibMMm1 - fibMMm2 ; fibMMm2 = fibM - fibMMm1 ; } else return i ; } if ( fibMMm1 == 1 && arr [ offset + 1 ] == x ) return offset + 1 ; return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 22 , 35 , 40 , 45 , 50 , 80 , 82 , 85 , 90 , 100 } ; int n = 11 ; int x = 85 ; System . out . print ( " Found ▁ at ▁ index : ▁ " + fibMonaccianSearch ( arr , x , n ) ) ; } }

from bisect import bisect_left NEW_LINE def fibMonaccianSearch ( arr , x , n ) : NEW_LINE INDENT fibMMm2 = 0 NEW_LINE fibMMm1 = 1 NEW_LINE fibM = fibMMm2 + fibMMm1 NEW_LINE while ( fibM < n ) : NEW_LINE INDENT fibMMm2 = fibMMm1 NEW_LINE fibMMm1 = fibM NEW_LINE fibM = fibMMm2 + fibMMm1 NEW_LINE DEDENT offset = - 1 ; NEW_LINE while ( fibM > 1 ) : NEW_LINE INDENT i = min ( offset + fibMMm2 , n - 1 ) NEW_LINE if ( arr [ i ] < x ) : NEW_LINE INDENT fibM = fibMMm1 NEW_LINE fibMMm1 = fibMMm2 NEW_LINE fibMMm2 = fibM - fibMMm1 NEW_LINE offset = i NEW_LINE DEDENT elif ( arr [ i ] > x ) : NEW_LINE INDENT fibM = fibMMm2 NEW_LINE fibMMm1 = fibMMm1 - fibMMm2 NEW_LINE fibMMm2 = fibM - fibMMm1 NEW_LINE DEDENT else : NEW_LINE INDENT return i NEW_LINE DEDENT DEDENT if ( fibMMm1 and arr [ offset + 1 ] == x ) : NEW_LINE INDENT return offset + 1 ; NEW_LINE DEDENT return - 1 NEW_LINE DEDENT arr = [ 10 , 22 , 35 , 40 , 45 , 50 , 80 , 82 , 85 , 90 , 100 ] NEW_LINE n = len ( arr ) NEW_LINE x = 85 NEW_LINE print ( " Found ▁ at ▁ index : " , fibMonaccianSearch ( arr , x , n ) ) NEW_LINE


import java . io . * ; class GFG { static boolean checkForElement ( int array [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += array [ i ] ; if ( sum % 2 > 0 ) return false ; sum /= 2 ; int start = 0 ; int end = n - 1 ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( array [ mid ] == sum ) return true ; else if ( array [ mid ] > sum ) end = mid - 1 ; else start = mid + 1 ; } return false ; } public static void main ( String [ ] args ) { int array [ ] = { 1 , 2 , 3 } ; int n = array . length ; if ( checkForElement ( array , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def checkForElement ( array , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += array [ i ] NEW_LINE DEDENT if ( sum % 2 ) : NEW_LINE INDENT return False NEW_LINE DEDENT sum //= 2 NEW_LINE start = 0 NEW_LINE end = n - 1 NEW_LINE while ( start <= end ) : NEW_LINE INDENT mid = start + ( end - start ) // 2 NEW_LINE if ( array [ mid ] == sum ) : NEW_LINE INDENT return True NEW_LINE DEDENT elif ( array [ mid ] > sum ) : NEW_LINE INDENT end = mid - 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT start = mid + 1 NEW_LINE DEDENT DEDENT return False NEW_LINE 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


class GFG { final static int MOD = 1000000007 ; static long countStrings ( int N ) { int i , j ; int dp [ ] [ ] = new int [ N + 1 ] [ 3 ] ; for ( i = 0 ; i < N + 1 ; i ++ ) { for ( j = 9 ; j < 3 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } dp [ 1 ] [ 0 ] = 1 ; dp [ 1 ] [ 1 ] = 1 ; dp [ 1 ] [ 2 ] = 0 ; for ( i = 2 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD ; dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD ; } int ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD ; return ans ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( countStrings ( N ) ) ; } }

MOD = 1000000007 NEW_LINE def countStrings ( N ) : NEW_LINE INDENT dp = [ [ 0 ] * 3 for i in range ( N + 1 ) ] NEW_LINE dp [ 1 ] [ 0 ] = 1 ; NEW_LINE dp [ 1 ] [ 1 ] = 1 ; NEW_LINE dp [ 1 ] [ 2 ] = 0 ; NEW_LINE for i in range ( 2 , N + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = ( dp [ i - 1 ] [ 0 ] + dp [ i - 1 ] [ 1 ] + dp [ i - 1 ] [ 2 ] ) % MOD NEW_LINE dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] % MOD NEW_LINE dp [ i ] [ 2 ] = dp [ i - 1 ] [ 1 ] % MOD NEW_LINE DEDENT ans = ( dp [ N ] [ 0 ] + dp [ N ] [ 1 ] + dp [ N ] [ 2 ] ) % MOD NEW_LINE return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 3 NEW_LINE print ( countStrings ( N ) ) NEW_LINE DEDENT


import java . util . * ; public class GfG { private static int findX ( int n , int k ) { int r = n , v , u ; int m = ( int ) Math . sqrt ( k ) + 1 ; for ( int i = 2 ; i <= m && k > 1 ; i ++ ) { if ( i == m ) { i = k ; } for ( u = v = 0 ; k % i == 0 ; v ++ ) { k /= i ; } if ( v > 0 ) { int t = n ; while ( t > 0 ) { t /= i ; u += t ; } r = Math . min ( r , u / v ) ; } } return r ; } public static void main ( String args [ ] ) { int n = 5 ; int k = 2 ; System . out . println ( findX ( n , k ) ) ; } }

import math NEW_LINE def findX ( n , k ) : NEW_LINE INDENT r = n NEW_LINE m = int ( math . sqrt ( k ) ) + 1 NEW_LINE i = 2 NEW_LINE while i <= m and k > 1 : NEW_LINE INDENT if ( i == m ) : NEW_LINE INDENT i = k NEW_LINE DEDENT u = 0 NEW_LINE v = 0 NEW_LINE while k % i == 0 : NEW_LINE INDENT k //= i NEW_LINE v += 1 NEW_LINE DEDENT if ( v > 0 ) : NEW_LINE INDENT t = n NEW_LINE while ( t > 0 ) : NEW_LINE INDENT t //= i NEW_LINE u += t NEW_LINE DEDENT r = min ( r , u // v ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return r NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE k = 2 NEW_LINE print ( findX ( n , k ) ) NEW_LINE DEDENT


public class GFG { static class Pair { int min ; int max ; } static Pair getMinMax ( int arr [ ] , int n ) { Pair minmax = new Pair ( ) ; int i ; if ( n % 2 == 0 ) { if ( arr [ 0 ] > arr [ 1 ] ) { minmax . max = arr [ 0 ] ; minmax . min = arr [ 1 ] ; } else { minmax . min = arr [ 0 ] ; minmax . max = arr [ 1 ] ; } i = 2 ; } else { minmax . min = arr [ 0 ] ; minmax . max = arr [ 0 ] ; i = 1 ; } while ( i < n - 1 ) { if ( arr [ i ] > arr [ i + 1 ] ) { if ( arr [ i ] > minmax . max ) { minmax . max = arr [ i ] ; } if ( arr [ i + 1 ] < minmax . min ) { minmax . min = arr [ i + 1 ] ; } } else { if ( arr [ i + 1 ] > minmax . max ) { minmax . max = arr [ i + 1 ] ; } if ( arr [ i ] < minmax . min ) { minmax . min = arr [ i ] ; } } i += 2 ; } return minmax ; } public static void main ( String args [ ] ) { int arr [ ] = { 1000 , 11 , 445 , 1 , 330 , 3000 } ; int arr_size = 6 ; Pair minmax = getMinMax ( arr , arr_size ) ; System . out . printf ( " \n Minimum ▁ element ▁ is ▁ % d " , minmax . min ) ; System . out . printf ( " \n Maximum ▁ element ▁ is ▁ % d " , minmax . max ) ; } }

def getMinMax ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT mx = max ( arr [ 0 ] , arr [ 1 ] ) NEW_LINE mn = min ( arr [ 0 ] , arr [ 1 ] ) NEW_LINE i = 2 NEW_LINE DEDENT else : NEW_LINE INDENT mx = mn = arr [ 0 ] NEW_LINE i = 1 NEW_LINE DEDENT while ( i < n - 1 ) : NEW_LINE INDENT if arr [ i ] < arr [ i + 1 ] : NEW_LINE INDENT mx = max ( mx , arr [ i + 1 ] ) NEW_LINE mn = min ( mn , arr [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT mx = max ( mx , arr [ i ] ) NEW_LINE mn = min ( mn , arr [ i + 1 ] ) NEW_LINE DEDENT i += 2 NEW_LINE DEDENT return ( mx , mn ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1000 , 11 , 445 , 1 , 330 , 3000 ] NEW_LINE mx , mn = getMinMax ( arr ) NEW_LINE print ( " Minimum ▁ element ▁ is " , mn ) NEW_LINE print ( " Maximum ▁ element ▁ is " , mx ) NEW_LINE DEDENT


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

def countNumbers ( N ) : NEW_LINE INDENT return ( pow ( 10 , N ) - pow ( 8 , N ) ) // 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 5 NEW_LINE print ( countNumbers ( n ) ) NEW_LINE DEDENT


import java . util . * ; class solution { static void sort ( String [ ] s , int n ) { for ( int i = 1 ; i < n ; i ++ ) { String temp = s [ i ] ; int j = i - 1 ; while ( j >= 0 && temp . length ( ) < s [ j ] . length ( ) ) { s [ j + 1 ] = s [ j ] ; j -- ; } s [ j + 1 ] = temp ; } } static void printArraystring ( String str [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( str [ i ] + " ▁ " ) ; } public static void main ( String args [ ] ) { String [ ] arr = { " GeeksforGeeks " , " I " , " from " , " am " } ; int n = arr . length ; sort ( arr , n ) ; printArraystring ( arr , n ) ; } }

def printArraystring ( string , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT print ( string [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT def sort ( s , n ) : NEW_LINE INDENT for i in range ( 1 , n ) : NEW_LINE INDENT temp = s [ i ] NEW_LINE j = i - 1 NEW_LINE while j >= 0 and len ( temp ) < len ( s [ j ] ) : NEW_LINE INDENT s [ j + 1 ] = s [ j ] NEW_LINE j -= 1 NEW_LINE DEDENT s [ j + 1 ] = temp NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ " GeeksforGeeks " , " I " , " from " , " am " ] NEW_LINE n = len ( arr ) NEW_LINE sort ( arr , n ) NEW_LINE printArraystring ( arr , n ) NEW_LINE DEDENT


class GFG { static int min_moves ( int n ) { int ans = Integer . MAX_VALUE ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { ans = Math . min ( ans , i + n / i - 2 ) ; } } return ans ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( min_moves ( n ) ) ; } }

import sys NEW_LINE from math import sqrt NEW_LINE def min_moves ( n ) : NEW_LINE INDENT ans = sys . maxsize ; NEW_LINE for i in range ( 1 , int ( sqrt ( n ) ) + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT ans = min ( ans , i + n // i - 2 ) ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 10 ; NEW_LINE print ( min_moves ( n ) ) ; NEW_LINE DEDENT


class Test { static void printUnique ( int l , int r ) { for ( int i = l ; i <= r ; i ++ ) { int num = i ; boolean visited [ ] = new boolean [ 10 ] ; while ( num != 0 ) { if ( visited [ num % 10 ] ) break ; visited [ num % 10 ] = true ; num = num / 10 ; } if ( num == 0 ) System . out . print ( i + " ▁ " ) ; } } public static void main ( String args [ ] ) { int l = 1 , r = 20 ; printUnique ( l , r ) ; } }

def printUnique ( l , r ) : NEW_LINE INDENT for i in range ( l , r + 1 ) : NEW_LINE INDENT num = i ; NEW_LINE visited = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ; NEW_LINE while ( num ) : NEW_LINE INDENT if visited [ num % 10 ] == 1 : NEW_LINE INDENT break ; NEW_LINE DEDENT visited [ num % 10 ] = 1 ; NEW_LINE num = ( int ) ( num / 10 ) ; NEW_LINE DEDENT if num == 0 : NEW_LINE INDENT print ( i , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT DEDENT l = 1 ; NEW_LINE r = 20 ; NEW_LINE printUnique ( l , r ) ; NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; class Getpairs { public static void findPair ( int [ ] arr , int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( Integer i : arr ) { s . add ( i ) ; } boolean found = false ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( s . contains ( sum ) ) { found = true ; System . out . println ( arr [ i ] + " ▁ " + arr [ j ] ) ; } } } if ( found == false ) System . out . println ( " Not ▁ Exist ▁ " ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 10 , 4 , 8 , 13 , 5 } ; int n = arr . length ; findPair ( arr , n ) ; } }

def findPair ( arr , n ) : NEW_LINE INDENT s = { i : 1 for i in arr } NEW_LINE found = False NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if arr [ i ] + arr [ j ] in s . keys ( ) : NEW_LINE INDENT print ( arr [ i ] , arr [ j ] ) NEW_LINE found = True NEW_LINE DEDENT DEDENT DEDENT if found == False : NEW_LINE INDENT print ( " Not ▁ exist " ) NEW_LINE DEDENT DEDENT arr = [ 10 , 4 , 8 , 13 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE findPair ( arr , n ) NEW_LINE


import java . io . * ; class GFG { static int replace ( String A , String B ) { int n = A . length ( ) , m = B . length ( ) ; int count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( i + j >= n ) break ; else if ( A . charAt ( i + j ) != B . charAt ( j ) ) break ; } if ( j == m ) { count ++ ; i += m - 1 ; } } return count ; } public static void main ( String args [ ] ) { String str1 = " aaaaaaaa " ; String str2 = " aaa " ; System . out . println ( replace ( str1 , str2 ) ) ; } }

def replace ( A , B ) : NEW_LINE INDENT n , m = len ( A ) , len ( B ) NEW_LINE count , i = 0 , 0 NEW_LINE while i < n : NEW_LINE INDENT j = 0 NEW_LINE while j < m : NEW_LINE INDENT if i + j >= n or A [ i + j ] != B [ j ] : NEW_LINE INDENT break NEW_LINE DEDENT j += 1 NEW_LINE DEDENT if j == m : NEW_LINE INDENT count += 1 NEW_LINE i += m - 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str1 = " aaaaaaaa " NEW_LINE str2 = " aaa " NEW_LINE print ( replace ( str1 , str2 ) ) NEW_LINE DEDENT


import java . util . HashSet ; import java . util . LinkedList ; import java . util . Set ; class GFG { int val ; int steps ; public GFG ( int val , int steps ) { this . val = val ; this . steps = steps ; } } public class GeeksForGeeks { private static int minOperations ( int src , int target ) { Set < GFG > visited = new HashSet < > ( 1000 ) ; LinkedList < GFG > queue = new LinkedList < GFG > ( ) ; GFG node = new GFG ( src , 0 ) ; queue . offer ( node ) ; visited . add ( node ) ; while ( ! queue . isEmpty ( ) ) { GFG temp = queue . poll ( ) ; visited . add ( temp ) ; if ( temp . val == target ) { return temp . steps ; } int mul = temp . val * 2 ; int sub = temp . val - 1 ; if ( mul > 0 && mul < 1000 ) { GFG nodeMul = new GFG ( mul , temp . steps + 1 ) ; queue . offer ( nodeMul ) ; } if ( sub > 0 && sub < 1000 ) { GFG nodeSub = new GFG ( sub , temp . steps + 1 ) ; queue . offer ( nodeSub ) ; } } return - 1 ; } public static void main ( String [ ] args ) { int x = 4 , y = 7 ; GFG src = new GFG ( x , y ) ; System . out . println ( minOperations ( x , y ) ) ; } }

import queue NEW_LINE class node : NEW_LINE INDENT def __init__ ( self , val , level ) : NEW_LINE INDENT self . val = val NEW_LINE self . level = level NEW_LINE DEDENT DEDENT def minOperations ( x , y ) : NEW_LINE INDENT visit = set ( ) NEW_LINE q = queue . Queue ( ) NEW_LINE n = node ( x , 0 ) NEW_LINE q . put ( n ) NEW_LINE while ( not q . empty ( ) ) : NEW_LINE INDENT t = q . get ( ) NEW_LINE if ( t . val == y ) : NEW_LINE INDENT return t . level NEW_LINE DEDENT visit . add ( t . val ) NEW_LINE if ( t . val * 2 == y or t . val - 1 == y ) : NEW_LINE INDENT return t . level + 1 NEW_LINE DEDENT if ( t . val * 2 not in visit ) : NEW_LINE INDENT n . val = t . val * 2 NEW_LINE n . level = t . level + 1 NEW_LINE q . put ( n ) NEW_LINE DEDENT if ( t . val - 1 >= 0 and t . val - 1 not in visit ) : NEW_LINE INDENT n . val = t . val - 1 NEW_LINE n . level = t . level + 1 NEW_LINE q . put ( n ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT x = 4 NEW_LINE y = 7 NEW_LINE print ( minOperations ( x , y ) ) NEW_LINE DEDENT


class GFG { static int getPosOfRightmostSetBit ( int n ) { return ( int ) ( ( Math . log10 ( n & - n ) ) / ( Math . log10 ( 2 ) ) ) + 1 ; } static int setRightmostUnsetBit ( int n ) { if ( n == 0 ) return 1 ; if ( ( n & ( n + 1 ) ) == 0 ) return n ; int pos = getPosOfRightmostSetBit ( ~ n ) ; return ( ( 1 << ( pos - 1 ) ) | n ) ; } public static void main ( String arg [ ] ) { int n = 21 ; System . out . print ( setRightmostUnsetBit ( n ) ) ; } }

import math NEW_LINE def getPosOfRightmostSetBit ( n ) : NEW_LINE INDENT return int ( math . log2 ( n & - n ) + 1 ) NEW_LINE DEDENT def setRightmostUnsetBit ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( ( n & ( n + 1 ) ) == 0 ) : NEW_LINE INDENT return n NEW_LINE DEDENT pos = getPosOfRightmostSetBit ( ~ n ) NEW_LINE return ( ( 1 << ( pos - 1 ) ) | n ) NEW_LINE DEDENT n = 21 NEW_LINE print ( setRightmostUnsetBit ( n ) ) NEW_LINE


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

def countWays ( n ) : NEW_LINE INDENT dp = [ 0 for i in range ( n + 1 ) ] NEW_LINE dp [ 0 ] = 0 NEW_LINE dp [ 1 ] = 1 NEW_LINE dp [ 2 ] = 1 NEW_LINE for i in range ( 3 , n + 1 ) : NEW_LINE INDENT dp [ i ] = dp [ i - 1 ] + dp [ i - 3 ] + 1 NEW_LINE DEDENT return dp [ n ] NEW_LINE DEDENT n = 6 NEW_LINE print ( countWays ( n ) ) NEW_LINE


class GFG { static int find_extra_element_index ( int [ ] arrA , int [ ] arrB ) { int extra_element = sum ( arrA ) - sum ( arrB ) ; return indexOf ( arrA , extra_element ) ; } static int sum ( int [ ] arr ) { int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; } return sum ; } static int indexOf ( int [ ] arr , int element ) { for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] == element ) { return i ; } } return - 1 ; } public static void main ( String [ ] args ) { int [ ] arrA = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int [ ] arrB = { 2 , 4 , 6 , 8 , 10 , 12 } ; System . out . println ( find_extra_element_index ( arrA , arrB ) ) ; } }

def find_extra_element_index ( arrA , arrB ) : NEW_LINE INDENT extra_element = sum ( arrA ) - sum ( arrB ) NEW_LINE return arrA . index ( extra_element ) NEW_LINE DEDENT arrA = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ] NEW_LINE arrB = [ 2 , 4 , 6 , 8 , 10 , 12 ] NEW_LINE print ( find_extra_element_index ( arrA , arrB ) ) NEW_LINE


import java . io . * ; class GFG { static int MinOperation ( int a [ ] , int n , int k ) { int result = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( a [ i ] != 1 && a [ i ] > k ) { result = result + Math . min ( a [ i ] % k , k - a [ i ] % k ) ; } else { result = result + k - a [ i ] ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 6 } ; int n = arr . length ; int k = 5 ; System . out . println ( MinOperation ( arr , n , k ) ) ; } }

def MinOperation ( a , n , k ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] != 1 and a [ i ] > k ) : NEW_LINE INDENT result = ( result + min ( a [ i ] % k , k - a [ i ] % k ) ) NEW_LINE DEDENT else : NEW_LINE INDENT result = result + k - a [ i ] NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 4 , 5 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE k = 5 NEW_LINE print ( MinOperation ( arr , n , k ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static String alphabets = " abcdefghijklmnopqrstuvwxyz " ; static void panLipogramChecker ( char [ ] s ) { for ( int i = 0 ; i < s . length ; i ++ ) { s [ i ] = Character . toLowerCase ( s [ i ] ) ; } int counter = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int pos = find ( s , alphabets . charAt ( i ) ) ; if ( pos < 0 || pos > s . length ) counter += 1 ; } if ( counter == 0 ) System . out . println ( " Pangram " ) ; else if ( counter >= 2 ) System . out . println ( " Not ▁ a ▁ pangram ▁ but ▁ might ▁ a ▁ lipogram " ) ; else System . out . println ( " Pangrammatic ▁ Lipogram " ) ; } static int find ( char [ ] arr , char c ) { for ( int i = 0 ; i < arr . length ; i ++ ) { if ( c == arr [ i ] ) return 1 ; } return - 1 ; } public static void main ( String [ ] args ) { char [ ] str = " The ▁ quick ▁ brown ▁ fox ▁ jumped ▁ over ▁ the ▁ lazy ▁ dog " . toCharArray ( ) ; panLipogramChecker ( str ) ; str = " The ▁ quick ▁ brown ▁ fox ▁ jumps ▁ over ▁ the ▁ lazy ▁ dog " . toCharArray ( ) ; panLipogramChecker ( str ) ; str = " The ▁ quick ▁ brown ▁ fox ▁ jum ▁ over ▁ the ▁ lazy ▁ dog " . toCharArray ( ) ; panLipogramChecker ( str ) ; } }

alphabets = ' abcdefghijklmnopqrstuvwxyz ' NEW_LINE def panLipogramChecker ( s ) : NEW_LINE INDENT s . lower ( ) NEW_LINE counter = 0 NEW_LINE for ch in alphabets : NEW_LINE INDENT if ( s . find ( ch ) < 0 ) : NEW_LINE INDENT counter += 1 NEW_LINE DEDENT DEDENT if ( counter == 0 ) : NEW_LINE INDENT result = " Pangram " NEW_LINE DEDENT elif ( counter == 1 ) : NEW_LINE INDENT result = " Pangrammatic ▁ Lipogram " NEW_LINE DEDENT else : NEW_LINE INDENT result = " Not ▁ a ▁ pangram ▁ but ▁ might ▁ a ▁ lipogram " NEW_LINE DEDENT return result NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT print ( panLipogramChecker ( " The quick brown fox   \ jumped over the lazy dog " ) ) NEW_LINE print ( panLipogramChecker ( " The quick brown fox   \ jumps over the lazy dog " ) ) NEW_LINE print ( panLipogramChecker ( " The quick brown fox jum \ over the lazy dog " ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT main ( ) NEW_LINE DEDENT


class GFG { static int calNum ( int year ) { return ( year / 4 ) - ( year / 100 ) + ( year / 400 ) ; } static void leapNum ( int l , int r ) { l -- ; int num1 = calNum ( r ) ; int num2 = calNum ( l ) ; System . out . print ( num1 - num2 + " \n " ) ; } public static void main ( String [ ] args ) { int l1 = 1 , r1 = 400 ; leapNum ( l1 , r1 ) ; int l2 = 400 , r2 = 2000 ; leapNum ( l2 , r2 ) ; } }

def calNum ( year ) : NEW_LINE INDENT return ( year // 4 ) - ( year // 100 ) + ( year // 400 ) ; NEW_LINE DEDENT def leapNum ( l , r ) : NEW_LINE INDENT l -= 1 ; NEW_LINE num1 = calNum ( r ) ; NEW_LINE num2 = calNum ( l ) ; NEW_LINE print ( num1 - num2 ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT l1 = 1 ; r1 = 400 ; NEW_LINE leapNum ( l1 , r1 ) ; NEW_LINE l2 = 400 ; r2 = 2000 ; NEW_LINE leapNum ( l2 , r2 ) ; NEW_LINE DEDENT


class GFG { static int log_a_to_base_b ( int a , int b ) { int rslt = ( a > b - 1 ) ? 1 + log_a_to_base_b ( a / b , b ) : 0 ; return rslt ; } public static void main ( String [ ] args ) { int a = 3 ; int b = 2 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; a = 256 ; b = 4 ; System . out . println ( log_a_to_base_b ( a , b ) ) ; } }

def log_a_to_base_b ( a , b ) : NEW_LINE INDENT rslt = ( 1 + log_a_to_base_b ( a // b , b ) ) if ( a > ( b - 1 ) ) else 0 ; NEW_LINE return rslt ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a = 3 ; NEW_LINE b = 2 ; NEW_LINE print ( log_a_to_base_b ( a , b ) ) ; NEW_LINE a = 256 ; NEW_LINE b = 4 ; NEW_LINE print ( log_a_to_base_b ( a , b ) ) ; NEW_LINE DEDENT


class GFG { static int xorOfSum ( int a [ ] , int n ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) answer ^= ( a [ i ] + a [ j ] ) ; } return answer ; } public static void main ( String [ ] args ) { int n = 3 ; int A [ ] = { 1 , 2 , 3 } ; System . out . print ( xorOfSum ( A , n ) ) ; } }

def xorOfSum ( a , n ) : NEW_LINE INDENT answer = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT answer ^= ( a [ i ] + a [ j ] ) NEW_LINE DEDENT DEDENT return answer NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE A = [ 1 , 2 , 3 ] NEW_LINE print ( xorOfSum ( A , n ) ) NEW_LINE DEDENT


import java . util . * ; import java . lang . * ; public class GfG { public static int firstDigit ( int n ) { while ( n >= 10 ) n /= 10 ; return n ; } public static int lastDigit ( int n ) { return ( n % 10 ) ; } public static void main ( String argc [ ] ) { int n = 98562 ; System . out . println ( firstDigit ( n ) + " ▁ " + lastDigit ( n ) ) ; } }

def firstDigit ( n ) : NEW_LINE INDENT while n >= 10 : NEW_LINE INDENT n = n / 10 ; NEW_LINE DEDENT return int ( n ) NEW_LINE DEDENT def lastDigit ( n ) : NEW_LINE INDENT return ( n % 10 ) NEW_LINE DEDENT n = 98562 ; NEW_LINE print ( firstDigit ( n ) , end = " ▁ " ) NEW_LINE print ( lastDigit ( n ) ) NEW_LINE


import java . io . * ; class GFG { static int N = 3 ; static int countPairs ( int a [ ] [ ] ) { int sumr [ ] = new int [ N ] ; int sumc [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) { sumr [ i ] += a [ i ] [ j ] ; sumc [ j ] += a [ i ] [ j ] ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( sumc [ i ] > sumr [ j ] ) count ++ ; return count ; } public static void main ( String [ ] args ) { int a [ ] [ ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; System . out . println ( countPairs ( a ) ) ; } }

N = 3 NEW_LINE def countPairs ( a ) : NEW_LINE INDENT sumr = [ 0 for i in range ( N ) ] NEW_LINE sumc = [ 0 for i in range ( N ) ] NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT sumr [ i ] += a [ i ] [ j ] NEW_LINE sumc [ j ] += a [ i ] [ j ] NEW_LINE DEDENT DEDENT count = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT for j in range ( N ) : NEW_LINE INDENT if ( sumc [ i ] > sumr [ j ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] NEW_LINE print ( countPairs ( a ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int anagram_pairs ( String [ ] s , int n ) { Map < String , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char [ ] chArr = s [ i ] . toCharArray ( ) ; Arrays . sort ( chArr ) ; s [ i ] = new String ( chArr ) ; if ( mp . containsKey ( s [ i ] ) ) { mp . put ( s [ i ] , mp . get ( s [ i ] ) + 1 ) ; } else { mp . put ( s [ i ] , 1 ) ; } } int ans = 0 ; for ( Map . Entry < String , Integer > i : mp . entrySet ( ) ) { int k = i . getValue ( ) ; ans += ( k * ( k - 1 ) ) / 2 ; } return ans ; } public static void main ( String [ ] args ) { String [ ] s = { " aaab " , " aaba " , " baaa " , " cde " , " dec " } ; int n = s . length ; System . out . println ( anagram_pairs ( s , n ) ) ; } }

def anagram_pairs ( s , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT temp_str = " " . join ( sorted ( s [ i ] ) ) NEW_LINE if temp_str in mp : NEW_LINE INDENT mp [ temp_str ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ temp_str ] = 1 NEW_LINE DEDENT DEDENT ans = 0 NEW_LINE for k in mp . values ( ) : NEW_LINE INDENT ans += ( k * ( k - 1 ) ) // 2 NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = [ " aaab " , " aaba " , " baaa " , " cde " , " dec " ] NEW_LINE n = len ( s ) NEW_LINE print ( anagram_pairs ( s , n ) ) NEW_LINE DEDENT


import java . util . * ; class solution { static int nthTerm ( int n ) { return ( int ) Math . pow ( n , 2 ) - 2 * n + 2 ; } public static void main ( String arr [ ] ) { int N = 4 ; System . out . println ( nthTerm ( N ) ) ; } }

from math import * NEW_LINE def nthTerm ( n ) : NEW_LINE INDENT return pow ( n , 2 ) - 2 * n + 2 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 4 NEW_LINE print ( nthTerm ( N ) ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int countSteps ( int x , int y ) { if ( x % y == 0 ) return x / y ; return x / y + countSteps ( y , x % y ) ; } public static void main ( String [ ] args ) { int x = 100 , y = 19 ; System . out . println ( countSteps ( x , y ) ) ; } }

import math NEW_LINE def countSteps ( x , y ) : NEW_LINE INDENT if ( x % y == 0 ) : NEW_LINE INDENT return math . floor ( x / y ) ; NEW_LINE DEDENT return math . floor ( ( x / y ) + countSteps ( y , x % y ) ) ; NEW_LINE DEDENT x = 100 ; NEW_LINE y = 19 ; NEW_LINE print ( countSteps ( x , y ) ) ; NEW_LINE


import java . util . * ; class GFG { public static boolean solve ( String n , int l ) { if ( l < 3 ) { if ( Integer . parseInt ( n ) % 8 == 0 ) return true ; n = new String ( ( new StringBuilder ( ) ) . append ( n ) . reverse ( ) ) ; if ( Integer . parseInt ( n ) % 8 == 0 ) return true ; return false ; } int [ ] hash = new int [ 10 ] ; for ( int i = 0 ; i < l ; i ++ ) hash [ n . charAt ( i ) - '0' ] ++ ; for ( int i = 104 ; i < 1000 ; i += 8 ) { int dup = i ; int [ ] freq = new int [ 10 ] ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = dup / 10 ; freq [ dup % 10 ] ++ ; dup = i ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; dup = dup / 10 ; if ( freq [ dup % 10 ] > hash [ dup % 10 ] ) continue ; return true ; } return false ; } public static void main ( String [ ] args ) { String number = "31462708" ; int l = number . length ( ) ; if ( solve ( number , l ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def solve ( n , l ) : NEW_LINE INDENT if l < 3 : NEW_LINE INDENT if int ( n ) % 8 == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT n = n [ : : - 1 ] NEW_LINE if int ( n ) % 8 == 0 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT hash = 10 * [ 0 ] NEW_LINE for i in range ( 0 , l ) : NEW_LINE INDENT hash [ int ( n [ i ] ) - 0 ] += 1 ; NEW_LINE DEDENT for i in range ( 104 , 1000 , 8 ) : NEW_LINE INDENT dup = i NEW_LINE freq = 10 * [ 0 ] NEW_LINE freq [ int ( dup % 10 ) ] += 1 ; NEW_LINE dup = dup / 10 NEW_LINE freq [ int ( dup % 10 ) ] += 1 ; NEW_LINE dup = dup / 10 NEW_LINE freq [ int ( dup % 10 ) ] += 1 ; NEW_LINE dup = i NEW_LINE if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT dup = dup / 10 ; NEW_LINE if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT dup = dup / 10 NEW_LINE if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT number = "31462708" NEW_LINE l = len ( number ) NEW_LINE if solve ( number , l ) : 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 search ( int ar [ ] , int size ) { int a = 0 , b = size - 1 ; int mid = 0 ; while ( ( b - a ) > 1 ) { mid = ( a + b ) / 2 ; if ( ( ar [ a ] - a ) != ( ar [ mid ] - mid ) ) b = mid ; else if ( ( ar [ b ] - b ) != ( ar [ mid ] - mid ) ) a = mid ; } return ( ar [ mid ] + 1 ) ; } public static void main ( String [ ] args ) { int ar [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 8 } ; int size = ar . length ; System . out . println ( " Missing ▁ number : ▁ " + search ( ar , size ) ) ; } }

def search ( ar , size ) : NEW_LINE INDENT a = 0 NEW_LINE b = size - 1 NEW_LINE mid = 0 NEW_LINE while b > a + 1 : NEW_LINE INDENT mid = ( a + b ) // 2 NEW_LINE if ( ar [ a ] - a ) != ( ar [ mid ] - mid ) : NEW_LINE INDENT b = mid NEW_LINE DEDENT elif ( ar [ b ] - b ) != ( ar [ mid ] - mid ) : NEW_LINE INDENT a = mid NEW_LINE DEDENT DEDENT return ar [ mid ] + 1 NEW_LINE DEDENT a = [ 1 , 2 , 3 , 4 , 5 , 6 , 8 ] NEW_LINE n = len ( a ) NEW_LINE print ( " Missing ▁ number : " , search ( a , n ) ) NEW_LINE


class Main { static int findCount ( int m , int n ) { int num1 = 0 ; for ( int i = 0 ; i < m ; i ++ ) num1 = ( num1 * 10 ) + 9 ; int num2 = 0 ; for ( int i = 0 ; i < ( m - 1 ) ; i ++ ) num2 = ( num2 * 10 ) + 9 ; return ( ( num1 / n ) - ( num2 / n ) ) ; } public static void main ( String [ ] args ) { int m = 2 , n = 6 ; System . out . println ( findCount ( m , n ) ) ; } }

def findCount ( m , n ) : NEW_LINE INDENT num1 = 0 NEW_LINE for i in range ( 0 , m ) : NEW_LINE INDENT num1 = ( num1 * 10 ) + 9 NEW_LINE DEDENT num2 = 0 NEW_LINE for i in range ( 0 , ( m - 1 ) ) : NEW_LINE INDENT num2 = ( num2 * 10 ) + 9 NEW_LINE DEDENT return int ( ( num1 / n ) - ( num2 / n ) ) NEW_LINE DEDENT m = 2 ; n = 6 NEW_LINE print ( findCount ( m , n ) ) NEW_LINE


public class GFG { static int EqualNumbers ( int a [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; if ( sum % n != 0 ) return n - 1 ; return n ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 4 , 1 } ; int n = a . length ; System . out . println ( EqualNumbers ( a , n ) ) ; } }

def EqualNumbers ( a , n ) : NEW_LINE INDENT sum = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT sum += a [ i ] ; NEW_LINE DEDENT if ( sum % n ) : NEW_LINE INDENT return n - 1 ; NEW_LINE DEDENT return n ; NEW_LINE DEDENT a = [ 1 , 4 , 1 ] ; NEW_LINE n = len ( a ) ; NEW_LINE print ( EqualNumbers ( a , n ) ) ; NEW_LINE


class GFG { static int product ( int N ) { int ans = 1 ; int val = ( int ) Math . pow ( 2 , N - 1 ) ; for ( int i = 1 ; i <= N ; i ++ ) { ans *= ( int ) Math . pow ( i , val ) ; } return ans ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . println ( product ( N ) ) ; } }

def product ( N ) : NEW_LINE INDENT ans = 1 ; NEW_LINE val = 2 ** ( N - 1 ) ; NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT ans *= ( i ** val ) ; NEW_LINE DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 2 ; NEW_LINE print ( product ( N ) ) ; NEW_LINE DEDENT


class Main { static int binarySearch ( int arr [ ] , int low , int high , int key ) { if ( high < low ) return - 1 ; int mid = ( low + high ) / 2 ; if ( key == arr [ mid ] ) return mid ; if ( key > arr [ mid ] ) return binarySearch ( arr , ( mid + 1 ) , high , key ) ; return binarySearch ( arr , low , ( mid - 1 ) , key ) ; } static int deleteElement ( int arr [ ] , int n , int key ) { int pos = binarySearch ( arr , 0 , n - 1 , key ) ; if ( pos == - 1 ) { System . out . println ( " Element ▁ not ▁ found " ) ; return n ; } int i ; for ( i = pos ; i < n - 1 ; i ++ ) arr [ i ] = arr [ i + 1 ] ; return n - 1 ; } public static void main ( String [ ] args ) { int i ; int arr [ ] = { 10 , 20 , 30 , 40 , 50 } ; int n = arr . length ; int key = 30 ; System . out . print ( " Array ▁ before ▁ deletion : \n " ) ; for ( i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; n = deleteElement ( arr , n , key ) ; System . out . print ( " \n \n Array ▁ after ▁ deletion : \n " ) ; for ( i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } }

def deleteElement ( arr , n , key ) : NEW_LINE INDENT pos = binarySearch ( arr , 0 , n - 1 , key ) NEW_LINE if ( pos == - 1 ) : NEW_LINE INDENT print ( " Element ▁ not ▁ found " ) NEW_LINE return n NEW_LINE DEDENT for i in range ( pos , n - 1 ) : NEW_LINE INDENT arr [ i ] = arr [ i + 1 ] NEW_LINE DEDENT return n - 1 NEW_LINE DEDENT def binarySearch ( arr , low , high , key ) : NEW_LINE INDENT if ( high < low ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT mid = ( low + high ) // 2 NEW_LINE if ( key == arr [ mid ] ) : NEW_LINE INDENT return mid NEW_LINE DEDENT if ( key > arr [ mid ] ) : NEW_LINE INDENT return binarySearch ( arr , ( mid + 1 ) , high , key ) NEW_LINE DEDENT return binarySearch ( arr , low , ( mid - 1 ) , key ) NEW_LINE DEDENT arr = [ 10 , 20 , 30 , 40 , 50 ] NEW_LINE n = len ( arr ) NEW_LINE key = 30 NEW_LINE print ( " Array ▁ before ▁ deletion " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT n = deleteElement ( arr , n , key ) NEW_LINE print ( " \n \n Array ▁ after ▁ deletion " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT


class Fibonacci { static boolean isMultipleOf10 ( int n ) { if ( n % 15 == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 30 ; if ( isMultipleOf10 ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

def isMultipleOf10 ( n ) : NEW_LINE INDENT return ( n % 15 == 0 ) NEW_LINE DEDENT n = 30 NEW_LINE if ( isMultipleOf10 ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT


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

def getCount ( A , B2 , C ) : NEW_LINE INDENT count = 0 NEW_LINE i = 1 NEW_LINE while ( i < A ) : NEW_LINE INDENT j = ( B2 // i ) + 1 NEW_LINE if ( C >= j ) : NEW_LINE INDENT count = count + C - j + 1 NEW_LINE DEDENT if ( A >= j and C >= i ) : NEW_LINE INDENT count = count + ( C - i + 1 ) * ( A - j + 1 ) NEW_LINE DEDENT if ( A >= j ) : NEW_LINE INDENT A = j - 1 NEW_LINE DEDENT i += 1 NEW_LINE DEDENT return count NEW_LINE DEDENT def countTriplets ( A , B , C ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , B + 1 ) : NEW_LINE INDENT ans = ( ans + getCount ( A , i * i , C ) ) NEW_LINE 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


import math NEW_LINE def print1 ( n , k ) : NEW_LINE INDENT for i in range ( 0 , n ) : NEW_LINE INDENT print ( " \n " ) NEW_LINE for j in range ( 0 , ( 3 * k + 2 ) ) : NEW_LINE INDENT if ( ( i == 0 and j != k and j != 2 * k + 1 ) or ( ( i == math . floor ( n / 2 ) ) and ( j > 1 ) and ( j != k ) and ( j != 2 * k + 1 ) and ( j != 2 * k + 3 ) ) or ( ( i == n - 1 ) and ( j != k ) and ( ( j <= k ) or ( j > 2 * k + 1 ) ) ) or ( j == 0 ) or ( j == k + 1 ) or ( j == ( 2 * k + 2 ) ) or ( ( j == k - 1 or j == 3 * k + 1 ) and ( i > math . floor ( n / 2 ) ) ) ) : NEW_LINE INDENT print ( " * " , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ▁ " , end = " " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT n = 7 NEW_LINE k = 5 NEW_LINE print1 ( n , k ) NEW_LINE


import java . util . * ; import java . lang . * ; public class GfG { public static int find ( int n , int k ) { if ( n + 1 >= k ) return ( k - 1 ) ; else return ( 2 * n + 1 - k ) ; } public static void main ( String argc [ ] ) { int n = 4 , k = 7 ; int freq = find ( n , k ) ; if ( freq < 0 ) System . out . print ( " ▁ element " + " ▁ not ▁ exist ▁ \n ▁ " ) ; else System . out . print ( " ▁ Frequency " + " ▁ of ▁ " + k + " ▁ is ▁ " + freq + " \n " ) ; } }

import math NEW_LINE def find ( n , k ) : NEW_LINE INDENT if ( n + 1 >= k ) : NEW_LINE INDENT return ( k - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( 2 * n + 1 - k ) NEW_LINE DEDENT DEDENT n = 4 NEW_LINE k = 7 NEW_LINE freq = find ( n , k ) NEW_LINE if ( freq < 0 ) : NEW_LINE INDENT print ( " ▁ element ▁ not ▁ exist " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " ▁ Frequency ▁ of ▁ " , k , " ▁ is ▁ " , freq ) NEW_LINE DEDENT


import java . util . * ; class solution { static float surfaceArea ( float a , float b , float h ) { return 5 * a * b + 5 * b * h ; } static float volume ( float b , float h ) { return ( 5 * b * h ) / 2 ; } public static void main ( String arr [ ] ) { float a = 5 ; float b = 3 ; float h = 7 ; System . out . println ( " surface ▁ area = ▁ " + surfaceArea ( a , b , h ) + " , ▁ " ) ; System . out . println ( " volume = ▁ " + volume ( b , h ) ) ; } }

def surfaceArea ( a , b , h ) : NEW_LINE INDENT return 5 * a * b + 5 * b * h NEW_LINE DEDENT def volume ( b , h ) : NEW_LINE INDENT return ( 5 * b * h ) / 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 5 NEW_LINE b = 3 NEW_LINE h = 7 NEW_LINE print ( " surface ▁ area ▁ = " , surfaceArea ( a , b , h ) , " , " , " volume ▁ = " , volume ( b , h ) ) NEW_LINE DEDENT


import java . util . HashMap ; import java . util . Map ; class GFG { static int sum ( int ar [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . put ( ar [ i ] , 0 ) ; } for ( int i = 0 ; i < n ; i ++ ) { mp . put ( ar [ i ] , mp . get ( ar [ i ] ) + 1 ) ; } int sum = 0 ; for ( Map . Entry p : mp . entrySet ( ) ) { n -= ( int ) p . getValue ( ) ; sum += n ; } return sum ; } public static void main ( String [ ] args ) { int n = 6 ; int ar [ ] = { 5 , 4 , 4 , 2 , 2 , 8 } ; int ans = sum ( ar , n ) ; System . out . println ( ans ) ; } }

def sum ( ar , n ) : NEW_LINE INDENT mp = dict ( ) NEW_LINE for i in ar : NEW_LINE INDENT if i in mp : NEW_LINE INDENT mp [ i ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT mp [ i ] = 1 NEW_LINE DEDENT DEDENT mp = sorted ( list ( mp . items ( ) ) ) NEW_LINE sum = 0 NEW_LINE for pair in mp : NEW_LINE INDENT n -= pair [ 1 ] NEW_LINE sum += n NEW_LINE DEDENT return sum NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n = 6 NEW_LINE ar = [ 5 , 4 , 4 , 2 , 2 , 8 ] NEW_LINE ans = sum ( ar , n ) NEW_LINE print ( ans ) NEW_LINE DEDENT main ( ) NEW_LINE


import java . util . * ; class Count { public static int countKdivPairs ( int A [ ] , int n , int K ) { int freq [ ] = new int [ K ] ; for ( int i = 0 ; i < n ; i ++ ) ++ freq [ A [ i ] % K ] ; int sum = freq [ 0 ] * ( freq [ 0 ] - 1 ) / 2 ; for ( int i = 1 ; i <= K / 2 && i != ( K - i ) ; i ++ ) sum += freq [ i ] * freq [ K - i ] ; if ( K % 2 == 0 ) sum += ( freq [ K / 2 ] * ( freq [ K / 2 ] - 1 ) / 2 ) ; return sum ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 2 , 1 , 7 , 5 , 3 } ; int n = 6 ; int K = 4 ; System . out . print ( countKdivPairs ( A , n , K ) ) ; } }

def countKdivPairs ( A , n , K ) : NEW_LINE INDENT freq = [ 0 ] * K NEW_LINE for i in range ( n ) : NEW_LINE INDENT freq [ A [ i ] % K ] += 1 NEW_LINE DEDENT sum = freq [ 0 ] * ( freq [ 0 ] - 1 ) / 2 ; NEW_LINE i = 1 NEW_LINE while ( i <= K // 2 and i != ( K - i ) ) : NEW_LINE INDENT sum += freq [ i ] * freq [ K - i ] NEW_LINE i += 1 NEW_LINE DEDENT if ( K % 2 == 0 ) : NEW_LINE INDENT sum += ( freq [ K // 2 ] * ( freq [ K // 2 ] - 1 ) / 2 ) ; NEW_LINE DEDENT return int ( sum ) NEW_LINE DEDENT A = [ 2 , 2 , 1 , 7 , 5 , 3 ] NEW_LINE n = len ( A ) NEW_LINE K = 4 NEW_LINE print ( countKdivPairs ( A , n , K ) ) NEW_LINE


class GFG { static int CountSetBits ( int n ) { if ( n == 0 ) return 0 ; if ( ( n & 1 ) == 1 ) return 1 + CountSetBits ( n >> 1 ) ; else return CountSetBits ( n >> 1 ) ; } public static void main ( String [ ] args ) { int n = 21 ; System . out . println ( CountSetBits ( n ) ) ; } }

def CountSetBits ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( ( n & 1 ) == 1 ) : NEW_LINE INDENT return 1 + CountSetBits ( n >> 1 ) ; NEW_LINE DEDENT else : NEW_LINE INDENT return CountSetBits ( n >> 1 ) ; NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 21 ; NEW_LINE print ( CountSetBits ( n ) ) ; NEW_LINE DEDENT


import java . util . Arrays ; class GFG { static long ProdOfPrimes ( int n ) { boolean prime [ ] = new boolean [ n + 1 ] ; Arrays . fill ( prime , 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 ; } } long prod = 1 ; for ( int i = 2 ; i <= n ; i ++ ) if ( prime [ i ] ) prod *= i ; return prod ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . print ( ProdOfPrimes ( n ) ) ; } }

def ProdOfPrimes ( n ) : NEW_LINE INDENT prime = [ True for i in range ( 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 prod = 1 NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT if ( prime [ i ] ) : NEW_LINE INDENT prod *= i NEW_LINE DEDENT DEDENT return prod NEW_LINE DEDENT n = 10 NEW_LINE print ( ProdOfPrimes ( n ) ) NEW_LINE


class GFG { static int SumOfDigits ( String str , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( int ) ( str . charAt ( i ) - '0' ) ; return sum ; } static boolean Divisible ( String str , int n ) { if ( SumOfDigits ( str , n ) % 3 == 0 && str . charAt ( n - 1 ) == '0' ) return true ; return false ; } public static void main ( String [ ] args ) { String str = "263730746028908374890" ; int n = str . length ( ) ; if ( Divisible ( str , n ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

def SumOfDigits ( str , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sum += int ( ord ( str [ i ] ) - ord ( '0' ) ) NEW_LINE DEDENT return sum NEW_LINE DEDENT def Divisible ( str , n ) : NEW_LINE INDENT if ( ( SumOfDigits ( str , n ) % 3 == 0 and str [ n - 1 ] == '0' ) ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT str = "263730746028908374890" NEW_LINE n = len ( str ) NEW_LINE if ( Divisible ( str , n ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


import java . util . * ; import java . lang . * ; class GFG { public static int sumOfSeries ( int n ) { int x ; if ( n % 2 == 0 ) x = ( n / 2 ) * ( n + 1 ) ; else x = ( ( n + 1 ) / 2 ) * n ; return x * x ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( sumOfSeries ( n ) ) ; } }

def sumOfSeries ( n ) : NEW_LINE INDENT x = 0 NEW_LINE if n % 2 == 0 : NEW_LINE INDENT x = ( n / 2 ) * ( n + 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT x = ( ( n + 1 ) / 2 ) * n NEW_LINE DEDENT return ( int ) ( x * x ) NEW_LINE DEDENT n = 5 NEW_LINE print ( sumOfSeries ( n ) ) NEW_LINE


import java . util . * ; class GFG { static int countPairs ( String s1 , int n1 , String s2 , int n2 ) { int [ ] freq1 = new int [ 26 ] ; int [ ] freq2 = new int [ 26 ] ; Arrays . fill ( freq1 , 0 ) ; Arrays . fill ( freq2 , 0 ) ; int i , count = 0 ; for ( i = 0 ; i < n1 ; i ++ ) freq1 [ s1 . charAt ( i ) - ' a ' ] ++ ; for ( i = 0 ; i < n2 ; i ++ ) freq2 [ s2 . charAt ( i ) - ' a ' ] ++ ; for ( i = 0 ; i < 26 ; i ++ ) count += ( Math . min ( freq1 [ i ] , freq2 [ i ] ) ) ; return count ; } public static void main ( String args [ ] ) { String s1 = " geeksforgeeks " , s2 = " platformforgeeks " ; int n1 = s1 . length ( ) , n2 = s2 . length ( ) ; System . out . println ( countPairs ( s1 , n1 , s2 , n2 ) ) ; } }

def countPairs ( s1 , n1 , s2 , n2 ) : NEW_LINE INDENT freq1 = [ 0 ] * 26 ; NEW_LINE freq2 = [ 0 ] * 26 ; NEW_LINE count = 0 ; NEW_LINE for i in range ( n1 ) : NEW_LINE INDENT freq1 [ ord ( s1 [ i ] ) - ord ( ' a ' ) ] += 1 ; NEW_LINE DEDENT for i in range ( n2 ) : NEW_LINE INDENT freq2 [ ord ( s2 [ i ] ) - ord ( ' a ' ) ] += 1 ; NEW_LINE DEDENT for i in range ( 26 ) : NEW_LINE INDENT count += min ( freq1 [ i ] , freq2 [ i ] ) ; NEW_LINE DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s1 = " geeksforgeeks " ; NEW_LINE s2 = " platformforgeeks " ; NEW_LINE n1 = len ( s1 ) ; NEW_LINE n2 = len ( s2 ) ; NEW_LINE print ( countPairs ( s1 , n1 , s2 , n2 ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int totalPairs ( int [ ] arr1 , int [ ] arr2 , int K , int n , int m ) { HashSet < pair > s = new HashSet < pair > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr1 [ i ] > arr2 [ j ] ) { if ( arr1 [ i ] % arr2 [ j ] == K ) s . add ( new pair ( arr1 [ i ] , arr2 [ j ] ) ) ; } else { if ( arr2 [ j ] % arr1 [ i ] == K ) s . add ( new pair ( arr2 [ j ] , arr1 [ i ] ) ) ; } } } return s . size ( ) ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 8 , 3 , 7 , 50 } ; int [ ] arr2 = { 5 , 1 , 10 , 4 } ; int K = 3 ; int n = arr1 . length ; int m = arr2 . length ; System . out . println ( totalPairs ( arr1 , arr2 , K , n , m ) ) ; } }

def totalPairs ( arr1 , arr2 , K , n , m ) : NEW_LINE INDENT s = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if ( arr1 [ i ] > arr2 [ j ] ) : NEW_LINE INDENT if ( arr1 [ i ] % arr2 [ j ] == K ) : NEW_LINE INDENT s [ ( arr1 [ i ] , arr2 [ j ] ) ] = 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT if ( arr2 [ j ] % arr1 [ i ] == K ) : NEW_LINE INDENT s [ ( arr2 [ j ] , arr1 [ i ] ) ] = 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return len ( s ) NEW_LINE DEDENT arr1 = [ 8 , 3 , 7 , 50 ] NEW_LINE arr2 = [ 5 , 1 , 10 , 4 ] NEW_LINE K = 3 NEW_LINE n = len ( arr1 ) NEW_LINE m = len ( arr2 ) NEW_LINE print ( totalPairs ( arr1 , arr2 , K , n , m ) ) NEW_LINE


import java . util . * ; class GFG { static Vector < Integer > solve ( int X , Vector < Integer > A ) { int min = Integer . MAX_VALUE ; int ind = - 1 ; for ( int i = 0 ; i < A . size ( ) ; i ++ ) { if ( A . get ( i ) < min ) { min = A . get ( i ) ; ind = i ; } } int maxIndChosen = X / min ; Vector < Integer > ans = new Vector < > ( ) ; if ( maxIndChosen == 0 ) { return ans ; } for ( int i = 0 ; i < maxIndChosen ; i ++ ) { ans . add ( ind ) ; } int temp = maxIndChosen ; int sum = maxIndChosen * A . get ( ind ) ; for ( int i = 0 ; i < ind ; i ++ ) { if ( sum - X == 0 || temp == 0 ) break ; while ( ( sum - A . get ( ind ) + A . get ( i ) ) <= X && temp != 0 ) { ans . remove ( 0 ) ; ans . add ( i ) ; temp -- ; sum += ( A . get ( i ) - A . get ( ind ) ) ; } } Collections . sort ( ans ) ; return ans ; } public static void main ( String args [ ] ) { Integer arr [ ] = { 5 , 6 , 4 , 8 } ; Vector < Integer > A = new Vector < Integer > ( Arrays . asList ( arr ) ) ; int X = 18 ; Vector < Integer > ans = solve ( X , A ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) System . out . print ( ans . get ( i ) + " ▁ " ) ; } }

import sys ; NEW_LINE def solve ( X , A ) : NEW_LINE INDENT minimum = sys . maxsize ; NEW_LINE ind = - 1 ; NEW_LINE for i in range ( len ( A ) ) : NEW_LINE INDENT if ( A [ i ] < minimum ) : NEW_LINE INDENT minimum = A [ i ] ; NEW_LINE ind = i ; NEW_LINE DEDENT DEDENT maxIndChosen = X // minimum ; NEW_LINE ans = [ ] ; NEW_LINE if ( maxIndChosen == 0 ) : NEW_LINE INDENT return ans ; NEW_LINE DEDENT for i in range ( maxIndChosen ) : NEW_LINE INDENT ans . append ( ind ) ; NEW_LINE DEDENT temp = maxIndChosen ; NEW_LINE sum = maxIndChosen * A [ ind ] ; NEW_LINE for i in range ( ind ) : NEW_LINE INDENT if ( sum - X == 0 or temp == 0 ) : NEW_LINE INDENT break ; NEW_LINE DEDENT while ( ( sum - A [ ind ] + A [ i ] ) <= X and temp != 0 ) : NEW_LINE INDENT del ( ans [ 0 ] ) ; NEW_LINE ans . append ( i ) ; NEW_LINE temp -= 1 ; NEW_LINE sum += ( A [ i ] - A [ ind ] ) ; NEW_LINE DEDENT DEDENT ans . sort ( ) ; NEW_LINE return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 5 , 6 , 4 , 8 ] ; NEW_LINE X = 18 ; NEW_LINE ans = solve ( X , A ) ; NEW_LINE for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( ans [ i ] , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT


public class GFG { static long getClosest ( int a , int b , int x ) { long num = ( long ) Math . pow ( a , b ) ; int floor = ( int ) ( num / x ) ; long numOnLeft = x * floor ; long numOnRight = x * ( floor + 1 ) ; if ( ( num - numOnLeft ) < ( numOnRight - num ) ) { return numOnLeft ; } else { return numOnRight ; } } public static void main ( String [ ] args ) { int a = 349 , b = 1 , x = 4 ; System . out . println ( getClosest ( a , b , x ) ) ; } }

def getClosest ( a , b , x ) : NEW_LINE INDENT num = pow ( a , b ) NEW_LINE floor = num // x NEW_LINE numOnLeft = x * floor NEW_LINE numOnRight = x * ( floor + 1 ) NEW_LINE if ( ( num - numOnLeft ) < ( numOnRight - num ) ) : NEW_LINE INDENT return numOnLeft NEW_LINE DEDENT else : NEW_LINE INDENT return numOnRight NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT a , b , x = 349 , 1 , 4 NEW_LINE print ( getClosest ( a , b , x ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { public static int getDistinctPoints ( int current_pos , String path ) { int len = path . length ( ) ; int points [ ] = new int [ len + 1 ] ; points [ 0 ] = current_pos ; for ( int i = 0 ; i < len ; i ++ ) { char ch = path . charAt ( i ) ; if ( ch == '0' ) { current_pos -- ; points [ i + 1 ] = current_pos ; } else { current_pos ++ ; points [ i + 1 ] = current_pos ; } } return countDistinct ( points , len + 1 ) ; } public static int countDistinct ( int arr [ ] , int len ) { HashSet < Integer > hs = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < len ; i ++ ) { hs . add ( arr [ i ] ) ; } return hs . size ( ) ; } public static void main ( String [ ] args ) { int current_pos = 5 ; String path = "011101" ; System . out . print ( getDistinctPoints ( current_pos , path ) ) ; } }

def countDistinct ( arr , Len ) : NEW_LINE INDENT hs = dict ( ) NEW_LINE for i in range ( Len ) : NEW_LINE INDENT hs [ arr [ i ] ] = 1 NEW_LINE DEDENT return len ( hs ) NEW_LINE DEDENT def getDistinctPoints ( current_pos , path ) : NEW_LINE INDENT Len = len ( path ) NEW_LINE points = [ 0 for i in range ( Len + 1 ) ] NEW_LINE points [ 0 ] = current_pos NEW_LINE for i in range ( Len ) : NEW_LINE INDENT ch = path [ i ] NEW_LINE if ( ch == '0' ) : NEW_LINE INDENT current_pos -= 1 NEW_LINE points [ i + 1 ] = current_pos NEW_LINE DEDENT else : NEW_LINE INDENT current_pos += 1 NEW_LINE points [ i + 1 ] = current_pos NEW_LINE DEDENT DEDENT return countDistinct ( points , Len + 1 ) NEW_LINE DEDENT current_pos = 5 NEW_LINE path = "011101" NEW_LINE print ( getDistinctPoints ( current_pos , path ) ) NEW_LINE


class Gfg1 { static int Log2n ( int n ) { return ( n > 1 ) ? 1 + Log2n ( n / 2 ) : 0 ; } public static void main ( String args [ ] ) { int n = 32 ; System . out . println ( Log2n ( n ) ) ; } }

def Log2n ( n ) : NEW_LINE INDENT return 1 + Log2n ( n / 2 ) if ( n > 1 ) else 0 NEW_LINE DEDENT n = 32 NEW_LINE print ( Log2n ( n ) ) NEW_LINE


import java . util . * ; class Gfg { public static int composite_factors ( int n ) { int count = 0 ; int i , j ; int [ ] a = new int [ n + 1 ] ; for ( i = 0 ; i < n ; i ++ ) { a [ i ] = 0 ; } for ( i = 1 ; i <= n ; ++ i ) { if ( n % i == 0 ) { a [ i ] = i ; } } for ( i = 2 ; i <= n ; i ++ ) { j = 2 ; int p = 1 ; while ( j < a [ i ] ) { if ( a [ i ] % j == 0 ) { p = 0 ; break ; } j ++ ; } if ( p == 0 && a [ i ] != 0 ) { count ++ ; } } return count ; } public static void main ( String [ ] args ) { int n = 100 ; System . out . println ( composite_factors ( n ) ) ; } }

def composite_factors ( n ) : NEW_LINE INDENT count = 0 ; NEW_LINE a = [ 0 ] * ( n + 1 ) ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT a [ i ] = i ; NEW_LINE DEDENT DEDENT for i in range ( 2 , n + 1 ) : NEW_LINE INDENT j = 2 ; NEW_LINE p = 1 ; NEW_LINE while ( j < a [ i ] ) : NEW_LINE INDENT if ( a [ i ] % j == 0 ) : NEW_LINE INDENT p = 0 ; NEW_LINE break ; NEW_LINE DEDENT j += 1 ; NEW_LINE DEDENT if ( p == 0 and a [ i ] != 0 ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT return count ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 100 ; NEW_LINE print ( composite_factors ( n ) ) ; NEW_LINE DEDENT


class GfG { static void findTime ( String T , int K ) { int minutes = ( ( T . charAt ( 0 ) - '0' ) * 10 + T . charAt ( 1 ) - '0' ) * 60 + ( ( T . charAt ( 3 ) - '0' ) * 10 + T . charAt ( 4 ) - '0' ) ; minutes += K ; int hour = ( minutes / 60 ) % 24 ; int min = minutes % 60 ; if ( hour < 10 ) { System . out . print ( "0" + hour + " : " ) ; } else { System . out . print ( hour + " : " ) ; } if ( min < 10 ) { System . out . println ( "0" + min ) ; } else { System . out . println ( min ) ; } } public static void main ( String [ ] args ) { String T = "21:39" ; int K = 43 ; findTime ( T , K ) ; } }

def findTime ( T , K ) : NEW_LINE INDENT minutes = ( ( ( ord ( T [ 0 ] ) - ord ( '0' ) ) * 10 + ord ( T [ 1 ] ) - ord ( '0' ) ) * 60 + ( ( ord ( T [ 3 ] ) - ord ( '0' ) ) * 10 + ord ( T [ 4 ] ) - ord ( '0' ) ) ) ; NEW_LINE minutes += K NEW_LINE hour = ( int ( minutes / 60 ) ) % 24 NEW_LINE min = minutes % 60 NEW_LINE if ( hour < 10 ) : NEW_LINE INDENT print ( 0 , hour , " : " , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( hour , " : " , end = " ▁ " ) NEW_LINE DEDENT if ( min < 10 ) : NEW_LINE INDENT print ( 0 , min , end = " ▁ " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( min , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT T = "21:39" NEW_LINE K = 43 NEW_LINE findTime ( T , K ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int highestPowerof2 ( int n ) { int p = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ; return ( int ) Math . pow ( 2 , p ) ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( highestPowerof2 ( n ) ) ; } }

import math NEW_LINE def highestPowerof2 ( n ) : NEW_LINE INDENT p = int ( math . log ( n , 2 ) ) ; NEW_LINE return int ( pow ( 2 , p ) ) ; NEW_LINE DEDENT n = 10 ; NEW_LINE print ( highestPowerof2 ( n ) ) ; NEW_LINE


import java . math . * ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; if ( b == 0 ) return a ; if ( a == b ) return a ; if ( a > b ) return gcd ( a - b , b ) ; return gcd ( a , b - a ) ; } static int LCM ( int x , int y , int z ) { int ans = ( ( x * y ) / ( gcd ( x , y ) ) ) ; return ( ( z * ans ) / ( gcd ( ans , z ) ) ) ; } static int findDivisible ( int n , int x , int y , int z ) { int lcm = LCM ( x , y , z ) ; int largestNDigitNum = ( int ) Math . pow ( 10 , n ) - 1 ; int remainder = largestNDigitNum % lcm ; if ( remainder == 0 ) return largestNDigitNum ; largestNDigitNum -= remainder ; if ( largestNDigitNum >= ( int ) Math . pow ( 10 , n - 1 ) ) return largestNDigitNum ; else return 0 ; } public static void main ( String args [ ] ) { int n = 2 , x = 3 , y = 4 , z = 6 ; int res = findDivisible ( n , x , y , z ) ; if ( res != 0 ) System . out . println ( res ) ; else System . out . println ( " Not ▁ possible " ) ; } }

def gcd ( a , b ) : NEW_LINE INDENT if ( a == 0 ) : NEW_LINE INDENT return b ; NEW_LINE DEDENT if ( b == 0 ) : NEW_LINE INDENT return a ; 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 LCM ( x , y , z ) : NEW_LINE INDENT ans = ( ( x * y ) / ( gcd ( x , y ) ) ) ; NEW_LINE return ( ( z * ans ) / ( gcd ( ans , z ) ) ) ; NEW_LINE DEDENT def findDivisible ( n , x , y , z ) : NEW_LINE INDENT lcm = LCM ( x , y , z ) ; NEW_LINE largestNDigitNum = int ( pow ( 10 , n ) ) - 1 ; NEW_LINE remainder = largestNDigitNum % lcm ; NEW_LINE if ( remainder == 0 ) : NEW_LINE INDENT return largestNDigitNum ; NEW_LINE DEDENT largestNDigitNum -= remainder ; NEW_LINE if ( largestNDigitNum >= int ( pow ( 10 , n - 1 ) ) ) : NEW_LINE INDENT return largestNDigitNum ; NEW_LINE DEDENT else : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT DEDENT n = 2 ; x = 3 ; NEW_LINE y = 4 ; z = 6 ; NEW_LINE res = int ( findDivisible ( n , x , y , z ) ) ; NEW_LINE if ( res != 0 ) : NEW_LINE INDENT print ( res ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ possible " ) ; NEW_LINE DEDENT


class MaxevenSum { static int maxEvenSum ( int arr [ ] , int n ) { int pos_sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) if ( arr [ i ] > 0 ) pos_sum += arr [ i ] ; if ( pos_sum % 2 == 0 ) return pos_sum ; int ans = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; ++ i ) { if ( arr [ i ] % 2 != 0 ) { if ( arr [ i ] > 0 ) ans = ans > ( pos_sum - arr [ i ] ) ? ans : ( pos_sum - arr [ i ] ) ; else ans = ans > ( pos_sum + arr [ i ] ) ? ans : ( pos_sum + arr [ i ] ) ; } } return ans ; } public static void main ( String s [ ] ) { int a [ ] = { - 2 , 2 , - 3 , 1 } ; System . out . println ( maxEvenSum ( a , a . length ) ) ; } }

INT_MIN = - 100000000 NEW_LINE def maxEvenSum ( arr , n ) : NEW_LINE INDENT pos_sum = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT pos_sum += arr [ i ] NEW_LINE DEDENT DEDENT if ( pos_sum % 2 == 0 ) : NEW_LINE INDENT return pos_sum NEW_LINE DEDENT ans = INT_MIN ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] % 2 != 0 ) : NEW_LINE INDENT if ( arr [ i ] > 0 ) : NEW_LINE INDENT ans = max ( ans , pos_sum - arr [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT ans = max ( ans , pos_sum + arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT return ans NEW_LINE DEDENT a = [ - 2 , 2 , - 3 , 1 ] NEW_LINE n = len ( a ) NEW_LINE print ( maxEvenSum ( a , n ) ) NEW_LINE


import java . io . * ; public class GFG { static int MAX_CHAR = 26 ; static boolean distributingBalls ( long k , long n , String str ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ str . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( a [ i ] > k ) return false ; return true ; } static public void main ( String [ ] args ) { long n = 6 , k = 3 ; String str = " aacaab " ; if ( distributingBalls ( k , n , str ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

MAX_CHAR = 26 NEW_LINE def distributingBalls ( k , n , string ) : NEW_LINE INDENT a = [ 0 ] * MAX_CHAR NEW_LINE for i in range ( n ) : NEW_LINE INDENT a [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1 NEW_LINE DEDENT for i in range ( MAX_CHAR ) : NEW_LINE INDENT if ( a [ i ] > k ) : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n , k = 6 , 3 NEW_LINE string = " aacaab " NEW_LINE if ( distributingBalls ( k , n , string ) ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT DEDENT


class GFG { static long factorial ( long n ) { long res = 1 ; for ( int i = 1 ; i <= n ; i ++ ) res = res * i ; return res ; } static long count ( String word ) { int freq [ ] = new int [ 27 ] ; for ( int i = 0 ; i < 27 ; i ++ ) freq [ i ] = 0 ; long vowel = 0 , consonant = 0 ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) { freq [ word . charAt ( i ) - ' A ' ] ++ ; if ( word . charAt ( i ) == ' A ' || word . charAt ( i ) == ' E ' || word . charAt ( i ) == ' I ' || word . charAt ( i ) == ' O ' || word . charAt ( i ) == ' U ' ) { vowel ++ ; } else consonant ++ ; } long vowelArrange ; vowelArrange = factorial ( vowel ) ; vowelArrange /= factorial ( freq [ 0 ] ) ; vowelArrange /= factorial ( freq [ 4 ] ) ; vowelArrange /= factorial ( freq [ 8 ] ) ; vowelArrange /= factorial ( freq [ 14 ] ) ; vowelArrange /= factorial ( freq [ 20 ] ) ; long consonantArrange ; consonantArrange = factorial ( consonant ) ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( i != 0 && i != 4 && i != 8 && i != 14 && i != 20 ) consonantArrange /= factorial ( freq [ i ] ) ; } long total = vowelArrange * consonantArrange ; return total ; } public static void main ( String [ ] args ) { String word = " COMPUTER " ; long ans = count ( word ) ; System . out . println ( ans ) ; } }

def factorial ( n ) : NEW_LINE INDENT res = 1 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT res = res * i NEW_LINE DEDENT return res NEW_LINE DEDENT def count ( word ) : NEW_LINE INDENT freq = [ 0 for i in range ( 30 ) ] NEW_LINE vowel = 0 NEW_LINE consonant = 0 NEW_LINE for i in range ( len ( word ) ) : NEW_LINE INDENT freq [ ord ( word [ i ] ) - 65 ] += 1 NEW_LINE if ( word [ i ] == ' A ' or word [ i ] == ' E ' or word [ i ] == ' I ' or word [ i ] == ' O ' or word [ i ] == ' U ' ) : NEW_LINE INDENT vowel += 1 NEW_LINE DEDENT else : NEW_LINE INDENT consonant += 1 NEW_LINE DEDENT DEDENT vowelArrange = factorial ( vowel ) NEW_LINE vowelArrange //= factorial ( freq [ 0 ] ) NEW_LINE vowelArrange //= factorial ( freq [ 4 ] ) NEW_LINE vowelArrange //= factorial ( freq [ 8 ] ) NEW_LINE vowelArrange //= factorial ( freq [ 14 ] ) NEW_LINE vowelArrange //= factorial ( freq [ 20 ] ) NEW_LINE consonantArrange = factorial ( consonant ) NEW_LINE for i in range ( 26 ) : NEW_LINE INDENT if ( i != 0 and i != 4 and i != 8 and i != 14 and i != 20 ) : NEW_LINE INDENT consonantArrange //= factorial ( freq [ i ] ) NEW_LINE DEDENT DEDENT total = vowelArrange * consonantArrange NEW_LINE return total NEW_LINE DEDENT word = " COMPUTER " NEW_LINE ans = count ( word ) NEW_LINE print ( ans ) NEW_LINE


public class GFG { static final int MAX = 50 ; static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) { if ( low == high ) { return a [ low ] * turn ; } if ( dp [ low ] [ high ] != 0 ) { return dp [ low ] [ high ] ; } dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ; return dp [ low ] [ high ] ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 1 , 5 , 2 } ; int n = arr . length ; int dp [ ] [ ] = new int [ MAX ] [ MAX ] ; System . out . println ( solve ( dp , arr , 0 , n - 1 , 1 ) ) ; } }

MAX = 50 NEW_LINE def solve ( dp , a , low , high , turn ) : NEW_LINE INDENT if ( low == high ) : NEW_LINE INDENT return a [ low ] * turn NEW_LINE DEDENT if ( dp [ low ] [ high ] != 0 ) : NEW_LINE INDENT return dp [ low ] [ high ] NEW_LINE DEDENT dp [ low ] [ high ] = max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ; NEW_LINE return dp [ low ] [ high ] NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 3 , 1 , 5 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE dp = [ [ 0 for x in range ( MAX ) ] for y in range ( MAX ) ] NEW_LINE print ( solve ( dp , arr , 0 , n - 1 , 1 ) ) NEW_LINE DEDENT