import java . io . * ; import java . util . * ;   import static java . lang . Math . * ;   public class Task { public static void main ( String [ ] args ) throws IOException { Reader reader = new Reader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ;   int n = reader . nextInt ( ) ; int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { arr [ i ] = reader . nextInt ( ) ; }   int sum = 0 ; for ( int i = 0 ; i < n ; ++ i ) { sum += arr [ i ] ; }   if ( sum == 0 ) { int sum1 = 0 ; int i = 0 ; while ( i < n ) { sum1 += arr [ i ] ; ++ i ; if ( sum1 != 0 ) { break ; } }   if ( i == n ) { out . println ( " NO " ) ; } else { out . println ( " YES " ) ; out . println ( 2 ) ; out . println ( String . format ( " % d ▁ % d " , 1 , i ) ) ; out . println ( String . format ( " % d ▁ % d " , i + 1 , n ) ) ; } } else { out . println ( " YES " ) ; out . println ( 1 ) ; out . println ( String . format ( " % d ▁ % d " , 1 , n ) ) ; }   reader . close ( ) ; out . close ( ) ; } }   class Reader { private BufferedReader bufferedReader ; private StringTokenizer tokenizer ;   public Reader ( ) { bufferedReader = new BufferedReader ( new InputStreamReader ( System . in ) , 32786 ) ; }   public void close ( ) throws IOException { bufferedReader . close ( ) ; }   public String next ( ) throws IOException { while ( tokenizer == null || ! tokenizer . hasMoreTokens ( ) ) { tokenizer = new StringTokenizer ( bufferedReader . readLine ( ) ) ; }   return tokenizer . nextToken ( ) ; }   public int nextInt ( ) throws IOException { return Integer . parseInt ( next ( ) ) ; }   public long nextLong ( ) throws IOException { return Long . parseLong ( next ( ) ) ; } }

import java . io . * ; import java . util . * ;   public class Leshaandarraysplitting { public static void main ( String args [ ] ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int a [ ] = new int [ n ] ; int sum = 0 ; int allZero = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = in . nextInt ( ) ; if ( a [ i ] != 0 ) allZero = 1 ; sum += a [ i ] ; } if ( sum == 0 && allZero == 1 ) { System . out . println ( " YES " ) ; System . out . println ( 2 ) ; int k = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += a [ i ] ; if ( sum != 0 ) { k = i + 1 ; break ; } } System . out . println ( "1 ▁ " + k ) ; System . out . println ( ( k + 1 ) + " ▁ " + n ) ;   } else if ( allZero == 1 ) { System . out . println ( " YES " ) ; System . out . println ( 1 ) ; System . out . println ( "1 ▁ " + n ) ; } else { System . out . println ( " NO " ) ; }   } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . Arrays ; import java . util . StringTokenizer ;   public class test { public static void main ( String ... args ) throws NumberFormatException , IOException { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; int n = Integer . parseInt ( br . readLine ( ) ) ; int [ ] a = new int [ n + 1 ] ; int [ ] sum = new int [ n + 1 ] ; StringTokenizer st = new StringTokenizer ( br . readLine ( ) ) ; for ( int i = 1 ; i <= n ; i ++ ) { a [ i ] = Integer . parseInt ( st . nextToken ( ) ) ; sum [ i ] = sum [ i - 1 ] + a [ i ] ; } boolean [ ] boundary = new boolean [ n + 1 ] ; int l = 1 ; int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( sum [ i ] - sum [ l - 1 ] == 0 ) { continue ; } else { int j = i + 1 ; while ( j <= n && a [ j ] == 0 ) { j ++ ; } i = j - 1 ; boundary [ i ] = true ; l = i + 1 ; count ++ ; } } if ( ! boundary [ n ] ) { System . out . println ( " NO " ) ; } else { System . out . println ( " YES " ) ; System . out . println ( count ) ; int left = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( boundary [ i ] ) { System . out . println ( left + " ▁ " + i ) ; left = i + 1 ; } } } } }

import java . util . Scanner ; public class Main { public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ; int n = scan . nextInt ( ) ; int [ ] a = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = scan . nextInt ( ) ; sum += a [ i ] ; } if ( sum != 0 ) { System . out . println ( " YES \n " + 1 + " \n " + 1 + " ▁ " + n ) ; } else if ( n == 1 ) System . out . println ( " NO " ) ; else { int summ = 0 ; int j ; for ( j = 0 ; j < n ; j ++ ) { summ += a [ j ] ; if ( summ != 0 ) break ; } if ( j == n ) System . out . println ( " NO " ) ; else System . out . println ( " YES \n " + 2 + " \n " + 1 + " ▁ " + ( j + 1 ) + " \n " + ( j + 2 ) + " ▁ " + n ) ; } } }

n = int ( input ( ) )   a = [ int ( b ) for b in input ( ) . split ( ) ]   ans = 0 indexes = [ ]   if len ( set ( a ) ) == 1 and a [ 0 ] == 0 : print ( " NO " ) exit ( )   if sum ( a ) != 0 : print ( " YES " ) print ( 1 ) print ( 1 , n ) exit ( )   for i in range ( n ) : if a [ i ] != 0 : indexes . append ( i )   print ( " YES " ) print ( 2 ) print ( 1 , indexes [ 0 ] + 1 ) print ( indexes [ 0 ] + 2 , n )   NEW_LINE

import sys , mathn = int ( input ( ) ) array = list ( map ( int , input ( ) . split ( ) ) ) if array . count ( 0 ) == n : print ( ' NO ' ) sys . exit ( ) if sum ( array ) == 0 : print ( ' YES ' ) print ( 2 ) i = 1 while sum ( array [ 0 : i ] ) == 0 or sum ( array [ i : ] ) == 0 : i += 1 print ( 1 , i ) print ( i + 1 , n ) else : print ( ' YES ' ) print ( 1 ) print ( 1 , n ) NEW_LINE

n = int ( input ( ) ) lst = list ( map ( int , input ( ) . strip ( ) . split ( ' ▁ ' ) ) ) if sum ( lst ) != 0 : print ( ' YES ' ) print ( 1 ) print ( 1 , n , end = " ▁ " ) elif lst . count ( 0 ) == n : print ( ' NO ' ) elif lst . count ( 0 ) == 0 : print ( ' YES ' ) print ( n ) for j in range ( n ) : print ( j + 1 , j + 1 , end = " ▁ " ) print ( ) else : print ( ' YES ' ) print ( 2 ) for j in range ( n ) : if sum ( lst [ : j ] ) != 0 and sum ( lst [ j : ] ) != 0 : print ( 1 , j , end = " ▁ " ) print ( ) print ( j + 1 , n , end = " ▁ " ) print ( ) break NEW_LINE

import mathn = int ( input ( ) ) p = list ( map ( int , input ( ) . split ( ) ) ) sm = 0 pos = - 1 for i in range ( n ) : sm += p [ i ] p [ i ] = smif p [ n - 1 ] != 0 : print ( " YES " ) print ( "1" ) print ( "1" , n ) else : for i in range ( n - 1 ) : if abs ( p [ i ] - p [ n - 1 ] ) != 0 : pos = i break if pos == - 1 : print ( " NO " ) else : print ( " YES " ) print ( "2" ) print ( "1" , ( pos + 1 ) ) print ( ( pos + 2 ) , n )                   NEW_LINE


import java . util . * ; import java . lang . * ; import java . io . * ; public class Codechef { public static void main ( String [ ] args ) throws java . lang . Exception { Scanner sc = new Scanner ( System . in ) ; int l = 0 , n = 0 , r = 0 , i = 0 , f = 0 ; if ( sc . hasNext ( ) ) l = sc . nextInt ( ) ; if ( sc . hasNext ( ) ) n = sc . nextInt ( ) ; if ( sc . hasNext ( ) ) r = sc . nextInt ( ) ; if ( l >= 3 && l <= 100 && n >= 1 && n <= l && r >= 1 && r <= l ) { if ( n - r > 1 ) { f = n - r ; System . out . print ( " < < " + " ▁ " ) ; } else { f = 1 ; } for ( i = f ; i <= n + r ; i ++ ) { if ( i == n ) System . out . print ( " ( " + i + " ) " + " ▁ " ) ; else if ( i <= l ) System . out . print ( i + " ▁ " ) ; } if ( n + r < l ) System . out . print ( " > > " ) ; } } }

import java . util . Scanner ;   public class Pages { public static void main ( String [ ] args ) { new Pages ( ) . run ( ) ; }   private void run ( ) { Scanner sc = new Scanner ( System . in ) ; int n = sc . nextInt ( ) ; int p = sc . nextInt ( ) ; int d = sc . nextInt ( ) ;   if ( p - d > 1 ) { System . out . print ( " < < ▁ " ) ; int i = p - d ; while ( i < p ) { System . out . print ( i + " ▁ " ) ; i ++ ; } } else if ( p - d <= 1 ) { int i = 1 ; while ( i < p ) { System . out . print ( i + " ▁ " ) ; i ++ ; } } System . out . print ( " ( " + p + " ) ▁ " ) ;   if ( p + d < n ) { int i = p + 1 ; while ( i <= p + d ) { System . out . print ( i + " ▁ " ) ; i ++ ; } System . out . print ( " > > " ) ; } else if ( p + d >= n ) { int i = p + 1 ; while ( i <= n ) { System . out . print ( i + " ▁ " ) ; i ++ ; } }    } }

import java . io . * ; import java . util . * ;   public class pages { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int p = in . nextInt ( ) ; int k = in . nextInt ( ) ; String res = " " ; if ( p - k > 1 ) res += " < < ▁ " ; for ( int i = p - k ; i <= p + k ; i ++ ) { if ( i > n ) break ; else if ( i < 1 ) continue ; else if ( i == p ) { res += " ( " + i + " ) ▁ " ; } else { res += i + " ▁ " ; } } if ( p + k < n ) { res += " > > " ; } System . out . println ( res ) ; } }

import java . util . Scanner ;   public class A_Pages {   public static void main ( String [ ] args ) { Scanner scan = new Scanner ( System . in ) ;   int n = scan . nextInt ( ) ; int p = scan . nextInt ( ) ; int k = scan . nextInt ( ) ; if ( p < 1 || p > n ) return ; int head = p - k < 1 ? 1 : p - k ; int tail = p + k > n ? n : p + k ;   if ( p - k > 1 ) System . out . printf ( " < < " ) ; for ( int i = head ; i <= tail ; i ++ ) { if ( i == p ) { System . out . printf ( " ▁ ( % d ) ▁ " , i ) ; } else { System . out . print ( " ▁ " + i + " ▁ " ) ; } } if ( p + k < n ) System . out . printf ( " > > " ) ; scan . close ( ) ; }   }

import java . util . Scanner ;    public class Main {   public static void main ( String [ ] args ) {

n , p , k = list ( map ( int , input ( ) . split ( ' ▁ ' ) ) )   NEW_LINE

n , p , k = map ( int , input ( ) . split ( ) ) a = " " sum = 0   if ( p - k != 1 and p - k > 0 ) : a = a + " < < " i = 0 while ( sum != p ) : r = p + i - k sum = r i = i + 1 if ( sum < 1 ) : continue if ( sum == p ) : a = a + " ▁ " + " ( " + str ( p ) + " ) " break else : a = a + " ▁ " + str ( sum ) i = i - 2 while ( sum != p + k ) : if ( sum == n ) : break sum = p + k - i i = i - 1 a = a + " ▁ " + str ( sum ) if ( p + k < n ) : a = a + " ▁ " + " > > " print ( a ) NEW_LINE

n , p , k = map ( int , input ( ) . split ( ) ) x = 0 close_symbol = Truepages = " " if ( ( p - k ) > 1 ) : pages += " < < ▁ "   if ( k <= p ) : for x in range ( k ) : if ( p - k + x == 0 ) : continue NEW_LINE

import sysfrom functools import reducefrom collections import Counterimport timeimport datetimefrom math import sqrt , gcd   NEW_LINE

from sys import stdoutwrite = stdout . write   n , p , k = map ( int , input ( ) . split ( ) ) if p - k > 1 : write ( ' < < ▁ ' ) for i in range ( p - k , p + k + 1 ) : if 1 <= i <= n : write ( f ' { i } ▁ ' if i != p else f ' ( { i } ) ▁ ' ) if p + k < n : print ( ' > > ' ) else : print ( ) NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class Main { static class RealScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ;   String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } }   public static void main ( String [ ] args ) { RealScanner sc = new RealScanner ( ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) { count ++ ; } else { System . out . print ( count ) ; count = 0 ; } } System . out . print ( count ) ; } }

import java . util . * ; import java . io . * ;   public class Main { public static void main ( String [ ] args ) throws IOException { FastScanner in = new FastScanner ( System . in ) ; PrintWriter out = new PrintWriter ( System . out ) ; new Main ( ) . run ( in , out ) ; out . close ( ) ; }   public static long mod = 17352642619633L ;   void run ( FastScanner in , PrintWriter out ) { int N = in . nextInt ( ) ; char [ ] ca = in . next ( ) . toCharArray ( ) ;   int ret = 0 ; for ( int i = 0 ; i < N ; ) { int len = 0 ; while ( i < N && ca [ i ] == '1' ) { len ++ ; i ++ ; } ret = ret * 10 + len ; i ++ ; } if ( ca [ N - 1 ] == '0' ) ret *= 10 ; out . println ( ret ) ;    }   static class FastScanner { BufferedReader br ; StringTokenizer st ;   public FastScanner ( InputStream in ) { br = new BufferedReader ( new InputStreamReader ( in ) ) ; st = null ; }   String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } } }

import java . util . Scanner ;   public class nk { public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; String s = in . next ( ) + " [ " ; int cur = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) { cur ++ ; } else { print ( cur ) ; for ( int j = i + 1 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) == '0' ) { print ( '0' ) ; i ++ ; } else { break ; } } cur = 0 ; } } } public static void print ( Object ob ) { System . out . print ( ob ) ; } public static void println ( ) { print ( ' \n ' ) ; } public static void println ( Object ob ) { print ( ob ) ; println ( ) ; } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . StringTokenizer ;   public class Binary_Protocol { static class RealScanner { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; StringTokenizer st = new StringTokenizer ( " " ) ;   String next ( ) { while ( ! st . hasMoreTokens ( ) ) try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   int [ ] readArray ( int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) a [ i ] = nextInt ( ) ; return a ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } }   public static void main ( String [ ] args ) { RealScanner sc = new RealScanner ( ) ; int n = sc . nextInt ( ) ; String s = sc . next ( ) ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '1' ) { count ++ ; } else { System . out . print ( count ) ; count = 0 ; } } System . out . print ( count ) ; } }

t = int ( input ( ) ) n = input ( )   p = n . split ( "0" )   for i in range ( len ( p ) ) : print ( len ( p [ i ] ) , end = " " ) NEW_LINE

input ( )   s = input ( ) . split ( '0' ) for i in s : print ( len ( i ) , end = ' ' ) NEW_LINE

input ( ) s = input ( ) . split ( '0' ) message = ' ' for word in s : message = message + str ( len ( word ) ) print ( message ) NEW_LINE

n = int ( input ( ) ) s = input ( ) z = cur = 0 res = [ ]   for i in range ( n ) : if s [ i ] == '0' and i != n - 1 : z += 1 if cur : res . append ( str ( cur ) ) ; cur = 0 ; elif ( s [ i ] == '1' and i == n - 1 ) : if z >= 2 : for i in range ( z - 1 ) : res . append ( '0' ) z = 0 res . append ( str ( cur + 1 ) ) elif ( s [ i ] == '0' and i == n - 1 ) : if cur : res . append ( str ( cur ) ) ; cur = 0 ; z += 1 for i in range ( z ) : res . append ( '0' ) else : cur += 1 if z >= 2 : for i in range ( z - 1 ) : res . append ( '0' ) z = 0 print ( ' ' . join ( res ) ) NEW_LINE


import java . util . * ; import java . io . * ;     public class A {    public static void main ( String [ ] args ) throws IOException { FastReader sc = new FastReader ( ) ; PrintWriter out = new PrintWriter ( System . out ) ;   int n = sc . nextInt ( ) , m = sc . nextInt ( ) ; int [ ] diff = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { String str = sc . next ( ) ; int s = str . indexOf ( ' S ' ) ; int g = str . indexOf ( ' G ' ) ; if ( s < g ) { out . println ( - 1 ) ; out . close ( ) ; return ; }   diff [ i ] = s - g ; } Arrays . sort ( diff ) ; int count = 0 ; while ( true ) { int min = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( diff [ i ] != 0 ) { min = diff [ i ] ; break ; } } if ( min == 0 ) break ;   for ( int i = 0 ; i < n ; i ++ ) diff [ i ] = Math . max ( 0 , diff [ i ] - min ) ;   count ++ ;   }   out . println ( count ) ; out . close ( ) ; }   }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . HashSet ; import java . util . Set ; import java . util . StringTokenizer ;   public class InnaAndNewMatrixOfCandies { public static void main ( String [ ] args ) { FastReader fs = new FastReader ( ) ; StringBuilder sb = new StringBuilder ( ) ; Set < Integer > set = new HashSet < > ( ) ; int n = fs . nextInt ( ) ; int m = fs . nextInt ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = fs . next ( ) ; int sweet = - 1 ; int dwarf = - 1 ; for ( int j = 0 ; j < m ; j ++ ) { if ( s . charAt ( j ) == ' G ' ) dwarf = j ; else if ( s . charAt ( j ) == ' S ' ) sweet = j ; } if ( sweet - dwarf < 0 ) { System . out . println ( - 1 ) ; return ; } else set . add ( sweet - dwarf ) ; } System . out . println ( set . size ( ) ) ; }   static class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; }   String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; }   int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   long nextLong ( ) { return Long . parseLong ( next ( ) ) ; }   double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; }   float nextFloat ( ) { return Float . parseFloat ( next ( ) ) ; } } }

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class Main {   public static void main ( String args [ ] ) throws Exception {   Solve instance = new Solve ( ) ; instance . solve ( ) ; }   }    class Solve { FastReader sc ; String s [ ] ; int n ; int m ; HashSet < Integer > set = new HashSet < > ( ) ; public Solve ( ) { sc = new FastReader ( ) ; } private void input ( ) { n = sc . nextInt ( ) ; m = sc . nextInt ( ) ; s = new String [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { s [ i ] = sc . next ( ) ; } } public void solve ( ) { input ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( s [ i ] . indexOf ( ' S ' ) - s [ i ] . indexOf ( ' G ' ) ) < 0 ) { System . out . println ( " - 1" ) ; System . exit ( 0 ) ; } else { set . add ( ( s [ i ] . indexOf ( ' S ' ) - s [ i ] . indexOf ( ' G ' ) ) ) ; } } System . out . println ( set . size ( ) ) ; } }      class FastReader { BufferedReader br ; StringTokenizer st ; public FastReader ( ) { br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; } String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; } int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; } long nextLong ( ) { return Long . parseLong ( next ( ) ) ; } double nextDouble ( ) { return Double . parseDouble ( next ( ) ) ; } String nextLine ( ) { String str = " " ; try { str = br . readLine ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } return str ; } }

import java . util . * ;   public class Main {   public static void main ( String [ ] args ) { Scanner in = new Scanner ( System . in ) ; int n = in . nextInt ( ) ; int m = in . nextInt ( ) ; Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String str = in . next ( ) ; int sIndex = 0 ; int gIndex = 0 ; for ( int j = 0 ; j < m ; j ++ ) { if ( str . charAt ( j ) == ' G ' ) gIndex = j ; else if ( str . charAt ( j ) == ' S ' ) sIndex = j ; } if ( sIndex - gIndex > 0 ) set . add ( sIndex - gIndex ) ; else { System . out . println ( - 1 ) ; System . exit ( 0 ) ; } }   System . out . println ( set . size ( ) ) ; in . close ( ) ;   } }

n , m = map ( int , input ( ) . split ( ) ) l = [ ] for i in range ( n ) : l . append ( input ( ) ) l1 , l2 , ansl = [ ] , [ ] , [ ] for i in range ( n ) : l1 . append ( l [ i ] . index ( ' G ' ) ) l2 . append ( l [ i ] . index ( ' S ' ) ) ans = - 1 for i in range ( n ) : if l1 [ i ] < l2 [ i ] : ansl . append ( l2 [ i ] - l1 [ i ] - 1 ) ans = max ( ans , l2 [ i ] - l1 [ i ] - 1 ) elif l1 [ i ] > l2 [ i ] : ansl . append ( - 1 ) if - 1 in ansl : print ( - 1 ) else : print ( len ( set ( ansl ) ) ) NEW_LINE

distance = lambda x : ( x . find ( ' S ' ) - x . find ( ' G ' ) ) def main ( ) : n , m = map ( int , input ( ) . split ( ) ) s = { distance ( input ( ) ) for i in range ( n ) } if min ( s ) < 0 : print ( - 1 ) else : print ( len ( s ) ) main ( ) NEW_LINE

n , m = [ int ( i ) for i in input ( ) . split ( ) ] mini = 0 flag = 0 dist = [ ] for i in range ( n ) : l = list ( input ( ) ) S = l . index ( " S " ) G = l . index ( " G " ) if G > S : flag = 1 else : dist . append ( S - G )     if flag == 1 : print ( - 1 ) else : print ( len ( set ( dist ) ) )     NEW_LINE

n , m = [ int ( y ) for y in input ( ) . split ( ) ] a = set ( ) found = Falsefor _ in range ( n ) : s = input ( ) for i in range ( m ) : if s [ i ] == ' G ' : g = i if s [ i ] == ' S ' : c = i if c < g : print ( - 1 ) found = True break else : a . add ( c - g ) if not found : print ( len ( a ) ) NEW_LINE

n , m = map ( int , input ( ) . split ( ) ) minn = 1000 a = [ ] for i in range ( n ) : word = input ( ) if word . find ( " S " ) < word . find ( " G " ) : print ( - 1 ) exit ( ) else : x = word . find ( " S " ) - word . find ( " G " ) if x not in a : a . append ( x ) print ( len ( a ) )   NEW_LINE


import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . Reader ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Scanner ; import java . util . StringTokenizer ;   public class ProblemA {   public static void main ( String [ ] args ) {

from math import ceil   if __name__ == ' _ _ main _ _ ' : n = int ( input ( ) ) arr = list ( map ( int , input ( ) . split ( ) ) )   narr = [ True ]   for i in range ( 1 , n - 1 ) : x = arr [ i ] narr . append ( x == arr [ i - 1 ] or x == arr [ i + 1 ] )   narr . append ( True )   cnt = 0 mc = 0   for x in narr : if not x : cnt += 1 if x and cnt : mc = max ( mc , cnt ) cnt = 0   if cnt : mc = max ( mc , cnt )   print ( ceil ( mc / 2 ) )   ss = None   for i , x in enumerate ( arr ) : if not narr [ i ] : if ss is None : ss = i elif ss is not None : if arr [ ss - 1 ] == x : for j in range ( ss , i ) : arr [ j ] = x else : for j in range ( ss , i ) : arr [ j ] = arr [ ss - 1 ] if j < ( i + ss ) / 2 else x ss = None   print ( * arr ) NEW_LINE

import sysinput = sys . stdin . readline   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) d = [ ] e = [ ] for i in range ( 1 , n - 1 ) : if a [ i ] != a [ i - 1 ] and a [ i ] != a [ i + 1 ] : e . append ( [ a [ i ] , i ] ) else : if e != [ ] : d . append ( e ) e = [ ] if e != [ ] : d . append ( e ) if len ( d ) == 0 : print ( 0 ) print ( * a ) else : e = [ ] for i in range ( len ( d ) ) : if d [ i ] [ 0 ] [ 0 ] == 0 : if len ( d [ i ] ) % 2 == 0 : m = len ( d [ i ] ) e . append ( m // 2 ) for j in range ( m // 2 ) : a [ d [ i ] [ j ] [ 1 ] ] = 1 a [ d [ i ] [ m - j - 1 ] [ 1 ] ] = 0 else : m = len ( d [ i ] ) e . append ( m // 2 + 1 ) for j in range ( m ) : a [ d [ i ] [ j ] [ 1 ] ] = 1 if d [ i ] [ 0 ] [ 0 ] == 1 : if len ( d [ i ] ) % 2 == 0 : m = len ( d [ i ] ) e . append ( m // 2 ) for j in range ( m // 2 ) : a [ d [ i ] [ j ] [ 1 ] ] = 0 a [ d [ i ] [ m - j - 1 ] [ 1 ] ] = 1 else : m = len ( d [ i ] ) e . append ( m // 2 + 1 ) for j in range ( m ) : a [ d [ i ] [ j ] [ 1 ] ] = 0 print ( max ( e ) ) print ( * a ) NEW_LINE

import math   n = int ( input ( ) ) a = list ( map ( int , input ( ) . split ( ) ) ) segs = [ ] st = - 1 for i in range ( n ) : iso = False if i == 0 or i == n - 1 else a [ i - 1 ] == a [ i + 1 ] and a [ i ] != a [ i - 1 ] if iso and st == - 1 : st = i elif not iso and st != - 1 : segs . append ( ( st , i - 1 ) ) st = - 1 ans = 0 for l , r in segs : span = r - l + 1 ans = max ( ans , span ) for i in range ( span // 2 ) : a [ l + i ] = a [ l - 1 ] a [ r - i ] = a [ r + 1 ] if span % 2 : j = l + span // 2 a [ j ] = sorted ( [ a [ j - 1 ] , a [ j ] , a [ j + 1 ] ] ) [ 1 ] print ( math . ceil ( ans / 2 ) ) print ( * a ) NEW_LINE


import java . util . Collections ; import java . util . HashSet ; import java . util . PriorityQueue ; import java . util . Scanner ; import java . util . Set ;   public class Problem522B {   public static void main ( String [ ] args ) { Scanner s = new Scanner ( System . in ) ; int totalWidth = 0 ; int n = s . nextInt ( ) ; int arr [ ] = new int [ n ] ; int height [ ] = new int [ n ] ; PriorityQueue < Integer > maxHeap = new PriorityQueue < > ( Collections . reverseOrder ( ) ) ;

import java . util . * ;   public class Solution { private static Scanner scan = new Scanner ( System . in ) ; public static void main ( String args [ ] ) { int n = scan . nextInt ( ) ; int [ ] [ ] arr = new int [ n ] [ 2 ] ;

import com . sun . org . apache . bcel . internal . generic . AALOAD ; import com . sun . org . apache . bcel . internal . generic . GOTO ; import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . io . PrintWriter ; import java . math . BigInteger ; import java . util . * ; import java . util . stream . IntStream ; import javafx . util . Pair ; import static jdk . nashorn . internal . runtime . regexp . joni . Syntax . Java ;   public class Main { public static void main ( String [ ] args ) throws IOException {   Scanner input = new Scanner ( System . in ) ; int n = input . nextInt ( ) ; PriorityQueue < Integer > pqueue = new PriorityQueue < > ( Collections . reverseOrder ( ) ) ; long total = 0 ; int w [ ] = new int [ n ] ; int h [ ] = new int [ n ] ; StringBuilder ans = new StringBuilder ( ) ; for ( int i = 0 ; i < n ; i ++ ) { w [ i ] = input . nextInt ( ) ; h [ i ] = input . nextInt ( ) ; pqueue . add ( h [ i ] ) ; total += w [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { long nowW = total - w [ i ] ; long height = - 1 ; if ( pqueue . peek ( ) == h [ i ] ) { int one = pqueue . poll ( ) ; height = pqueue . peek ( ) ; pqueue . add ( one ) ; } else height = pqueue . peek ( ) ;

import java . io . BufferedReader ; import java . io . IOException ; import java . io . InputStreamReader ; import java . util . * ;   public class Codeforces {   private static final Scanner sc = new Scanner ( System . in ) ; private static final BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; private static final long MOD = ( long ) ( 1e9 + 7 ) ;   public static int [ ] LPS ( String p ) { int [ ] lps = new int [ p . length ( ) ] ;   int i = 1 ; int j = 0 ; while ( i < p . length ( ) ) { if ( p . charAt ( i ) == p . charAt ( j ) ) { lps [ i ] = j + 1 ; i ++ ; j ++ ; } else { if ( j == 0 ) { lps [ i ] = 0 ; i ++ ; } else { j = lps [ j - 1 ] ; } } } return lps ; }   public static void KMP ( String text , String pattern ) { int [ ] lps = LPS ( pattern ) ; int i = 0 ; int j = 0 ; ArrayList < Integer > matches = new ArrayList < > ( ) ; while ( i < text . length ( ) ) { if ( text . charAt ( i ) == pattern . charAt ( j ) ) { i ++ ; j ++ ; } else { if ( j != 0 ) { j = lps [ j - 1 ] ; } else { i ++ ; } } if ( j == pattern . length ( ) ) { matches . add ( i - j ) ; j = lps [ j - 1 ] ; } } for ( int x : matches ) { System . out . println ( " Match ▁ at ▁ : ▁ " + x ) ; } }   private static class SegmentTree { private long [ ] st ; private int size ; private int n ; private long [ ] a ; SegmentTree ( long [ ] a , int n ) { this . size = 4 * n ; this . n = n ; this . a = a ; st = new long [ size ] ;

n = int ( input ( ) ) ar = [ ] max1 = 0 max2 = 0 tw = 0 for i in range ( n ) : w , h = map ( int , input ( ) . split ( ) ) tw += w if ( h >= max1 ) : max2 = max1 max1 = h if ( max2 < h and h < max1 ) : max2 = max ( max2 , h ) ar . append ( ( w , h ) ) for i in range ( n ) : if ( ar [ i ] [ 1 ] == max1 ) : print ( ( tw - ar [ i ] [ 0 ] ) * max2 , end = ' ▁ ' ) else : print ( ( tw - ar [ i ] [ 0 ] ) * max1 , end = ' ▁ ' ) NEW_LINE

n = int ( input ( ) ) w , h , h1 , h2 = [ ] , [ ] , 0 , 0 for i in range ( n ) : x , y = map ( int , input ( ) . split ( ) ) w . append ( x ) h . append ( y ) if y > h1 : h2 = h1 h1 = y elif y > h2 : h2 = yans = sum ( w ) for i in range ( n ) : if h [ i ] == h1 : print ( ( ans - w [ i ] ) * h2 , end = ' ▁ ' ) else : print ( ( ans - w [ i ] ) * h1 , end = ' ▁ ' ) NEW_LINE

n = int ( input ( ) ) wsum = 0 hli = [ ] li = [ ] mx = 0 mxc = 1 smx = 0 k = 0 for i in range ( n ) : w , h = map ( int , input ( ) . split ( ) ) li . append ( [ w , h ] ) wsum += w if h > mx : smx = mx mx = h elif h == mx : mxc += 1 if h > smx and h != mx : smx = h hli . append ( h ) for i in range ( n ) : w = li [ i ] [ 0 ] h = li [ i ] [ 1 ] tmp = wsum - w if mxc == 1 or mxc == 0 : if h == mx : print ( tmp * smx , end = ' ▁ ' ) else : print ( tmp * mx , end = ' ▁ ' ) elif mxc > 1 : print ( tmp * mx , end = ' ▁ ' ) NEW_LINE


import java . util . * ; import java . io . * ; public class Solution { static class Reader { final private int BUFFER_SIZE = 1 << 16 ; private DataInputStream din ; private byte [ ] buffer ; private int bufferPointer , bytesRead ; public Reader ( ) { din = new DataInputStream ( System . in ) ; buffer = new byte [ BUFFER_SIZE ] ; bufferPointer = bytesRead = 0 ; } public Reader ( String file_name ) throws IOException { din = new DataInputStream ( new FileInputStream ( file_name ) ) ; buffer = new byte [ BUFFER_SIZE ] ; bufferPointer = bytesRead = 0 ; } public String readLine ( ) throws IOException { byte [ ] buf = new byte [ 64 ] ;

store = [ ] maxes = [ 0 ] def s ( nums , M ) : p = 1 for num in nums : p = p * ( ( 1 + num ) % M ) % M if p == 0 : return M - 1 return ( p - 1 ) % Mi = 0 while 2 ** i <= 10 ** 9 : store . append ( 2 ** i ) maxes . append ( 2 ** ( i + 1 ) - 1 ) i += 1 T = int ( input ( ) ) for t in range ( T ) : d , m = [ int ( i ) for i in input ( ) . split ( ) ] ans = [ ] for i in range ( 1 , len ( maxes ) ) : if maxes [ i ] <= d : ans . append ( maxes [ i ] - maxes [ i - 1 ] ) else : if d != maxes [ i - 1 ] : ans . append ( d - maxes [ i - 1 ] ) break final = s ( ans , m ) print ( final ) NEW_LINE

import sys     def input ( ) : return sys . stdin . readline ( ) . rstrip ( )       INF = 1 << 64     def filter ( ord , M ) : if ( 1 << ord ) <= M : return min ( M - ( 1 << ord ) + 1 , ( 1 << ord ) )   else : return 0     def slv ( ) : d , mod = map ( int , input ( ) . split ( ) ) K = d . bit_length ( ) - 1 DP = [ [ 0 ] * ( K + 1 ) for i in range ( K + 1 ) ] for i in range ( K + 1 ) : DP [ 0 ] [ i ] = filter ( i , d ) for i in range ( 1 , K + 1 ) : NEW_LINE


import java . io . OutputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . PrintWriter ; import java . util . StringTokenizer ; import java . io . IOException ; import java . io . BufferedReader ; import java . io . InputStreamReader ; import java . io . InputStream ;   public class Main { public static void main ( String [ ] args ) { InputStream inputStream = System . in ; OutputStream outputStream = System . out ; FastI in = new FastI ( inputStream ) ; PrintWriter out = new PrintWriter ( outputStream ) ; BDubiousCyrpto solver = new BDubiousCyrpto ( ) ; solver . solve ( 1 , in , out ) ; out . close ( ) ; }   static class BDubiousCyrpto { public void solve ( int testNumber , FastI sc , PrintWriter out ) { int t = sc . nextInt ( ) ; loop : while ( t > 0 ) { t -- ; int l = sc . nextInt ( ) ; int r = sc . nextInt ( ) ; long m = sc . nextLong ( ) ; for ( int a = l ; a <= r ; a ++ ) { long n = m / a ; long rest = m % a ; if ( n != 0 ) { if ( rest <= r - l ) { out . println ( a + " ▁ " + ( l + rest ) + " ▁ " + l ) ; continue loop ; } } rest -= a ; if ( Math . abs ( rest ) <= r - l ) { out . println ( a + " ▁ " + l + " ▁ " + ( l - rest ) ) ; continue loop ; } } } }   }   static class FastI { BufferedReader br ; StringTokenizer st ;   public FastI ( InputStream inputStream ) { br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ;   }   public String next ( ) { while ( st == null || ! st . hasMoreElements ( ) ) { try { st = new StringTokenizer ( br . readLine ( ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } return st . nextToken ( ) ; }   public int nextInt ( ) { return Integer . parseInt ( next ( ) ) ; }   public long nextLong ( ) { return Long . parseLong ( next ( ) ) ; }   } }

for i in range ( int ( input ( ) ) ) : a , b , c = map ( int , input ( ) . split ( ) )   for j in range ( a , b + 1 ) :   if c % j < ( b - a + 1 ) and c // j != 0 : print ( j , a + c % j , a )   break if ( j - c % j ) < ( b - a + 1 ) : print ( j , a , a + ( j - c % j ) ) break NEW_LINE

import sysdef get_ints ( ) : return ( map ( int , sys . stdin . readline ( ) . strip ( ) . split ( ) ) )   for ad in range ( int ( input ( ) ) ) : l , r , m = get_ints ( ) x = r - l for i in range ( l , r + 1 ) : k = m % i if i - k <= x : a = i b = l c = l + i - k break elif k <= x : if k == m : continue c = l b = l + k a = i   break     print ( a , b , c ) NEW_LINE

import sysinput = sys . stdin . readline from collections import defaultdict   for _ in range ( int ( input ( ) ) ) : l , r , m = map ( int , input ( ) . split ( ) ) for i in range ( l , r + 1 ) :   if i - m % i <= r - l : c = r b = c - ( i - m % i ) a = i break   elif m % i <= r - l : c = l b = l + m % i a = i break print ( a , b , c )   NEW_LINE

for i in range ( int ( input ( ) ) ) : l , r , m = list ( map ( int , input ( ) . split ( ) ) ) d = r - l f = max ( 1 , m - d ) for j in range ( l , r + 1 ) : if f + j - f % j <= m + d or f % j == 0 : a = j if f % j == 0 : e = m - f else : e = m - f - j + f % j break if e > 0 : c = l b = c + e else : c = r b = c + e print ( a , b , c ) NEW_LINE


import java . util . Vector ; import java . util . Arrays ; class GfG { static int checkBit ( int pattern , Vector < Integer > arr , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( ( pattern & arr . get ( i ) ) == pattern ) count ++ ; return count ; } static int largest ( int arr [ ] , int n ) { Vector < Integer > v = new Vector < > ( ) ; for ( Integer a : arr ) v . add ( a ) ; v . add ( Integer . MAX_VALUE ) ; n ++ ; int res = 0 ; for ( int bit = 31 ; bit >= 0 ; bit -- ) { int count = checkBit ( res | ( 1 << bit ) , v , n ) ; if ( ( count | 1 ) != 1 ) res |= ( 1 << bit ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 8 , 6 , 2 } ; int n = arr . length ; System . out . println ( " Largest ▁ element ▁ = ▁ " + largest ( arr , n ) ) ; } }

import math as mt NEW_LINE def checkBit ( pattern , arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ( pattern & arr [ i ] ) == pattern ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT def largest ( arr , n ) : NEW_LINE INDENT v = arr NEW_LINE v . append ( 2 ** 31 - 1 ) NEW_LINE n = n + 1 NEW_LINE res = 0 NEW_LINE for bit in range ( 31 , - 1 , - 1 ) : NEW_LINE INDENT count = checkBit ( res | ( 1 << bit ) , v , n ) NEW_LINE if ( ( count | 1 ) != 1 ) : NEW_LINE INDENT res |= ( 1 << bit ) NEW_LINE DEDENT DEDENT return res NEW_LINE DEDENT arr = [ 4 , 8 , 6 , 2 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Largest ▁ element ▁ = " , largest ( arr , n ) ) NEW_LINE


class GFG { static int operations ( int op [ ] , int n , int k ) { int i , count = 0 ; int nVal = 0 ; int min = Integer . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { nVal += op [ i ] ; min = Math . min ( min , nVal ) ; if ( ( k + nVal ) <= 0 ) return ( i + 1 ) ; } if ( nVal >= 0 ) return - 1 ; int times = ( k - Math . abs ( min ) ) / Math . abs ( nVal ) ; k = ( k - ( times * Math . abs ( nVal ) ) ) ; count = ( times * n ) ; while ( k > 0 ) { for ( i = 0 ; i < n ; i ++ ) { k = k + op [ i ] ; count ++ ; if ( k <= 0 ) break ; } } return count ; } public static void main ( String [ ] args ) { int op [ ] = { - 60 , 65 , - 1 , 14 , - 25 } ; int n = op . length ; int k = 100000 ; System . out . print ( operations ( op , n , k ) ) ; } }

def operations ( op , n , k ) : NEW_LINE INDENT i , count = 0 , 0 NEW_LINE nVal = 0 NEW_LINE minimum = 10 ** 9 NEW_LINE for i in range ( n ) : NEW_LINE INDENT nVal += op [ i ] NEW_LINE minimum = min ( minimum , nVal ) NEW_LINE if ( ( k + nVal ) <= 0 ) : NEW_LINE INDENT return ( i + 1 ) NEW_LINE DEDENT DEDENT if ( nVal >= 0 ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT times = ( k - abs ( minimum ) ) // abs ( nVal ) NEW_LINE k = ( k - ( times * abs ( nVal ) ) ) NEW_LINE count = ( times * n ) NEW_LINE while ( k > 0 ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT k = k + op [ i ] NEW_LINE count += 1 NEW_LINE if ( k <= 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT op = [ - 60 , 65 , - 1 , 14 , - 25 ] NEW_LINE n = len ( op ) NEW_LINE k = 100000 NEW_LINE print ( operations ( op , n , k ) ) NEW_LINE


import java . util . * ; class GFG { static int subsequence ( int [ ] S , int [ ] T , int n , int m ) { int [ ] [ ] dp = new int [ n + 1 ] [ m + 1 ] ; int mod = 1000000007 ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 1 ; for ( int j = 0 ; j <= m ; j ++ ) dp [ 0 ] [ j ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j <= m ; ++ j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] - dp [ i - 1 ] [ j - 1 ] ; if ( S [ i - 1 ] == T [ j - 1 ] ) dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; dp [ i ] [ j ] += mod ; dp [ i ] [ j ] %= mod ; } } return dp [ n ] [ m ] ; } public static void main ( String [ ] args ) { int S [ ] = { 1 , 1 } ; int n = S . length ; int T [ ] = { 1 , 1 } ; int m = T . length ; System . out . println ( subsequence ( S , T , n , m ) ) ; } }

import numpy as np NEW_LINE mod = int ( 1e9 + 7 ) NEW_LINE def subsequence ( S , T , n , m ) : NEW_LINE INDENT dp = np . zeros ( ( n + 1 , m + 1 ) ) ; NEW_LINE for i in range ( n + 1 ) : NEW_LINE INDENT dp [ i ] [ 0 ] = 1 ; NEW_LINE DEDENT for j in range ( m + 1 ) : NEW_LINE INDENT dp [ 0 ] [ j ] = 1 ; NEW_LINE DEDENT for i in range ( 1 , n + 1 ) : NEW_LINE INDENT for j in range ( 1 , m + 1 ) : NEW_LINE INDENT dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i ] [ j - 1 ] -   \ NEW_LINE INDENT dp [ i - 1 ] [ j - 1 ] ; NEW_LINE DEDENT if ( S [ i - 1 ] == T [ j - 1 ] ) : NEW_LINE INDENT dp [ i ] [ j ] += dp [ i - 1 ] [ j - 1 ] ; NEW_LINE DEDENT dp [ i ] [ j ] += mod ; NEW_LINE dp [ i ] [ j ] %= mod ; NEW_LINE DEDENT DEDENT return dp [ n ] [ m ] ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = [ 1 , 1 ] ; NEW_LINE n = len ( S ) ; NEW_LINE T = [ 1 , 1 ] ; NEW_LINE m = len ( T ) ; NEW_LINE print ( subsequence ( S , T , n , m ) ) ; NEW_LINE DEDENT


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

def isPowerOfFour ( n ) : NEW_LINE INDENT count = 0 NEW_LINE if ( n and ( not ( n & ( n - 1 ) ) ) ) : NEW_LINE INDENT while ( n > 1 ) : NEW_LINE INDENT n >>= 1 NEW_LINE count += 1 NEW_LINE DEDENT if ( count % 2 == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT else : NEW_LINE INDENT return False NEW_LINE DEDENT DEDENT DEDENT test_no = 64 NEW_LINE if ( isPowerOfFour ( 64 ) ) : NEW_LINE INDENT print ( test_no , ' is ▁ a ▁ power ▁ of ▁ 4' ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( test_no , ' is ▁ not ▁ a ▁ power ▁ of ▁ 4' ) NEW_LINE DEDENT


import java . io . * ; class GFG { static boolean checkDistinct ( int x ) { int last = x % 10 ; while ( x > 0 ) { if ( x % 10 != last ) return false ; x = x / 10 ; } return true ; } static int findCount ( int L , int R ) { int count = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( checkDistinct ( i ) ) count += 1 ; } return count ; } public static void main ( String [ ] args ) { int L = 10 , R = 50 ; System . out . println ( findCount ( L , R ) ) ; } }

def checkDistinct ( x ) : NEW_LINE INDENT last = x % 10 NEW_LINE while ( x ) : NEW_LINE INDENT if ( x % 10 != last ) : NEW_LINE INDENT return False NEW_LINE DEDENT x = x // 10 NEW_LINE DEDENT return True NEW_LINE DEDENT def findCount ( L , R ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( L , R + 1 ) : NEW_LINE INDENT if ( checkDistinct ( i ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT L = 10 NEW_LINE R = 50 NEW_LINE print ( findCount ( L , R ) ) NEW_LINE


class GFG { static void removeDuplicates ( int arr [ ] , int n ) { int st = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n - 2 && arr [ i ] == arr [ i + 1 ] && arr [ i ] == arr [ i + 2 ] ) continue ; else { arr [ st ] = arr [ i ] ; st ++ ; } } System . out . print ( " { " ) ; for ( int i = 0 ; i < st ; i ++ ) { System . out . print ( arr [ i ] ) ; if ( i != st - 1 ) System . out . print ( " , ▁ " ) ; } System . out . print ( " } " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 5 } ; int n = arr . length ; removeDuplicates ( arr , n ) ; } }

def removeDuplicates ( arr , n ) : NEW_LINE INDENT st = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i < n - 2 and arr [ i ] == arr [ i + 1 ] and arr [ i ] == arr [ i + 2 ] ) : NEW_LINE INDENT continue ; NEW_LINE DEDENT else : NEW_LINE INDENT arr [ st ] = arr [ i ] ; NEW_LINE st += 1 ; NEW_LINE DEDENT DEDENT print ( " { " , end = " " ) NEW_LINE for i in range ( st ) : NEW_LINE INDENT print ( arr [ i ] , end = " " ) ; NEW_LINE if ( i != st - 1 ) : NEW_LINE INDENT print ( " , ▁ " , end = " " ) ; NEW_LINE DEDENT DEDENT print ( " } " , end = " " ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE removeDuplicates ( arr , n ) ; NEW_LINE DEDENT


import java . io . * ; class GFG { static int MAX = 1000000 ; static int MOD = 10000007 ; static int [ ] result = new int [ MAX + 1 ] ; static int [ ] fact = new int [ MAX + 1 ] ; static void preCompute ( ) { fact [ 0 ] = 1 ; result [ 0 ] = 1 ; for ( int i = 1 ; i <= MAX ; i ++ ) { fact [ i ] = ( ( fact [ i - 1 ] % MOD ) * i ) % MOD ; result [ i ] = ( ( result [ i - 1 ] % MOD ) * ( fact [ i ] % MOD ) ) % MOD ; } } static void performQueries ( int q [ ] , int n ) { preCompute ( ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . println ( result [ q [ i ] ] ) ; } public static void main ( String [ ] args ) { int q [ ] = { 4 , 5 } ; int n = q . length ; performQueries ( q , n ) ; } }

MAX = 1000000 NEW_LINE MOD = 10 ** 9 + 7 NEW_LINE result = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE fact = [ 0 for i in range ( MAX + 1 ) ] NEW_LINE def preCompute ( ) : NEW_LINE INDENT fact [ 0 ] = 1 NEW_LINE result [ 0 ] = 1 NEW_LINE for i in range ( 1 , MAX + 1 ) : NEW_LINE INDENT fact [ i ] = ( ( fact [ i - 1 ] % MOD ) * i ) % MOD NEW_LINE result [ i ] = ( ( result [ i - 1 ] % MOD ) * ( fact [ i ] % MOD ) ) % MOD NEW_LINE DEDENT DEDENT def performQueries ( q , n ) : NEW_LINE INDENT preCompute ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( result [ q [ i ] ] ) NEW_LINE DEDENT DEDENT q = [ 4 , 5 ] NEW_LINE n = len ( q ) NEW_LINE performQueries ( q , n ) NEW_LINE


import java . io . * ; class GFG { static int findMissingNo ( int [ ] arr , int n ) { int val ; int nextval ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] <= 0 || arr [ i ] > n ) continue ; val = arr [ i ] ; while ( arr [ val - 1 ] != val ) { nextval = arr [ val - 1 ] ; arr [ val - 1 ] = val ; val = nextval ; if ( val <= 0 || val > n ) break ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != i + 1 ) { return i + 1 ; } } return n + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 7 , 6 , 8 , - 1 , - 10 , 15 } ; int arr_size = arr . length ; int missing = findMissingNo ( arr , arr_size ) ; System . out . println ( " The ▁ smallest ▁ positive " + " ▁ missing ▁ number ▁ is ▁ " + missing ) ; } }

def findMissingNo ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] <= 0 or arr [ i ] > n ) : NEW_LINE INDENT continue NEW_LINE DEDENT val = arr [ i ] NEW_LINE while ( arr [ val - 1 ] != val ) : NEW_LINE INDENT nextval = arr [ val - 1 ] NEW_LINE arr [ val - 1 ] = val NEW_LINE val = nextval NEW_LINE if ( val <= 0 or val > n ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] != i + 1 ) : NEW_LINE INDENT return i + 1 NEW_LINE DEDENT DEDENT return n + 1 NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 3 , 7 , 6 , 8 , - 1 , - 10 , 15 ] NEW_LINE arr_size = len ( arr ) NEW_LINE missing = findMissingNo ( arr , arr_size ) NEW_LINE print ( " The ▁ smallest ▁ positive " , " missing ▁ number ▁ is ▁ " , missing ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int numberOfDivisors ( int num ) { int c = 0 ; for ( int i = 1 ; i <= num ; i ++ ) { if ( num % i == 0 ) { c += 1 ; } } return c ; } static int countNumbers ( int n ) { int c = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( numberOfDivisors ( i ) == 9 ) c += 1 ; } return c ; } public static void main ( String [ ] args ) { int n = 1000 ; System . out . print ( countNumbers ( n ) ) ; } }

def numberOfDivisors ( num ) : NEW_LINE INDENT c = 0 NEW_LINE for i in range ( 1 , num + 1 ) : NEW_LINE INDENT if ( num % i == 0 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT def countNumbers ( n ) : NEW_LINE INDENT c = 0 NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( numberOfDivisors ( i ) == 9 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT return c NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 1000 NEW_LINE print ( countNumbers ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int MAX = 10000 ; static int MAX_ELEMENT = 50 ; static int [ ] [ ] [ ] dp = new int [ MAX_ELEMENT ] [ MAX_ELEMENT ] [ MAX ] ; static int Max_Xor ( int arr [ ] , int i , int j , int mask , int n ) { if ( i >= n ) { if ( j == 0 ) return mask ; else return 0 ; } if ( dp [ i ] [ j ] [ mask ] != - 1 ) return dp [ i ] [ j ] [ mask ] ; int ans = 0 ; if ( j > 0 ) ans = Max_Xor ( arr , i + 1 , j - 1 , mask ^ arr [ i ] , n ) ; ans = Math . max ( ans , Max_Xor ( arr , i + 1 , j , mask , n ) ) ; return dp [ i ] [ j ] [ mask ] = ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 4 , 1 , 3 , 7 , 6 , 8 } ; int n = arr . length ; int k = 3 ; for ( int i = 0 ; i < MAX_ELEMENT ; i ++ ) { for ( int j = 0 ; j < MAX_ELEMENT ; j ++ ) { for ( int l = 0 ; l < MAX ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } System . out . println ( Max_Xor ( arr , 0 , k , 0 , n ) ) ; } }

MAX = 10000 NEW_LINE MAX_ELEMENT = 50 NEW_LINE dp = [ [ [ - 1 for i in range ( MAX ) ] for j in range ( MAX_ELEMENT ) ] for k in range ( MAX_ELEMENT ) ] NEW_LINE def Max_Xor ( arr , i , j , mask , n ) : NEW_LINE INDENT if ( i >= n ) : NEW_LINE INDENT if ( j == 0 ) : NEW_LINE INDENT return mask NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT if ( dp [ i ] [ j ] [ mask ] != - 1 ) : NEW_LINE INDENT return dp [ i ] [ j ] [ mask ] NEW_LINE DEDENT ans = 0 NEW_LINE if ( j > 0 ) : NEW_LINE INDENT ans = Max_Xor ( arr , i + 1 , j - 1 , mask ^ arr [ i ] , n ) NEW_LINE DEDENT ans = max ( ans , Max_Xor ( arr , i + 1 , j , mask , n ) ) NEW_LINE dp [ i ] [ j ] [ mask ] = ans NEW_LINE return ans NEW_LINE DEDENT arr = [ 2 , 5 , 4 , 1 , 3 , 7 , 6 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE k = 3 NEW_LINE print ( Max_Xor ( arr , 0 , k , 0 , n ) ) NEW_LINE


import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { public static int countOddSquares ( int n , int m ) { return ( int ) Math . pow ( ( double ) m , 0.5 ) - ( int ) Math . pow ( ( double ) n - 1 , 0.5 ) ; } public static void main ( String [ ] args ) { int n = 5 , m = 100 ; System . out . print ( " Count ▁ is ▁ " + countOddSquares ( n , m ) ) ; } }

def countOddSquares ( n , m ) : NEW_LINE INDENT return int ( m ** 0.5 ) - int ( ( n - 1 ) ** 0.5 ) NEW_LINE DEDENT n = 5 NEW_LINE m = 100 NEW_LINE print ( " Count ▁ is " , countOddSquares ( n , m ) ) NEW_LINE


import java . io . * ; class Binary { static int maxOnesIndex ( int arr [ ] , int n ) { int max_count = 0 ; int max_index = 0 ; int prev_zero = - 1 ; int prev_prev_zero = - 1 ; for ( int curr = 0 ; curr < n ; ++ curr ) { if ( arr [ curr ] == 0 ) { if ( curr - prev_prev_zero > max_count ) { max_count = curr - prev_prev_zero ; max_index = prev_zero ; } prev_prev_zero = prev_zero ; prev_zero = curr ; } } if ( n - prev_prev_zero > max_count ) max_index = prev_zero ; return max_index ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( " Index ▁ of ▁ 0 ▁ to ▁ be ▁ replaced ▁ is ▁ " + maxOnesIndex ( arr , n ) ) ; } }

def maxOnesIndex ( arr , n ) : NEW_LINE INDENT max_count = 0 NEW_LINE max_index = 0 NEW_LINE prev_zero = - 1 NEW_LINE prev_prev_zero = - 1 NEW_LINE for curr in range ( n ) : NEW_LINE INDENT if ( arr [ curr ] == 0 ) : NEW_LINE INDENT if ( curr - prev_prev_zero > max_count ) : NEW_LINE INDENT max_count = curr - prev_prev_zero NEW_LINE max_index = prev_zero NEW_LINE DEDENT prev_prev_zero = prev_zero NEW_LINE prev_zero = curr NEW_LINE DEDENT DEDENT if ( n - prev_prev_zero > max_count ) : NEW_LINE INDENT max_index = prev_zero NEW_LINE DEDENT return max_index NEW_LINE DEDENT arr = [ 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Index ▁ of ▁ 0 ▁ to ▁ be ▁ replaced ▁ is ▁ " , maxOnesIndex ( arr , n ) ) NEW_LINE


import java . io . * ; import java . lang . * ; class GFG { public static double answer ( double X , double K ) { double i = 10 ; double MIN = Math . pow ( i , K - 1 ) ; if ( MIN % X == 0 ) return ( MIN ) ; else return ( ( MIN + X ) - ( ( MIN + X ) % X ) ) ; } public static void main ( String [ ] args ) { double X = 83 ; double K = 5 ; System . out . println ( ( int ) answer ( X , K ) ) ; } }

def answer ( X , K ) : NEW_LINE INDENT MIN = pow ( 10 , K - 1 ) NEW_LINE if ( MIN % X == 0 ) : NEW_LINE INDENT return ( MIN ) NEW_LINE DEDENT else : NEW_LINE INDENT return ( ( MIN + X ) - ( ( MIN + X ) % X ) ) NEW_LINE DEDENT DEDENT X = 83 ; NEW_LINE K = 5 ; NEW_LINE print ( answer ( X , K ) ) ; NEW_LINE


class GFG { static double extrapolate ( double [ ] [ ] d , double x ) { double y = d [ 0 ] [ 1 ] + ( x - d [ 0 ] [ 0 ] ) / ( d [ 1 ] [ 0 ] - d [ 0 ] [ 0 ] ) * ( d [ 1 ] [ 1 ] - d [ 0 ] [ 1 ] ) ; return y ; } public static void main ( String [ ] args ) { double [ ] [ ] d = { { 1.2 , 2.7 } , { 1.4 , 3.1 } } ; double x = 2.1 ; System . out . println ( " Value ▁ of ▁ y ▁ at ▁ x ▁ = ▁ 2.1 ▁ : ▁ " + extrapolate ( d , x ) ) ; } }

def extrapolate ( d , x ) : NEW_LINE INDENT y = ( d [ 0 ] [ 1 ] + ( x - d [ 0 ] [ 0 ] ) / ( d [ 1 ] [ 0 ] - d [ 0 ] [ 0 ] ) * ( d [ 1 ] [ 1 ] - d [ 0 ] [ 1 ] ) ) ; NEW_LINE return y ; NEW_LINE DEDENT d = [ [ 1.2 , 2.7 ] , [ 1.4 , 3.1 ] ] ; NEW_LINE x = 2.1 ; NEW_LINE print ( " Value ▁ of ▁ y ▁ at ▁ x ▁ = ▁ 2.1 ▁ : " , extrapolate ( d , x ) ) ; NEW_LINE


class GFG { static void ifPossible ( int X , int Y ) { if ( X > Y ) swap ( X , Y ) ; if ( ( X + Y ) % 5 == 0 && 3 * X >= 2 * Y ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } static void swap ( int x , int y ) { int temp = x ; x = y ; y = temp ; } public static void main ( String [ ] args ) { int X = 33 , Y = 27 ; ifPossible ( X , Y ) ; } }

def ifPossible ( X , Y ) : NEW_LINE INDENT if ( X > Y ) : NEW_LINE INDENT X , Y = Y , X NEW_LINE DEDENT if ( ( X + Y ) % 5 == 0 and 3 * X >= 2 * Y ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT X = 33 NEW_LINE Y = 27 NEW_LINE ifPossible ( X , Y ) NEW_LINE


class GFG { static int MAX = 1000 ; static char [ ] replaceSpaces ( char [ ] str ) { int space_count = 0 , i = 0 ; for ( i = 0 ; i < str . length ; i ++ ) if ( str [ i ] == ' ▁ ' ) space_count ++ ; while ( str [ i - 1 ] == ' ▁ ' ) { space_count -- ; i -- ; } int new_length = i + space_count * 2 ; if ( new_length > MAX ) return str ; int index = new_length - 1 ; char [ ] new_str = str ; str = new char [ new_length ] ; for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( new_str [ j ] == ' ▁ ' ) { str [ index ] = '0' ; str [ index - 1 ] = '2' ; str [ index - 2 ] = ' % ' ; index = index - 3 ; } else { str [ index ] = new_str [ j ] ; index -- ; } } return str ; } public static void main ( String [ ] args ) { char [ ] str = " Mr ▁ John ▁ Smith ▁ " . toCharArray ( ) ; str = replaceSpaces ( str ) ; for ( int i = 0 ; i < str . length ; i ++ ) System . out . print ( str [ i ] ) ; } }

MAX = 1000 ; NEW_LINE def replaceSpaces ( string ) : NEW_LINE INDENT string = string . strip ( ) NEW_LINE i = len ( string ) NEW_LINE space_count = string . count ( ' ▁ ' ) NEW_LINE new_length = i + space_count * 2 NEW_LINE if new_length > MAX : NEW_LINE INDENT return - 1 NEW_LINE DEDENT index = new_length - 1 NEW_LINE string = list ( string ) NEW_LINE for f in range ( i - 2 , new_length - 2 ) : NEW_LINE INDENT string . append ( '0' ) NEW_LINE DEDENT for j in range ( i - 1 , 0 , - 1 ) : NEW_LINE INDENT if string [ j ] == ' ▁ ' : NEW_LINE INDENT string [ index ] = '0' NEW_LINE string [ index - 1 ] = '2' NEW_LINE string [ index - 2 ] = ' % ' NEW_LINE index = index - 3 NEW_LINE DEDENT else : NEW_LINE INDENT string [ index ] = string [ j ] NEW_LINE index -= 1 NEW_LINE DEDENT DEDENT return ' ' . join ( string ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " Mr ▁ John ▁ Smith ▁ " NEW_LINE s = replaceSpaces ( s ) NEW_LINE print ( s ) NEW_LINE DEDENT


import java . util . Arrays ; public class Test { static int arr [ ] = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; static void rotate ( ) { int x = arr [ arr . length - 1 ] , i ; for ( i = arr . length - 1 ; i > 0 ; i -- ) arr [ i ] = arr [ i - 1 ] ; arr [ 0 ] = x ; } public static void main ( String [ ] args ) { System . out . println ( " Given ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; rotate ( ) ; System . out . println ( " Rotated ▁ Array ▁ is " ) ; System . out . println ( Arrays . toString ( arr ) ) ; } }

def rotate ( arr , n ) : NEW_LINE INDENT x = arr [ n - 1 ] NEW_LINE for i in range ( n - 1 , 0 , - 1 ) : NEW_LINE INDENT arr [ i ] = arr [ i - 1 ] ; NEW_LINE DEDENT arr [ 0 ] = x ; NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Given ▁ array ▁ is " ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT rotate ( arr , n ) NEW_LINE print ( " \n Rotated ▁ array ▁ is " ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = ' ▁ ' ) NEW_LINE DEDENT


class CountSubString { int countSubStr ( char str [ ] , int n ) { int m = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == '1' ) m ++ ; } return m * ( m - 1 ) / 2 ; } public static void main ( String [ ] args ) { CountSubString count = new CountSubString ( ) ; String string = "00100101" ; char str [ ] = string . toCharArray ( ) ; int n = str . length ; System . out . println ( count . countSubStr ( str , n ) ) ; } }

def countSubStr ( st , n ) : NEW_LINE INDENT m = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( st [ i ] == '1' ) : NEW_LINE INDENT m = m + 1 NEW_LINE DEDENT DEDENT return m * ( m - 1 ) // 2 NEW_LINE DEDENT st = "00100101" ; NEW_LINE list ( st ) NEW_LINE n = len ( st ) NEW_LINE print ( countSubStr ( st , n ) , end = " " ) NEW_LINE


import java . util . * ; class GFG { static int countStaircases ( int N ) { int [ ] [ ] memo = new int [ N + 5 ] [ N + 5 ] ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = 0 ; j <= N ; j ++ ) { memo [ i ] [ j ] = 0 ; } } memo [ 3 ] [ 2 ] = memo [ 4 ] [ 2 ] = 1 ; for ( int i = 5 ; i <= N ; i ++ ) { for ( int j = 2 ; j <= i ; j ++ ) { if ( j == 2 ) { memo [ i ] [ j ] = memo [ i - j ] [ j ] + 1 ; } else { memo [ i ] [ j ] = memo [ i - j ] [ j ] + memo [ i - j ] [ j - 1 ] ; } } } int answer = 0 ; for ( int i = 1 ; i <= N ; i ++ ) answer = answer + memo [ N ] [ i ] ; return answer ; } public static void main ( String [ ] args ) { int N = 7 ; System . out . println ( countStaircases ( N ) ) ; } }

def countStaircases ( N ) : NEW_LINE INDENT memo = [ [ 0 for x in range ( N + 5 ) ] for y in range ( N + 5 ) ] NEW_LINE for i in range ( N + 1 ) : NEW_LINE INDENT for j in range ( N + 1 ) : NEW_LINE INDENT memo [ i ] [ j ] = 0 NEW_LINE DEDENT DEDENT memo [ 3 ] [ 2 ] = memo [ 4 ] [ 2 ] = 1 NEW_LINE for i in range ( 5 , N + 1 ) : NEW_LINE INDENT for j in range ( 2 , i + 1 ) : NEW_LINE INDENT if ( j == 2 ) : NEW_LINE INDENT memo [ i ] [ j ] = memo [ i - j ] [ j ] + 1 NEW_LINE DEDENT else : NEW_LINE INDENT memo [ i ] [ j ] = ( memo [ i - j ] [ j ] + memo [ i - j ] [ j - 1 ] ) NEW_LINE DEDENT DEDENT DEDENT answer = 0 NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT answer = answer + memo [ N ] [ i ] NEW_LINE DEDENT return answer NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 7 NEW_LINE print ( countStaircases ( N ) ) NEW_LINE DEDENT


class GFG { static long dp [ ] [ ] [ ] = new long [ 18 ] [ 2 ] [ 162 ] ; static long solve ( int i , boolean tight , int sum_so_far , int Sum , String number , int len ) { if ( i == len ) { if ( sum_so_far == Sum ) return 1 ; else return 0 ; } long ans = dp [ i ] [ 1 ] [ sum_so_far ] ; if ( ans != - 1 ) { return ans ; } ans = 0 ; boolean ntight ; int nsum_so_far ; for ( char currdigit = '0' ; currdigit <= '9' ; currdigit ++ ) { if ( ! tight && currdigit > number . charAt ( i ) ) { break ; } ntight = tight || currdigit < number . charAt ( i ) ; nsum_so_far = sum_so_far + ( currdigit - '0' ) ; ans += solve ( i + 1 , ntight , nsum_so_far , Sum , number , len ) ; } return ans ; } public static void main ( String [ ] args ) { long count = 0 ; int sum = 4 ; String number = "100" ; for ( int i = 0 ; i < 18 ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) { for ( int k = 0 ; k < 162 ; k ++ ) dp [ i ] [ j ] [ k ] = - 1 ; } } System . out . println ( solve ( 0 , false , 0 , sum , number , number . length ( ) ) ) ; } }

def solve ( i , tight , sum_so_far , Sum , number , length ) : NEW_LINE INDENT if i == length : NEW_LINE INDENT if sum_so_far == Sum : NEW_LINE INDENT return 1 NEW_LINE DEDENT else : NEW_LINE INDENT return 0 NEW_LINE DEDENT DEDENT ans = dp [ i ] [ tight ] [ sum_so_far ] NEW_LINE if ans != - 1 : NEW_LINE INDENT return ans NEW_LINE DEDENT ans = 0 NEW_LINE for currdigit in range ( 0 , 10 ) : NEW_LINE INDENT currdigitstr = str ( currdigit ) NEW_LINE if not tight and currdigitstr > number [ i ] : NEW_LINE INDENT break NEW_LINE DEDENT ntight = tight or currdigitstr < number [ i ] NEW_LINE nsum_so_far = sum_so_far + currdigit NEW_LINE ans += solve ( i + 1 , ntight , nsum_so_far , Sum , number , length ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT count , Sum = 0 , 4 NEW_LINE number = "100" NEW_LINE dp = [ [ [ - 1 for i in range ( 162 ) ] for j in range ( 2 ) ] for k in range ( 18 ) ] NEW_LINE print ( solve ( 0 , 0 , 0 , Sum , number , len ( number ) ) ) NEW_LINE DEDENT


static int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = 0 , max_ending_here = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; }

def maxSubArraySum ( a , size ) : NEW_LINE INDENT max_so_far = 0 NEW_LINE max_ending_here = 0 NEW_LINE for i in range ( 0 , size ) : NEW_LINE INDENT max_ending_here = max_ending_here + a [ i ] NEW_LINE if max_ending_here < 0 : NEW_LINE INDENT max_ending_here = 0 NEW_LINE DEDENT elif ( max_so_far < max_ending_here ) : NEW_LINE INDENT max_so_far = max_ending_here NEW_LINE DEDENT DEDENT return max_so_far NEW_LINE DEDENT


class GFG { static int countSC ( int N ) { int res = ( int ) Math . sqrt ( N ) + ( int ) Math . cbrt ( N ) - ( int ) ( Math . sqrt ( Math . cbrt ( N ) ) ) ; return res ; } public static void main ( String [ ] args ) { int N = 20 ; System . out . println ( " Number ▁ of ▁ squares ▁ " + " and ▁ cubes ▁ is ▁ " + countSC ( N ) ) ; } }

import math NEW_LINE def countSC ( N ) : NEW_LINE INDENT res = ( int ( math . sqrt ( N ) ) + int ( N ** ( 1 / 3 ) ) - int ( math . sqrt ( N ** ( 1 / 3 ) ) ) ) NEW_LINE return res NEW_LINE DEDENT N = 20 NEW_LINE print ( " Number ▁ of ▁ squares ▁ and ▁ cubes ▁ is " , countSC ( N ) ) NEW_LINE


class GFG { static void SieveOfSundaram ( boolean marked [ ] , int nNew ) { for ( int i = 1 ; i <= nNew ; i ++ ) for ( int j = i ; ( i + j + 2 * i * j ) <= nNew ; j ++ ) marked [ i + j + 2 * i * j ] = true ; } static int countPrimePairs ( int n ) { int nNew = ( n - 2 ) / 2 ; boolean marked [ ] = new boolean [ nNew + 1 ] ; SieveOfSundaram ( marked , nNew ) ; int count = 0 , prime_num ; for ( int i = 1 ; i <= nNew ; i ++ ) { if ( marked [ i ] == false ) { prime_num = 2 * i + 1 ; count = count + ( prime_num / 2 ) ; } } return count ; } public static void main ( String [ ] args ) { int n = 12 ; System . out . println ( " Number ▁ of ▁ prime ▁ pairs : ▁ " + countPrimePairs ( n ) ) ; } }

def SieveOfSundaram ( marked , nNew ) : NEW_LINE INDENT for i in range ( 1 , nNew + 1 ) : NEW_LINE INDENT for j in range ( i , nNew ) : NEW_LINE INDENT if i + j + 2 * i * j > nNew : NEW_LINE INDENT break NEW_LINE DEDENT marked [ i + j + 2 * i * j ] = True NEW_LINE DEDENT DEDENT DEDENT def countPrimePairs ( n ) : NEW_LINE INDENT nNew = ( n - 2 ) // 2 NEW_LINE marked = [ False for i in range ( nNew + 1 ) ] NEW_LINE SieveOfSundaram ( marked , nNew ) NEW_LINE count , prime_num = 0 , 0 NEW_LINE for i in range ( 1 , nNew + 1 ) : NEW_LINE INDENT if ( marked [ i ] == False ) : NEW_LINE INDENT prime_num = 2 * i + 1 NEW_LINE count = count + ( prime_num // 2 ) NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT n = 12 NEW_LINE print ( " Number ▁ of ▁ prime ▁ pairs : ▁ " , countPrimePairs ( n ) ) NEW_LINE


class GFG { static void segregate0and1 ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) count ++ ; } for ( int i = 0 ; i < count ; i ++ ) arr [ i ] = 0 ; for ( int i = count ; i < n ; i ++ ) arr [ i ] = 1 ; } static void print ( int arr [ ] , int n ) { System . out . print ( " Array ▁ after ▁ segregation ▁ is ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; int n = arr . length ; segregate0and1 ( arr , n ) ; print ( arr , n ) ; } }

def segregate0and1 ( arr , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] == 0 ) : NEW_LINE INDENT count = count + 1 NEW_LINE DEDENT DEDENT for i in range ( 0 , count ) : NEW_LINE INDENT arr [ i ] = 0 NEW_LINE DEDENT for i in range ( count , n ) : NEW_LINE INDENT arr [ i ] = 1 NEW_LINE DEDENT DEDENT def print_arr ( arr , n ) : NEW_LINE INDENT print ( " Array ▁ after ▁ segregation ▁ is ▁ " , end = " " ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT arr = [ 0 , 1 , 0 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE segregate0and1 ( arr , n ) NEW_LINE print_arr ( arr , n ) NEW_LINE


import java . io . * ; class GFG { static int BitCount [ ] = new int [ 10000 ] ; static void fillSetBitsMatrix ( int arr [ ] , int n ) { for ( int i = 0 ; i < 32 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { long temp = arr [ j ] >> i ; if ( temp % 2 != 0 ) BitCount [ j ] += 1 ; } } for ( int i = 1 ; i < n ; i ++ ) BitCount [ i ] += BitCount [ i - 1 ] ; } static void Query ( int Q [ ] [ ] , int q ) { for ( int i = 0 ; i < q ; i ++ ) System . out . println ( ( BitCount [ Q [ i ] [ 1 ] ] - BitCount [ Q [ i ] [ 0 ] - 1 ] ) ) ; } public static void main ( String [ ] args ) { int Arr [ ] = { 1 , 5 , 6 , 10 , 9 , 4 , 67 } ; int n = Arr . length ; fillSetBitsMatrix ( Arr , n ) ; int q = 2 ; int Q [ ] [ ] = { { 1 , 5 } , { 2 , 6 } } ; Query ( Q , q ) ; } }

BitCount = [ 0 ] * 10000 NEW_LINE def fillSetBitsmatrix ( arr : list , n : int ) : NEW_LINE INDENT global BitCount NEW_LINE for i in range ( 32 ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT temp = arr [ j ] >> i NEW_LINE if temp % 2 != 0 : NEW_LINE INDENT BitCount [ j ] += 1 NEW_LINE DEDENT DEDENT DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT BitCount [ i ] += BitCount [ i - 1 ] NEW_LINE DEDENT DEDENT def Query ( Q : list , q : int ) : NEW_LINE INDENT for i in range ( q ) : NEW_LINE INDENT print ( BitCount [ Q [ i ] [ 1 ] ] - BitCount [ Q [ i ] [ 0 ] - 1 ] ) NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT Arr = [ 1 , 5 , 6 , 10 , 9 , 4 , 67 ] NEW_LINE n = len ( Arr ) NEW_LINE fillSetBitsmatrix ( Arr , n ) NEW_LINE q = 2 NEW_LINE Q = [ ( 1 , 5 ) , ( 2 , 6 ) ] NEW_LINE Query ( Q , q ) NEW_LINE DEDENT


import java . util . * ; public class Seasons { public static void findSeason ( int M ) { switch ( M ) { case 12 : case 1 : case 2 : System . out . println ( " WINTER " ) ; break ; case 3 : case 4 : case 5 : System . out . println ( " SPRING " ) ; break ; case 6 : case 7 : case 8 : System . out . println ( " SUMMER " ) ; break ; case 9 : case 10 : case 11 : System . out . println ( " AUTUMN " ) ; break ; default : System . out . println ( " Invalid ▁ Month ▁ number " ) ; break ; } } public static void main ( String abc [ ] ) { int M = 5 ; System . out . println ( " For ▁ Month ▁ number : ▁ " + M ) ; findSeason ( M ) ; M = 10 ; System . out . println ( " For ▁ Month ▁ number : ▁ " + M ) ; findSeason ( M ) ; } }

def findseason ( M ) : NEW_LINE INDENT list1 = [ [ 12 , 1 , 2 ] , [ 3 , 4 , 5 ] , [ 6 , 7 , 8 ] , [ 9 , 10 , 11 ] ] NEW_LINE if M in list1 [ 0 ] : NEW_LINE INDENT print ( " WINTER " ) NEW_LINE DEDENT elif M in list1 [ 1 ] : NEW_LINE INDENT print ( " SPRING " ) NEW_LINE DEDENT elif M in list1 [ 2 ] : NEW_LINE INDENT print ( " SUMMER " ) NEW_LINE DEDENT elif M in list1 [ 3 ] : NEW_LINE INDENT print ( " AUTUMN " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Invalid ▁ Month ▁ Number " ) NEW_LINE DEDENT DEDENT M = 5 NEW_LINE print ( " For ▁ Month ▁ number : " , M ) ; NEW_LINE findseason ( M ) NEW_LINE M = 10 NEW_LINE print ( " For ▁ Month ▁ number : " , M ) ; NEW_LINE findseason ( M ) NEW_LINE


import java . util . * ; public class GFG { static class Graph { int V ; LinkedList < Integer > [ ] adj ; Graph ( int V ) { this . V = V ; adj = new LinkedList [ V ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new LinkedList < Integer > ( ) ; } void addEdge ( int v , int w ) { adj [ v ] . add ( w ) ; } void DFSUtil ( int s , Vector < Boolean > visited ) { Stack < Integer > stack = new Stack < > ( ) ; stack . push ( s ) ; while ( stack . empty ( ) == false ) { s = stack . peek ( ) ; stack . pop ( ) ; if ( visited . get ( s ) == false ) { System . out . print ( s + " ▁ " ) ; visited . set ( s , true ) ; } Iterator < Integer > itr = adj [ s ] . iterator ( ) ; while ( itr . hasNext ( ) ) { int v = itr . next ( ) ; if ( ! visited . get ( v ) ) stack . push ( v ) ; } } } void DFS ( ) { Vector < Boolean > visited = new Vector < Boolean > ( V ) ; for ( int i = 0 ; i < V ; i ++ ) visited . add ( false ) ; for ( int i = 0 ; i < V ; i ++ ) if ( ! visited . get ( i ) ) DFSUtil ( i , visited ) ; } } public static void main ( String [ ] args ) { Graph g = new Graph ( 5 ) ; g . addEdge ( 1 , 0 ) ; g . addEdge ( 2 , 1 ) ; g . addEdge ( 3 , 4 ) ; g . addEdge ( 4 , 0 ) ; System . out . println ( " Following ▁ is ▁ Depth ▁ First ▁ Traversal " ) ; g . DFS ( ) ; } }

class Graph : NEW_LINE INDENT def __init__ ( self , V ) : NEW_LINE INDENT self . V = V NEW_LINE self . adj = [ [ ] for i in range ( V ) ] NEW_LINE DEDENT def addEdge ( self , v , w ) : NEW_LINE INDENT self . adj [ v ] . append ( w ) NEW_LINE DEDENT def DFSUtil ( self , s , visited ) : NEW_LINE INDENT stack = [ ] NEW_LINE stack . append ( s ) NEW_LINE while ( len ( stack ) != 0 ) : NEW_LINE INDENT s = stack . pop ( ) NEW_LINE if ( not visited [ s ] ) : NEW_LINE INDENT print ( s , end = " ▁ " ) NEW_LINE visited [ s ] = True NEW_LINE DEDENT i = 0 NEW_LINE while i < len ( self . adj [ s ] ) : NEW_LINE INDENT if ( not visited [ self . adj [ s ] [ i ] ] ) : NEW_LINE INDENT stack . append ( self . adj [ s ] [ i ] ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT DEDENT DEDENT def DFS ( self ) : NEW_LINE INDENT visited = [ False ] * self . V NEW_LINE for i in range ( self . V ) : NEW_LINE INDENT if ( not visited [ i ] ) : NEW_LINE INDENT self . DFSUtil ( i , visited ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT g = Graph ( 5 ) NEW_LINE g . addEdge ( 1 , 0 ) NEW_LINE g . addEdge ( 2 , 1 ) NEW_LINE g . addEdge ( 3 , 4 ) NEW_LINE g . addEdge ( 4 , 0 ) NEW_LINE print ( " Following ▁ is ▁ Depth ▁ First ▁ Traversal " ) NEW_LINE g . DFS ( ) NEW_LINE DEDENT


class sol { static class Node { int data ; Node next ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . data = key ; temp . next = null ; return temp ; } static Node rearrangeEvenOdd ( Node head ) { if ( head == null ) return null ; Node odd = head ; Node even = head . next ; Node evenFirst = even ; while ( true ) { if ( odd == null || even == null || ( even . next ) == null ) { break ; } odd . next = even . next ; odd = even . next ; if ( odd . next == null ) { even . next = null ; break ; } even . next = odd . next ; even = odd . next ; } Node current = evenFirst ; Node prev = null ; Node front = null ; while ( current != null ) { front = current . next ; current . next = prev ; prev = current ; current = front ; } evenFirst = prev ; odd . next = evenFirst ; return head ; } static void printlist ( Node node ) { while ( node != null ) { System . out . print ( node . data + " ▁ - > ▁ " ) ; node = node . next ; } System . out . println ( " null " ) ; } public static void main ( String args [ ] ) { Node head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 3 ) ; head . next . next . next = newNode ( 4 ) ; head . next . next . next . next = newNode ( 5 ) ; head . next . next . next . next . next = newNode ( 6 ) ; head = rearrangeEvenOdd ( head ) ; printlist ( head ) ; } }

import math NEW_LINE class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . next = None NEW_LINE DEDENT DEDENT def newNode ( key ) : NEW_LINE INDENT temp = Node ( key ) NEW_LINE temp . data = key NEW_LINE temp . next = None NEW_LINE return temp NEW_LINE DEDENT def rearrangeEvenOdd ( head ) : NEW_LINE INDENT if ( head == None ) : NEW_LINE INDENT return None NEW_LINE DEDENT odd = head NEW_LINE even = head . next NEW_LINE evenFirst = even NEW_LINE while True : NEW_LINE INDENT if ( odd == None or even == None or ( even . next ) == None ) : NEW_LINE INDENT break NEW_LINE DEDENT odd . next = even . next NEW_LINE odd = even . next NEW_LINE if ( odd . next == None ) : NEW_LINE INDENT even . next = None NEW_LINE break NEW_LINE DEDENT even . next = odd . next NEW_LINE even = odd . next NEW_LINE DEDENT current = evenFirst NEW_LINE prev = None NEW_LINE front = None NEW_LINE while ( current != None ) : NEW_LINE INDENT front = current . next NEW_LINE current . next = prev NEW_LINE prev = current NEW_LINE current = front NEW_LINE DEDENT evenFirst = prev NEW_LINE odd . next = evenFirst NEW_LINE return head NEW_LINE DEDENT def printlist ( node ) : NEW_LINE INDENT while ( node != None ) : NEW_LINE INDENT print ( node . data , end = " - > " ) NEW_LINE node = node . next NEW_LINE DEDENT print ( " NULL " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT head = newNode ( 1 ) NEW_LINE head . next = newNode ( 2 ) NEW_LINE head . next . next = newNode ( 3 ) NEW_LINE head . next . next . next = newNode ( 4 ) NEW_LINE head . next . next . next . next = newNode ( 5 ) NEW_LINE head . next . next . next . next . next = newNode ( 6 ) NEW_LINE head = rearrangeEvenOdd ( head ) NEW_LINE printlist ( head ) NEW_LINE DEDENT


class GFG { static void moveSpaceInFront ( char str [ ] ) { int i = str . length - 1 ; for ( int j = i ; j >= 0 ; j -- ) if ( str [ j ] != ' ▁ ' ) str [ i -- ] = str [ j ] ; while ( i >= 0 ) str [ i -- ] = ' ▁ ' ; } public static void main ( String [ ] args ) { char str [ ] = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " . toCharArray ( ) ; moveSpaceInFront ( str ) ; System . out . println ( String . valueOf ( str ) ) ; } }

def moveSpaceInFront ( s ) : NEW_LINE INDENT i = len ( s ) - 1 ; NEW_LINE for j in range ( i , - 1 , - 1 ) : NEW_LINE INDENT if ( s [ j ] != ' ▁ ' ) : NEW_LINE INDENT s = s [ : i ] + s [ j ] + s [ i + 1 : ] NEW_LINE i -= 1 ; NEW_LINE DEDENT DEDENT while ( i >= 0 ) : NEW_LINE INDENT s = s [ : i ] + ' ▁ ' + s [ i + 1 : ] NEW_LINE i -= 1 NEW_LINE DEDENT return s ; NEW_LINE DEDENT s = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " ; NEW_LINE s = moveSpaceInFront ( s ) ; NEW_LINE print ( s ) ; NEW_LINE


class GFG { static int MAX = 1000 ; static int f [ ] = new int [ MAX ] ; static int fib ( int n ) { if ( n == 0 ) { return 0 ; } if ( n == 1 || n == 2 ) { return ( f [ n ] = 1 ) ; } if ( f [ n ] == 1 ) { return f [ n ] ; } int k = ( n % 2 == 1 ) ? ( n + 1 ) / 2 : n / 2 ; f [ n ] = ( n % 2 == 1 ) ? ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) ) : ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; return f [ n ] ; } static int calculateEvenSum ( int n ) { return ( fib ( 2 * n + 1 ) - 1 ) ; } public static void main ( String [ ] args ) { int n = 8 ; System . out . println ( " Even ▁ indexed ▁ Fibonacci ▁ Sum ▁ upto ▁ " + n + " ▁ terms : ▁ " + calculateEvenSum ( n ) ) ; } }

MAX = 1000 ; NEW_LINE f = [ 0 ] * MAX ; NEW_LINE def fib ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT if ( n == 1 or n == 2 ) : NEW_LINE INDENT f [ n ] = 1 ; NEW_LINE return f [ n ] ; NEW_LINE DEDENT if ( f [ n ] ) : NEW_LINE INDENT return f [ n ] ; NEW_LINE DEDENT k = ( n + 1 ) // 2 if ( n % 2 == 1 ) else n // 2 ; NEW_LINE f [ n ] = ( fib ( k ) * fib ( k ) + fib ( k - 1 ) * fib ( k - 1 ) )   \ NEW_LINE if ( n % 2 == 1 ) else ( 2 * fib ( k - 1 ) + fib ( k ) ) * fib ( k ) ; NEW_LINE return f [ n ] ; NEW_LINE DEDENT def calculateEvenSum ( n ) : NEW_LINE INDENT return ( fib ( 2 * n + 1 ) - 1 ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 8 ; NEW_LINE print ( " Even ▁ indexed ▁ Fibonacci ▁ Sum ▁ upto " , n , " terms : " , calculateEvenSum ( n ) ) ; NEW_LINE DEDENT


import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static boolean CheckChildrenSum ( Node root ) { Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; while ( q . size ( ) > 0 ) { Node temp = q . peek ( ) ; q . remove ( ) ; if ( temp . left != null && temp . right != null ) { if ( temp . data != temp . left . data + temp . right . data ) return false ; q . add ( temp . left ) ; q . add ( temp . right ) ; } else if ( temp . left == null && temp . right != null ) { if ( temp . data != temp . right . data ) return false ; q . add ( temp . right ) ; } else if ( temp . right == null && temp . left != null ) { if ( temp . data != temp . left . data ) return false ; q . add ( temp . left ) ; } } return true ; } public static void main ( String args [ ] ) { Node root = newNode ( 10 ) ; root . left = newNode ( 8 ) ; root . right = newNode ( 2 ) ; root . left . left = newNode ( 3 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 2 ) ; if ( CheckChildrenSum ( root ) ) System . out . printf ( " Yes " ) ; else System . out . printf ( " No " ) ; } }

class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def CheckChildrenSum ( root ) : NEW_LINE INDENT q = [ ] NEW_LINE q . append ( root ) NEW_LINE while len ( q ) != 0 : NEW_LINE INDENT temp = q . pop ( ) NEW_LINE if temp . left and temp . right : NEW_LINE INDENT if ( temp . data != temp . left . data + temp . right . data ) : NEW_LINE INDENT return False NEW_LINE DEDENT q . append ( temp . left ) NEW_LINE q . append ( temp . right ) NEW_LINE DEDENT elif not temp . left and temp . right : NEW_LINE INDENT if temp . data != temp . right . data : NEW_LINE INDENT return False NEW_LINE DEDENT q . append ( temp . right ) NEW_LINE DEDENT elif not temp . right and temp . left : NEW_LINE INDENT if temp . data != temp . left . data : NEW_LINE INDENT return False NEW_LINE DEDENT q . append ( temp . left ) NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT root = Node ( 10 ) NEW_LINE root . left = Node ( 8 ) NEW_LINE root . right = Node ( 2 ) NEW_LINE root . left . left = Node ( 3 ) NEW_LINE root . left . right = Node ( 5 ) NEW_LINE root . right . right = Node ( 2 ) NEW_LINE if CheckChildrenSum ( root ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT


import java . util . * ; class GFG { static boolean sameJavaharAdj ( char str [ ] ) { int n = str . length , i ; TreeSet < Character > st = new TreeSet < > ( ) ; st . add ( str [ 0 ] ) ; for ( i = 1 ; i < n ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) { continue ; } if ( st . contains ( str [ i ] ) & ( str [ i ] != st . last ( ) ) ) { return false ; } st . add ( str [ i ] ) ; } return true ; } static int minSwaps ( char str [ ] , int l , int r , int cnt , int minm ) { if ( l == r ) { if ( sameJavaharAdj ( str ) ) { return cnt ; } else { return Integer . MAX_VALUE ; } } for ( int i = l + 1 ; i <= r ; i ++ ) { swap ( str , i , l ) ; cnt ++ ; int x = minSwaps ( str , l + 1 , r , cnt , minm ) ; swap ( str , i , l ) ; cnt -- ; int y = minSwaps ( str , l + 1 , r , cnt , minm ) ; minm = Math . min ( minm , Math . min ( x , y ) ) ; } return minm ; } static void swap ( char [ ] arr , int i , int j ) { char temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } public static void main ( String [ ] args ) { String str = " abbaacb " ; int n = str . length ( ) , cnt = 0 , minm = Integer . MAX_VALUE ; System . out . print ( minSwaps ( str . toCharArray ( ) , 0 , n - 1 , cnt , minm ) ) ; ; } }

from sys import maxsize NEW_LINE def sameCharAdj ( string ) : NEW_LINE INDENT n = len ( string ) NEW_LINE st = set ( ) NEW_LINE st . add ( string [ 0 ] ) NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if string [ i ] == string [ i - 1 ] : NEW_LINE INDENT continue NEW_LINE DEDENT if string [ i ] in st : NEW_LINE INDENT return False NEW_LINE DEDENT st . add ( string [ i ] ) NEW_LINE DEDENT return True NEW_LINE DEDENT def minSwaps ( string , l , r , cnt , minm ) : NEW_LINE INDENT if l == r : NEW_LINE INDENT if sameCharAdj ( string ) : NEW_LINE INDENT return cnt NEW_LINE DEDENT else : NEW_LINE INDENT return maxsize NEW_LINE DEDENT DEDENT for i in range ( l + 1 , r + 1 , 1 ) : NEW_LINE INDENT string [ i ] , string [ l ] = string [ l ] , string [ i ] NEW_LINE cnt += 1 NEW_LINE x = minSwaps ( string , l + 1 , r , cnt , minm ) NEW_LINE string [ i ] , string [ l ] = string [ l ] , string [ i ] NEW_LINE cnt -= 1 NEW_LINE y = minSwaps ( string , l + 1 , r , cnt , minm ) NEW_LINE minm = min ( minm , min ( x , y ) ) NEW_LINE DEDENT return minm NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT string = " abbaacb " NEW_LINE string = list ( string ) NEW_LINE n = len ( string ) NEW_LINE cnt = 0 NEW_LINE minm = maxsize NEW_LINE print ( minSwaps ( string , 0 , n - 1 , cnt , minm ) ) NEW_LINE DEDENT


import java . util . HashMap ; class GFG { public static int maxLengthSub ( int [ ] arr ) { int max_val = 0 ; int start = 0 ; HashMap < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { int temp = 0 ; if ( map . containsKey ( arr [ i ] - 1 ) ) { temp = map . get ( arr [ i ] - 1 ) ; } if ( map . containsKey ( arr [ i ] ) ) { temp = Math . max ( temp , map . get ( arr [ i ] ) ) ; } if ( map . containsKey ( arr [ i ] + 1 ) ) { temp = Math . max ( temp , map . get ( arr [ i ] + 1 ) ) ; } temp ++ ; if ( temp > max_val ) { max_val = temp ; } map . put ( arr [ i ] , temp ) ; } return max_val ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 6 , 3 , 7 , 6 , 5 , 8 } ; System . out . println ( maxLengthSub ( arr ) ) ; } }

from collections import defaultdict NEW_LINE def maxLenSub ( arr , n ) : NEW_LINE INDENT um = defaultdict ( lambda : 0 ) NEW_LINE maxLen = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT length = 0 NEW_LINE if ( arr [ i ] - 1 ) in um and length < um [ arr [ i ] - 1 ] : NEW_LINE INDENT length = um [ arr [ i ] - 1 ] NEW_LINE DEDENT if arr [ i ] in um and length < um [ arr [ i ] ] : NEW_LINE INDENT length = um [ arr [ i ] ] NEW_LINE DEDENT if ( arr [ i ] + 1 ) in um and length < um [ arr [ i ] + 1 ] : NEW_LINE INDENT length = um [ arr [ i ] + 1 ] NEW_LINE DEDENT um [ arr [ i ] ] = length + 1 NEW_LINE if maxLen < um [ arr [ i ] ] : NEW_LINE INDENT maxLen = um [ arr [ i ] ] NEW_LINE DEDENT DEDENT return maxLen NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 5 , 6 , 3 , 7 , 6 , 5 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE print ( " Maximum ▁ length ▁ subsequence ▁ = " , maxLenSub ( arr , n ) ) NEW_LINE DEDENT


import java . util . Arrays ; public class GFG { static void shuffleArray ( int a [ ] , int n ) { for ( int i = 0 , q = 1 , k = n ; i < n ; i ++ , k ++ , q ++ ) for ( int j = k ; j > i + q ; j -- ) { int temp = a [ j - 1 ] ; a [ j - 1 ] = a [ j ] ; a [ j ] = temp ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 } ; shuffleArray ( a , a . length / 2 ) ; System . out . println ( Arrays . toString ( a ) ) ; } }

def shuffleArray ( a , n ) : NEW_LINE INDENT i , q , k = 0 , 1 , n NEW_LINE while ( i < n ) : NEW_LINE INDENT j = k NEW_LINE while ( j > i + q ) : NEW_LINE INDENT a [ j - 1 ] , a [ j ] = a [ j ] , a [ j - 1 ] NEW_LINE j -= 1 NEW_LINE DEDENT i += 1 NEW_LINE k += 1 NEW_LINE q += 1 NEW_LINE DEDENT DEDENT a = [ 1 , 3 , 5 , 7 , 2 , 4 , 6 , 8 ] NEW_LINE n = len ( a ) NEW_LINE shuffleArray ( a , int ( n / 2 ) ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT print ( a [ i ] , end = " ▁ " ) NEW_LINE DEDENT


import java . io . * ; class GFG { static void printSubArray ( int arr [ ] , int start , int end ) { System . out . print ( " [ ▁ " ) ; for ( int i = start ; i <= end ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . print ( " ] ▁ " ) ; } static boolean divideArray ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int sum_so_far = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( 2 * sum_so_far + arr [ i ] == sum ) { System . out . print ( " The ▁ array ▁ can ▁ be ▁ divided ▁ into ▁ " + " two ▁ subarrays ▁ with ▁ equal ▁ sum \n The " + " ▁ two ▁ subarrays ▁ are ▁ - ▁ " ) ; printSubArray ( arr , 0 , i - 1 ) ; printSubArray ( arr , i + 1 , n - 1 ) ; return true ; } sum_so_far += arr [ i ] ; } System . out . println ( " The ▁ array ▁ cannot ▁ be ▁ divided ▁ into ▁ two ▁ " + " subarrays ▁ with ▁ equal ▁ sum " ) ; return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 2 , 3 , 2 , 1 } ; int n = arr . length ; divideArray ( arr , n ) ; } }

def printSubArray ( arr , start , end ) : NEW_LINE INDENT print ( " [ ▁ " , end = " " ) NEW_LINE for i in range ( start , end + 1 ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( " ] " , end = " " ) NEW_LINE DEDENT def divideArray ( arr , n ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT sum += arr [ i ] NEW_LINE DEDENT sum_so_far = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if 2 * sum_so_far + arr [ i ] == sum : NEW_LINE INDENT print ( " The ▁ array ▁ can ▁ be ▁ divided ▁ into " , " two ▁ subarrays ▁ with ▁ equal ▁ sum " ) NEW_LINE print ( " two ▁ subarrays ▁ are ▁ - " , end = " " ) NEW_LINE printSubArray ( arr , 0 , i - 1 ) NEW_LINE printSubArray ( arr , i + 1 , n - 1 ) NEW_LINE return True NEW_LINE DEDENT sum_so_far += arr [ i ] NEW_LINE DEDENT print ( " The ▁ array ▁ cannot ▁ be ▁ divided ▁ into " " two ▁ subarrays ▁ with ▁ equal ▁ sum " , end = " " ) NEW_LINE return False NEW_LINE DEDENT arr = [ 6 , 2 , 3 , 2 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE divideArray ( arr , n ) NEW_LINE


class GFG { static int ways ( String s , int n ) { int dp [ ] [ ] = new int [ n ] [ n ] ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { String temp = " " ; for ( int j = i ; j < n ; j ++ ) { temp += s . charAt ( j ) ; String test = " " ; for ( int k = i - 1 ; k >= 0 ; k -- ) { test += s . charAt ( k ) ; if ( test . compareTo ( temp ) < 0 ) { dp [ i ] [ j ] += dp [ k ] [ i - 1 ] ; } } } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += dp [ i ] [ n - 1 ] ; } return ans ; } public static void main ( String [ ] args ) { String s = " aabc " ; int n = s . length ( ) ; System . out . println ( ways ( s , n ) ) ; } }

def ways ( s , n ) : NEW_LINE INDENT dp = [ [ 0 for i in range ( n ) ] for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT dp [ 0 ] [ i ] = 1 NEW_LINE DEDENT for i in range ( 1 , n ) : NEW_LINE INDENT temp = " " NEW_LINE for j in range ( i , n ) : NEW_LINE INDENT temp += s [ j ] NEW_LINE test = " " NEW_LINE for k in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT test += s [ k ] NEW_LINE if ( test < temp ) : NEW_LINE INDENT dp [ i ] [ j ] += dp [ k ] [ i - 1 ] NEW_LINE DEDENT DEDENT DEDENT DEDENT ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans += dp [ i ] [ n - 1 ] NEW_LINE DEDENT return ans NEW_LINE DEDENT s = " aabc " NEW_LINE n = len ( s ) NEW_LINE print ( ways ( s , n ) ) NEW_LINE


import java . util . * ; class GFG { static void minOperation ( String S , int N , int K ) { if ( N % K != 0 ) { System . out . println ( " Not ▁ Possible " ) ; } else { int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { count [ ( S . charAt ( i ) - 97 ) ] ++ ; } int E = N / K ; Vector < Integer > greaterE = new Vector < > ( ) ; Vector < Integer > lessE = new Vector < > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] < E ) lessE . add ( E - count [ i ] ) ; else greaterE . add ( count [ i ] - E ) ; } Collections . sort ( greaterE ) ; Collections . sort ( lessE ) ; int mi = Integer . MAX_VALUE ; for ( int i = 0 ; i <= K ; i ++ ) { int set1 = i ; int set2 = K - i ; if ( greaterE . size ( ) >= set1 && lessE . size ( ) >= set2 ) { int step1 = 0 ; int step2 = 0 ; for ( int j = 0 ; j < set1 ; j ++ ) step1 += greaterE . get ( j ) ; for ( int j = 0 ; j < set2 ; j ++ ) step2 += lessE . get ( j ) ; mi = Math . min ( mi , Math . max ( step1 , step2 ) ) ; } } System . out . println ( mi ) ; } } public static void main ( String [ ] args ) { String S = " accb " ; int N = S . length ( ) ; int K = 2 ; minOperation ( S , N , K ) ; } }

def minOperation ( S , N , K ) : NEW_LINE INDENT if N % K : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT count = [ 0 ] * 26 NEW_LINE for i in range ( 0 , N ) : NEW_LINE INDENT count [ ord ( S [ i ] ) - 97 ] += 1 NEW_LINE DEDENT E = N // K NEW_LINE greaterE = [ ] NEW_LINE lessE = [ ] NEW_LINE for i in range ( 0 , 26 ) : NEW_LINE INDENT if count [ i ] < E : NEW_LINE INDENT lessE . append ( E - count [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT greaterE . append ( count [ i ] - E ) NEW_LINE DEDENT DEDENT greaterE . sort ( ) NEW_LINE lessE . sort ( ) NEW_LINE mi = float ( ' inf ' ) NEW_LINE for i in range ( 0 , K + 1 ) : NEW_LINE INDENT set1 , set2 = i , K - i NEW_LINE if ( len ( greaterE ) >= set1 and len ( lessE ) >= set2 ) : NEW_LINE INDENT step1 , step2 = 0 , 0 NEW_LINE for j in range ( 0 , set1 ) : NEW_LINE INDENT step1 += greaterE [ j ] NEW_LINE DEDENT for j in range ( 0 , set2 ) : NEW_LINE INDENT step2 += lessE [ j ] NEW_LINE DEDENT mi = min ( mi , max ( step1 , step2 ) ) NEW_LINE DEDENT DEDENT print ( mi ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " accb " NEW_LINE N = len ( S ) NEW_LINE K = 2 NEW_LINE minOperation ( S , N , K ) NEW_LINE DEDENT


import java . util . Stack ; class GFG { static int countNumber ( int n ) { int result = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) { Stack < Integer > s = new Stack < > ( ) ; if ( i <= n ) { s . push ( i ) ; result ++ ; } while ( ! s . empty ( ) ) { int tp = s . peek ( ) ; s . pop ( ) ; for ( int j = tp % 10 ; j <= 9 ; j ++ ) { int x = tp * 10 + j ; if ( x <= n ) { s . push ( x ) ; result ++ ; } } } } return result ; } public static void main ( String [ ] args ) { int n = 15 ; System . out . println ( countNumber ( n ) ) ; } }

def countNumber ( n ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( 1 , 10 ) : NEW_LINE INDENT s = [ ] NEW_LINE if ( i <= n ) : NEW_LINE INDENT s . append ( i ) NEW_LINE result += 1 NEW_LINE DEDENT while len ( s ) != 0 : NEW_LINE INDENT tp = s [ - 1 ] NEW_LINE s . pop ( ) NEW_LINE for j in range ( tp % 10 , 10 ) : NEW_LINE INDENT x = tp * 10 + j NEW_LINE if ( x <= n ) : NEW_LINE INDENT s . append ( x ) NEW_LINE result += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT return result NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 15 NEW_LINE print ( countNumber ( n ) ) NEW_LINE DEDENT


import java . util . * ; class GFG { static int countWays ( int n , int arr [ ] , int k ) { if ( k <= 0 || k >= n ) return 0 ; Set < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . add ( arr [ i ] ) ; if ( s . size ( ) <= k ) return 0 ; return s . size ( ) - k ; } public static void main ( String args [ ] ) { int arr [ ] = { 100 , 200 , 400 , 50 } ; int k = 3 ; int n = arr . length ; System . out . println ( countWays ( n , arr , k ) ) ; } }

def countWays ( n , arr , k ) : NEW_LINE INDENT if ( k <= 0 or k >= n ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT s = set ( ) NEW_LINE for element in arr : NEW_LINE INDENT s . add ( element ) NEW_LINE DEDENT if ( len ( s ) <= k ) : NEW_LINE INDENT return 0 ; NEW_LINE DEDENT return len ( s ) - k ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 100 , 200 , 400 , 50 ] NEW_LINE k = 3 ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( countWays ( n , arr , k ) ) 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 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 6 , 7 , 8 , 9 , 10 } ; int n , key ; n = arr . length ; key = 10 ; System . out . println ( " Index : ▁ " + binarySearch ( arr , 0 , n , key ) ) ; } }

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 [ int ( mid ) ] ) : NEW_LINE INDENT return mid NEW_LINE DEDENT if ( key > arr [ int ( 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 = [ 5 , 6 , 7 , 8 , 9 , 10 ] NEW_LINE n = len ( arr ) NEW_LINE key = 10 NEW_LINE print ( " Index : " , int ( binarySearch ( arr , 0 , n , key ) ) ) NEW_LINE


import java . util . Arrays ; class GFG { public static int partition ( int [ ] arr , int low , int high ) { int pivot = arr [ high ] , pivotloc = low ; for ( int i = low ; i <= high ; i ++ ) { if ( arr [ i ] < pivot ) { int temp = arr [ i ] ; arr [ i ] = arr [ pivotloc ] ; arr [ pivotloc ] = temp ; pivotloc ++ ; } } int temp = arr [ high ] ; arr [ high ] = arr [ pivotloc ] ; arr [ pivotloc ] = temp ; return pivotloc ; } public static int kthSmallest ( int [ ] arr , int low , int high , int k ) { int partition = partition ( arr , low , high ) ; if ( partition == k ) return arr [ partition ] ; else if ( partition < k ) return kthSmallest ( arr , partition + 1 , high , k ) ; else return kthSmallest ( arr , low , partition - 1 , k ) ; } public static void main ( String [ ] args ) { int [ ] array = new int [ ] { 10 , 4 , 5 , 8 , 6 , 11 , 26 } ; int [ ] arraycopy = new int [ ] { 10 , 4 , 5 , 8 , 6 , 11 , 26 } ; int kPosition = 3 ; int length = array . length ; if ( kPosition > length ) { System . out . println ( " Index ▁ out ▁ of ▁ bound " ) ; } else { System . out . println ( " K - th ▁ smallest ▁ element ▁ in ▁ array ▁ : ▁ " + kthSmallest ( arraycopy , 0 , length - 1 , kPosition - 1 ) ) ; } } }

def partition ( arr , l , r ) : NEW_LINE INDENT x = arr [ r ] NEW_LINE i = l NEW_LINE for j in range ( l , r ) : NEW_LINE INDENT if arr [ j ] <= x : NEW_LINE INDENT arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ] NEW_LINE i += 1 NEW_LINE DEDENT DEDENT arr [ i ] , arr [ r ] = arr [ r ] , arr [ i ] NEW_LINE return i NEW_LINE DEDENT def kthSmallest ( arr , l , r , k ) : NEW_LINE INDENT if ( k > 0 and k <= r - l + 1 ) : NEW_LINE INDENT index = partition ( arr , l , r ) NEW_LINE if ( index - l == k - 1 ) : NEW_LINE INDENT return arr [ index ] NEW_LINE DEDENT if ( index - l > k - 1 ) : NEW_LINE INDENT return kthSmallest ( arr , l , index - 1 , k ) NEW_LINE DEDENT return kthSmallest ( arr , index + 1 , r , k - index + l - 1 ) NEW_LINE DEDENT return INT_MAX NEW_LINE DEDENT arr = [ 10 , 4 , 5 , 8 , 6 , 11 , 26 ] NEW_LINE n = len ( arr ) NEW_LINE k = 3 NEW_LINE print ( " K - th ▁ smallest ▁ element ▁ is ▁ " , end = " " ) NEW_LINE print ( kthSmallest ( arr , 0 , n - 1 , k ) ) NEW_LINE


class Main { static int getMissingNo ( int a [ ] , int n ) { int x1 = a [ 0 ] ; int x2 = 1 ; for ( int i = 1 ; i < n ; i ++ ) x1 = x1 ^ a [ i ] ; for ( int i = 2 ; i <= n + 1 ; i ++ ) x2 = x2 ^ i ; return ( x1 ^ x2 ) ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 2 , 4 , 5 , 6 } ; int miss = getMissingNo ( a , 5 ) ; System . out . println ( miss ) ; } }

def getMissingNo ( a , n ) : NEW_LINE INDENT x1 = a [ 0 ] NEW_LINE x2 = 1 NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT x1 = x1 ^ a [ i ] NEW_LINE DEDENT for i in range ( 2 , n + 2 ) : NEW_LINE INDENT x2 = x2 ^ i NEW_LINE DEDENT return x1 ^ x2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = [ 1 , 2 , 4 , 5 , 6 ] NEW_LINE n = len ( a ) NEW_LINE miss = getMissingNo ( a , n ) NEW_LINE print ( miss ) NEW_LINE DEDENT


import java . io . * ; class GFG { static int mod = 1000000000 ; static int ways ( int i , int arr [ ] , int n ) { if ( i == n - 1 ) return 1 ; int sum = 0 ; for ( int j = 1 ; j + i < n && j <= arr [ i ] ; j ++ ) { sum += ( ways ( i + j , arr , n ) ) % mod ; sum %= mod ; } return sum % mod ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 1 , 4 , 3 } ; int n = arr . length ; System . out . println ( ways ( 0 , arr , n ) ) ; } }

mod = 1e9 + 7 ; NEW_LINE def ways ( i , arr , n ) : NEW_LINE INDENT if ( i == n - 1 ) : NEW_LINE INDENT return 1 ; NEW_LINE DEDENT sum = 0 ; NEW_LINE for j in range ( 1 , arr [ i ] + 1 ) : NEW_LINE INDENT if ( i + j < n ) : NEW_LINE INDENT sum += ( ways ( i + j , arr , n ) ) % mod ; NEW_LINE sum %= mod ; NEW_LINE DEDENT DEDENT return int ( sum % mod ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 5 , 3 , 1 , 4 , 3 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( ways ( 0 , arr , n ) ) ; NEW_LINE DEDENT


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

def Centered_Trigunal_num ( n ) : NEW_LINE INDENT return ( 3 * n * n + 3 * n + 2 ) // 2 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 3 NEW_LINE print ( Centered_Trigunal_num ( n ) ) NEW_LINE n = 12 NEW_LINE print ( Centered_Trigunal_num ( n ) ) NEW_LINE DEDENT


class Main { public static int nth_term ( int n ) { int a = 1 , b = 1 , c = 1 ; for ( int i = 0 ; i < n ; i ++ ) { c = a + b ; a = b ; b = c ; } return c ; } public static void main ( String [ ] args ) { int n = 10 ; int c = nth_term ( n ) ; System . out . println ( c ) ; } }

def nth_term ( n ) : NEW_LINE INDENT a = 1 NEW_LINE b = 1 NEW_LINE c = 1 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT c = a + b NEW_LINE a = b NEW_LINE b = c NEW_LINE DEDENT return c NEW_LINE DEDENT n = 10 NEW_LINE c = nth_term ( n ) NEW_LINE print ( c ) NEW_LINE


class GFG { static void findFactors ( int a , int b ) { int c ; c = a + b - 1 ; System . out . print ( c ) ; } public static void main ( String [ ] args ) { int a , b ; a = 13 ; b = 36 ; findFactors ( a , b ) ; } }

def findFactors ( a , b ) : NEW_LINE INDENT c = a + b - 1 NEW_LINE print ( c ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT a = 13 NEW_LINE b = 36 NEW_LINE findFactors ( a , b ) NEW_LINE DEDENT